Featured image of post Target Display Mode on Linux

Target Display Mode on Linux

Using my 2011 iMac as a monitor from Pop!_OS

Overview

Click to see a GIF!

In building our shed/home office, I was looking for a both a Linux machine that I could keep down there as well as a display to use with my iPad Pro or work MacBook Pro.

My Dad had an old (2011) 27" iMac laying around not doing much. It’s got an i5 CPU, 32GB RAM an SSD and a 2TB spinning rust drive inside. The great thing about this machine is that it can do Target Display Mode via the included Mini Display Port.

Under it’s regular operating system, (macOS) this means you can plug in a cable from the Mini Display Port on the back to another device such as a laptop or tablet, then press a keyboard shortcut and the iMac display becomes an external monitor for the device.

However as far as I knew, this was a feature only available in macOS.

I asked to borrow it off my Dad to do some testing and immediately installed Pop!_OS (my current Linux distro of choice) onto it. Everything worked great in Pop!_OS and the machine itself is really snappy and more than usable for what I need. However, Target Display Mode coudl still only be triggered from macOS.

So I set about trying to find a way to do this in Pop!_OS.

 


Target Display Mode

Target Display Mode is only available on certain iMac models. See the Target Display Mode documentation by Apple for more information on this.

From that article:

24-inch and 27-inch iMac models introduced in 2009 and 2010:

The cable connecting the two Mac computers must be a Mini DisplayPort cable.

 

iMac models introduced in 2011, 2012, 2013, and mid 2014:

The cable connecting the two Mac computers must be a Thunderbolt or Thunderbolt 2 cable.

 

Cable

Since my iMac is a 2011 model, and the devices I will be connecting to it are USB-C equiped (My iPad Pro and MacBook Pro) I used a Mini Display Port to USB-C cable.

For reference, I used this one from Amazon and it worked great.

 


smc_utils and Target Display Mode in Linux

Doing some research into if anyone had already done this, I found this video from “THE PHINTAGE COLLECTOR” who in the video talks you through setting up a version of “Tiny Core Linux” to boot into a very minimal Linux distro just to use Target Display Mode.

This is great, but for me I wanted to be able to use the underlying OS when i unplug my iPad Pro or work MacBook Pro for the day.

Therefore, I started looking into utilising the underlying project (smc_util) in some kind of script that could be triggered by a keyboard shortcut in Pop!_OS.

 


Process

  1. Download a copy of smc_util: https://github.com/floe/smc_util/

     

  2. Copy the entire smc_util folder to /usr/local/bin

 

  1. Edit the scripts as follows to add the full path to SmcDumpKey instead of ./SmcDumpKey as was in the files originally:

    • tdm_on.sh:

      1
      2
      3
      4
      5
      6
      
      #!/bin/bash
      /usr/local/bin/smc_util/SmcDumpKey MVHR 1
      sleep 1
      /usr/local/bin/smc_util/SmcDumpKey MVMR 2
      sleep 2
      DISPLAY=:0.0 xrandr --output eDP --off
      
    • tdm_off.sh:

      1
      2
      3
      4
      5
      6
      
      #!/bin/bash
      /usr/local/bin/smc_util/SmcDumpKey MVHR 0
      sleep 1
      /usr/local/bin/smc_util/SmcDumpKey MVMR 2
      sleep 2
      DISPLAY=:0.0 xrandr --output eDP --auto
      

 

  1. Make root the owner of the scripts:
1
2
3
chown root:root /usr/local/bin/smc_util/tdm_on.sh
chown root:root /usr/local/bin/smc_util/tdm_off.sh
chown root:root /usr/local/bin/smc_util/SmcDumpKey

 

  1. Set the setuid bit on the scripts, with other desired permissions. (You should ensure the files are not writable.)
1
2
3
chmod 4755 /usr/local/bin/smc_util/tdm_on.sh
chmod 4755 /usr/local/bin/smc_util/tdm_off.sh
chmod 4755 /usr/local/bin/smc_util/SmcDumpKey

 

  1. Edit the sudoers file sudo visudo to add the following:
1
2
3
ALL ALL=(ALL:ALL) NOPASSWD: /usr/local/bin/smc_util/tdm_on.sh
ALL ALL=(ALL:ALL) NOPASSWD: /usr/local/bin/smc_util/tdm_off.sh
ALL ALL=(ALL:ALL) NOPASSWD: /usr/local/bin/smc_util/SmcDumpKey

NOTE: I chose to use ALL at the start of the above lines, as there will be multiple users running this script. However, you should really think about whether this is needed - you could specify your own user (e.g. graham), or a group (e.g. %admin).

 

  1. Add the custom keyboard shortcuts (check out the Pop!_OS keyboard shortcuts guide) to execute the following commands:

    Gnome Custom Shortcuts

    • On: bash /usr/local/bin/smc_util/tdm_on.sh
    • Off: bash /usr/local/bin/smc_util/tdm_off.sh

    tdm_on shortcut

 


References

Built with Hugo
Theme Stack designed by Jimmy