Skip to content

Set up Ubuntu on an external drive

If your main OS is Windows and you would like to set up Ubuntu on an external drive, this guide will show you how to do it.

Prerequisites

For this guide you will need a 16+GB USB flash drive and an external SSD/HDD.

It is a good idea to have this guide open on another device in order to be able to follow it while setting up Ubuntu on the device you are currently reading this on.

It is also important to know which button opens your boot menu during start up.

Before continuing with the steps below, make sure to check whether you can disable your internal drive through the BIOS settings. If you can, follow this guide instead: https://medium.com/geekculture/installing-linux-ubuntu-20-04-on-an-external-portable-ssd-and-pitfalls-to-be-aware-of-388294e701b5

Prepare the USB flash drive

First, go to https://releases.ubuntu.com/22.04/ and downloading ubuntu-22.04.4-desktop-amd64.iso from the list of available files.

Afterwards, download balenaEtcher from here: https://etcher.balena.io/

Now plug in the USB flash drive, open balenaEtcher, click Flash from file, select the Ubuntu .iso we downloaded earlier, click Select target, select the USB flash drive, click Flash! and wait for it to finish the process.

Now the USB flash drive should be ready for the next step.

Prepare the external drive

The external drive must be formatted as GPT before the next steps.

Open cmd as administrator and open diskpart:

Terminal window
diskpart

At the diskpart prompt, enter:

Terminal window
list disk

Make note of the disk number that you want to convert to GPT format.

Again at the diskpart prompt, enter (replace <disk-number> accordingly):

Terminal window
select disk <disk-number>
clean

Finally, at the diskpart prompt, enter:

Terminal window
convert gpt

Setting up Ubuntu

Setting up partitions on the external drive’s Ubuntu

Restart your machine and open up the boot menu before Windows loads.

The USB flash drive should be in the list of options in the boot menu. Select it.

After Ubuntu loads you should have the option to choose between Try Ubuntu and Install Ubuntu. Click on Try Ubuntu.

Plug in your external drive and start GParted. Once GParted is open, in the upper right corner, change the target drive to the external drive (you can identify it based on its storage size, for example). If you are using a brand new external drive, it should not have any partitions on it. If it is not brand new/it already has something on it, right click, unmount any currently mounted paritions and delete them all.

Now, click on the unallocated volume, choose new, and create a 100MB fat32 partition. Click on the green checkmark to apply. Once the partition has been created - right click on it, select Manage Flags and enable the boot and esp flags.

Next, create a linux-swap partition. A rule of thumb for the size of this partition if you have plenty of RAM is to make it equal to 1/2 of your total RAM. Apply and give it the swap flag.

The final partition we have to create is the root one. Create an ext4 partition. You can give this one the rest of the space on the external drive if you are planning to use it only to run Ubuntu. Click apply.

Now that all the partitions have been created, you should have /dev/sdx1, /dev/sdx2 and /dev/sdx3 (x differs from case to case, although it’s usually a or b).

Before the next step, right click on each partition, select Information and take a photo of the pop-up using your phone or write the information you see on a piece of paper.

Installing Ubuntu

On Ubuntu’s task bar, you should have Install Ubuntu. Click on it.

When you get to the Installation type step, select Something else.

Now you should see a list of available drive volumes. Scroll down until you see the partitions created previously. Double click on the 100MB fat32 system efi partition (/dev/sdx1) and choose Use as EFI system partition. Do not format it or any of the next partitions. Double click on the /dev/sdx2 partition and select Use as swap area. Double click on the /dev/sdx3 partition, select Ext4 journaling system and set the mount point to /. Now set the Device for boot loader installations: to the name of the external drive. Click Install Now.

After Ubuntu has been installed, shut down your machine. Ubuntu might ask you to remove the USB stick and press enter as it is shutting down, do it.

Installing grub onto the ESP parition

Once your machine has shut down, plug your USB flash drive in and turn it on. Go to the boot settings and select the USB flash drive again. Select Try Ubuntu, open a terminal and type:

Terminal window
sudo umount /media/ubuntu/<the uuid of your media>

Replace the uuid of your media with whatever is in the folder.

Next, mount the new Ubuntu root volume from the external drive:

Terminal window
sudo mount /dev/sdx3 /mnt

Fix the UUIDs of the mount points in fstab for the external Ubuntu installation using the UUIDs you took a photo of or wrote down earlier:

Terminal window
sudo nano /mnt/etc/fstab

In nano, copy paste and comment the line with the /boot/efi mount point. In the new line replace the current UUID with the corresponding one from your photo/notes. Check if the swap and / mount points are pointed to the correct volumes, save and close the file.

Next, mount the new 100MB fat32 partition on /dev/sdx1:

Terminal window
sudo mount /dev/sdx1 /mnt/boot/efi

Next, create these system process mount points in order to be able to chroot into this volume and install Grub:

Terminal window
sudo mount -B /dev /mnt/dev
sudo mount -B /dev/pts /mnt/dev/pts
sudo mount -B /proc /mnt/proc
sudo mount -B /sys /mnt/sys

Copy over the current DNS settings just in case you need network access:

Terminal window
sudo cp /etc/resolv.conf /mnt/etc/

Now check for the presence of /sys/firmware/efi:

Terminal window
ls /sys/firmware/

If efi is not present, run:

Terminal window
modprobe efivars

Switch into a chroot environment:

Terminal window
sudo chroot /mnt

And install grub (be sure to replace x in /dev/sdx accordingly):

Terminal window
grub-install -d /usr/lib/grub/x86_64-efi --efi-directory=/boot/efi/ --removable /dev/sdx

Now turn off the machine.

Clean up the dual boot configuration

Turn on the machine and go to your boot menu. You might be redirected to a grub terminal. If so, type normal and press enter. Now you should see the different boot options. Pick the Windows one.

When Windows has started up, open a cmd window as administrator and type:

Terminal window
diskpart

The diskpart window should open. In it, type:

Terminal window
list disk

Choose the disk that is your machine’s primary boot drive (likely disk 0):

Terminal window
select disk 0

Show the partitions on this disk:

Terminal window
list partition

Select the EFI / ESP partition (likely around 100-200MB). Replace x accordingly:

Terminal window
select partition x

Assign a free drive letter to this partition:

Terminal window
assign letter=Z:

Exit diskpart and go back to the cmd. Type:

Terminal window
Z:

Now check if there is anything related to Ubuntu in there and delete it:

Terminal window
rmdir /S ubuntu

Now shut down your machine again.

When you turn on your machine without the external drive plugged in, Windows should start normally. When you turn it on with the external drive plugged in, you should get a grub selection menu which contains Ubuntu.

Information source

This guide was written and tested using https://www.58bits.com/blog/how-create-truly-portable-ubuntu-installation-external-usb-hdd-or-ssd as a source. If there are problems during the set up, check the comments in it for potential fixes.