HOW TO: Installing Linux on an external drive and running it on a MacBook

cyber security al sahawat times


HOW TO: Run Linux Ubuntu on a MacBook from an external drive


HOW TO | TECHNOLOGY | OPERATING SYSTEMS | LINUX | UBUNTU | APPLE | MAC BOOK

Disclaimer: Proceed at your own risk, every device and digital file has its own merits and limitations, this guide provides no troubleshoot in the event of user, hardware or software error. No liability is accepted in the event of damage to your devices or systems. 

This ‘How To’ guide is designed to guide you through the theoretical steps on how one might install the full Linux Ubuntu OS onto an external drive (such as an SSD) and run this on a MacBook. Given that this could irreversibly damage or destroy your device or system, it is not advised that you do this on any device or system that you do not own and do not mind loosing if you make any mistakes or anything goes wrong. Irreversible damage may be caused.

Why install on an external drive?

Linux and MacOS are both very secure so why run from an external drive? If you require a full Linux OS and do not want to deal with the lag caused by virtual machines but do not want to make permanent changes or partitions to your MacBook. Installing on a high speed external drive will allow the running of a full Linux Ubuntu OS environment with the convenience of a portable system that can simply be plugged into and run from any MacOS device.

System requirements: 

  1. An Intel powered Macbook form 2013 or later with at 2 UBS or USB-C ports.
  2. A bootable USB flash drive for installing Linux Ubuntu.
  3. A blank, high speed SSD drive. You can still use a USB drive, but an SSD USB drive will be more durable, reliable and faster. These types of drive typically range around €80-€200 depending on country and brand.

Format your portable environment

This is the SSD drive you wish to run the Linux Ubuntu OS from.

  1. Connect the drive to a MacBook and open Utilities.
  2. From Utilities – open Disk Utilities.
  3. Select the SSD (NOT your MacBook hard drive – check this CAREFULLY)
  4. Select Erase with the following variables selected:
    • Name: EmptyDrive
    • Format: Mac OS Extended (Journaled)
    • Scheme: GUID Partition Map
  5. Create a new partition called ‘Ubuntu Boot Loader’.

Loading Linux Ubuntu OS on the external drive: 

Firstly you will need to start a Linux ‘Live Session’

  1. Shutdown your Mac.
  2. Eject and remove the external SSD drive.
  3. Connect your Linux Installer USB flash drive that has the Linux Ubuntu installer on it.
  4. Boot you Mac pressing and holding the options key at the same time.
  5. Select the Orange EFI Boot option (right directional key then enter).
  6. Select ‘Try Ubuntu’

Prepare your external drive: 

  1. Reconnect your external SSD drive.
  2. Open the GParted application that will be in your Linux window (click the upper left corner search icon, type in “GParted” and click the GParted Partition Editor application icon).
  3. Within the GParted application, find your external SSD drive. (It will look something like this: /dev/sdd) . Check the letters disk size are appropriate to ensure you are selecting the correct drive.
  4. Delete all the partitions EXCEPT the hfs+ Ubuntu Boot Loader partition. (Removed partitions may be things such as: fat32 system labelled EFI or  hfs+ system labelled EmptyDrive.) For each partition to delete:
    • Select it
    • Click the red circular icon.
  5. The delete operations are only queued and have not yet been actioned. Click the green check box to action the operations.
  6. Add a new partition (click Partition > new).
  7. Select the following variables:
    • New Size: 14210 MiB (this should match your device’s RAM specs – e.g. 16 GB RAM would be 14210 MiB) How to convert GB RAM to MiB
    • File system: linux-swap
  8. Add another new partition with the following options:
    • New size: default
    • File system: ext4
    • Label: (Label as you wish)
  9. Apply the new partitions by clicking the green check
  10. Make a note of the ext4 partition name, e.g. /dev/sdd2
  11. Close GParted

Installing your new OS environment

  1. Connect to WiFi (this saves time later, but is optional)
  2. Select “Install Ubuntu” in upper left corner on the desktop.
  3. Select your language.
  4. Check the boxes:
    • Download updates
    • Install third party software
  5. Select the “something else” option.
  6. Find the ext4 formatted partition you just created in GParted. Be exact and don’t make any mistakes here – check, double check, then check again, it is extremely important you select the correct partition on the correct drive here.
  7. Select “change”… and apply the following variables:
    • default size
    • Ext4 journaling file system
    • Format the partition (check this box)
    • Mount point: /
  8.  Choose this device for boot loader installation: select the device that corresponds to the ext4 partition. (Do not select the SSD external drive itself, only the GParted created ext4 partition.)
  9. Follow the onscreen installation instructions.
  10. Once the installation has ‘finished’ select “continue testing”. (The installation process has not ‘finished’.)

Linux Ubuntu OS at this point is technically installed on your SSD external drive, yes, but you will not be able to boot into it from the MacBook load screen, since there’s no EFI boot loader needed for Mac firmware to recognise the OS as bootable.

You need to access the Ubuntu installation and create a boot.efi file that will be used to boot the OS. This needs to be done whilst still in the live Ubuntu session.

Making the OS Bootable: 

  1. Using the same search icon you used to find GParted, search for and open “Terminal”.
  2. Run the following command: (replace ‘/dev/sdaN’ with the device that corresponds to your ext4 partition that you made a note of earlier.)
    sudo mount /dev/sdaN /mnt
  3. To mount the top line directories use the following one line command:
    for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
  4. You can now use the chroot command to change your root directory to /mnt, so that the bash session in ‘Terminal’ is effectively running inside the Ubuntu installation:
    sudo chroot /mnt
  5. This allows you to configure GNU GRUB, the “GRand Unified Bootloader,” with:
    grub-mkconfig -o boot/grub/grub.cfg
  6. Save this to a standalone file with the following one line command:
    grub-mkstandalone -o boot.efi -d usr/lib/grub/x86_64-efi -O x86_64-efi --compress=xz boot/grub/grub.cfg
  7. Exit the chrooted partition:
    exit
  8. The boot.efi file is in the new installation, however, you now need to copy it to the live session:
    cp /mnt/boot.efi /home/ubuntu
  9. You now need to access the boot.efi file from your Mac OS system. The easiest way is to email the file to yourself, or save it to a cloud drive. You can find the boot.efi file in your home directory (click the file cabinet icon in the upper left, which launches a folder view of your home folder).
  10. Now you can shutdown Ubuntu. The device might lag.. give it 30 seconds or so and then shutdown the device itself.
  11. Click Utilities > Terminal.
    1. In the Terminal window, type in:
      csrutil disable
    2. Press Enter.
    3. Restart your Mac. If you get a black screen with the word “GRUB”, type “EXIT”Reboot your Mac into Recovery Mode by restarting your computer and holding down Command+R until the Apple logo appears on your screen
    4. Press Enter.
    5. Restart your Mac. If you ever get a black screen with the word “GRUB”, type “EXIT”.
  12. Launch Terminal (Go > Utilities > Terminal)
  13. Plug in your Linux Ubuntu SSD external drive and enter the following command into Terminal:
    cd /Volumes/Ubuntu\ Boot\ Loader/
  14. Enter the following commands (one at a time) (the password is your Mac’s password):
    sudo mkdir System mach kernel
    cd System
    sudo mkdir -p Library/CoreServices
    cd Library/CoreServices
  15. Download your boot.efi file from your email or cloud drive.
  16. Assuming your boot.efi file is now in your Downloads folder, enter the following command into Terminal:
    sudo cp ~/Downloads/boot.efi ./
  17. In both Mac OS and Linux Ubuntu, you can find a file through the user interface / finder, and drag the file into a terminal window, and it will insert the full path to the file.
  18. Now you need to make a ‘SystemVersion.plist’ file.
    1. <xml version="1.0" encoding="utf-8"?>
      <plist version="1.0">
      <dict>
      <key>ProductBuildVersion</key>
      <string></string>
      <key>ProductName</key>
      <string>Linux</string>
      <key>ProductVersion</key>
      <string>Ubuntu Linux</string>
      </dict>
      </plist>
  19. Copy the SystemVersion.plist file to the same directory on the external SSD drive where your boot.efi is (/Volumes/Ubuntu\ Boot\ Loader/System/Library/CoreServices). Go back to Terminal and execute the command:
    sudo cp ~/Downloads/SystemVersion.plist ./
  20. Open Disk Utility (Go > Utilities > Disk Utility) to check what disk number your bootloader is.
  21. Command:
    sudo bless --device /dev/diskNsK --setBoot
    Where you replace N and K with the numbers from step 20.

Turning SIP security back on: 

  1. Shut down your MacOS device.
  2. Remove your external device.
  3. Reboot your Mac into Recovery Mode by restarting your device and holding down Command+R until the Apple logo appears on your screen.
  4. Utilities > Terminal.
  5. Command:
    csrutil enable
  6. Shutdown the Mac device.

Boot to Linux Ubuntu from your MacBook: 

  1. Plug in your external SSD drive.
  2. Press the option key while booting up the MacBook.
  3. Select the orange Boot EFI.
  4. Now you have a full Ubuntu install actively running on your MacBook from the external device.

If you see the GRUB screen repeatedly when booting into Linux: go to System Preferences > Startup Disk, unlock, then select your Mac harddrive and restart the system. This will take longer than usual, so be patient. After that you won’t see the grub screen anymore on restarting your MacBook.

Get an external mouse with a left and right clicker. Failing that, in Linux select the “activities” icon and type “Universal Access”. Select “Pointing and Clicking”, and turn on Simulated Secondary Click. Now if you click and hold for a brief moment, you will get a right click.

Enjoy.

_

© 2021 Al-Sahawat Times, Printed and Distributed by IPMG, an Al-Said Group entity. 


Since you’re here …

… we have a small favour to ask. More people are reading Al-Sahawat Times than ever but advertising revenues across the global media industry are falling fast. And unlike many news organisations, we haven’t put up a total paywall. We want to keep our journalism as open as we can. So you can see why we need to ask for your help. Al-Sahawat Times’ independent, investigative journalism takes a lot of time, money and hard work to produce. But we do it because we believe truly ethical media and an unbias perspective really matters.

“I appreciate there not being a paywall: it is more democratic for the media to be available for all and not a commodity to be purchased by a few. I’m happy to make a contribution so others with less means still have access to information.”

If everyone who reads our reporting, who likes it, helps fund it, the future of ethical media and the futures of our staff and their families would be much more secure. For as little as £1, you can support Al-Sahawat Times and it only takes a minute. Thank you.




This story is available on:

APPLE NEWS | AL-SAHAWAT TIMES


Talk to a journalist

Email: NewsDesk@alsahawat.com

Web: alsahawat.com

Follow Al-Sahawat Times

⬆️ Follow on Instagram

⬆️ Follow on Twitter

⬆️ Follow on LinkedIn

⬆️ Follow on Facebook

⬆️ Follow on YouTube

Read it on APPLE NEWS

Read it on FLIPBOARD

About the Author

Caleb Simmons
Caleb Simmons | Journalist Since: 2003 | New York - Abu Dhabi - London - Barcelona
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments