How to install Ubuntu on USB Stick

Installing Ubuntu Linux onto a USB stick will allow you to have a portable operating sysem that you can plug into any computer. This differs from a live environment USB, as installing Ubuntu directly to a USB stick will create a persistent operating system, the same way it does when you install to a typical hard disk. However, the process of installing Ubuntu to USB is not the same as a usual hard drive.

There are some differences in the installation process and important caveats to keep in mind if you plan to install Ubuntu to a USB stick. We will go over those in the sections below. In this tutorial, we will cover the step by step instructions to install Ubuntu Linux to a USB flash drive.

In this tutorial you will learn:

  • How to install Ubuntu on USB Stick
How to install Ubuntu on USB Stick
How to install Ubuntu on USB Stick
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Ubuntu Linux
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Important things to keep in mind




Before you go forward with installing Ubuntu to USB, keep these things in mind:

  • Your flash drive should be USB 3.0, or the speed of the operating system will be painfully slow
  • You will need two flash drives – one as a bootable USB to install Ubuntu, and the other to install Ubuntu onto
  • You may need to disable secure boot on PCs in order to boot from the USB, since it will contain its own EFI partition

The installation process will differ slightly from a usual one because we will need to temporarily disable the ESP flag on the current hard drive. This is because Ubuntu will not allow us to install an EFI bootloader onto the USB drive if one already exists on the system’s hard drive. The workaround is to temporarily disable the ESP flag, install Ubuntu to USB, and then re-enable the ESP flag afterwards.

How to install Ubuntu on USB Stick step by step instructions

We will be using “USB 1” to refer to the USB stick that is acting as an Ubuntu installer, and “USB 2” to refer to the USB stick on which we will be installing the persistent Ubuntu.

  1. The first thing we will need to do is create a bootable USB Ubuntu stick. Download Ubuntu and then use the following dd command syntax to copy the contents over to USB 1.
    $ sudo dd bs=4M if=/path/to/ubuntu.iso of=/dev/sdX status=progress oflag=sync
    

    Of course, replace /path/to/ubuntu.iso with the path to your ISO file, and replace /dev/sdX with the name of your device.

  2. Next, plug in both flash drives and reboot your PC. When it starts up, make sure you boot to the USB installer (USB 1) that we just created in the previous step.
    Loading into the Ubuntu live environment from USB 1
    Loading into the Ubuntu live environment from USB 1
  3. Once you arrive at the welcome screen, click on the “Try Ubuntu” option.
    Click on 'try Ubuntu' to continue to the Ubuntu live environment
    Click on ‘try Ubuntu’ to continue to the Ubuntu live environment
  4. Next, open up the gparted application from within Ubuntu’s Activities menu.
    Open up gparted application
    Open up gparted application
  5. In gparted, right click on your system’s EFI partition, which should be marked by the esp flag. Click on the option “Manage Flags.”



    Click on manage flags option inside of gparted
    Click on manage flags option inside of gparted

  6. Inside of the flag management menu, uncheck the ESP option. This is only temporary, and we will be putting this back on when we are done installing Ubuntu to USB 2. You can exit gparted after this step is completed.
    Uncheck the ESP option in gparted
    Uncheck the ESP option in gparted
  7. Next, it is time to install Ubuntu onto USB 2. Click on the desktop shortcut to install Ubuntu. Proceed to choose your language and keyboard layout in the following installation prompts.
    Begin the installation process by clicking this icon located on the desktop
    Begin the installation process by clicking this icon located on the desktop
  8. Once you get to the “Installation Type” screen, click on the option for “Something else” before clicking continue.
    Click to choose some other type of partitioning scheme
    Click to choose some other type of partitioning scheme
  9. Make sure you select USB 2 from the drop down menu, as we do not want to make any changes to USB 1 or your other disks in the system.
    Choose USB 2 from the drop down menu
    Choose USB 2 from the drop down menu
  10. If you already have some partitions on USB 2, you can delete them by highlighting them and clicking the minus sign on the partition menu. Highlight your free space and click on the plus sign to add a new partition. The first partition will be our EFI partition and contain the boot loader. Fill out the settings as seen below.
    Creating an EFI partition on USB 2
    Creating an EFI partition on USB 2
  11. Next, we will create the primary (root) partition which can simply span the rest of the USB stick. Fill out the settings as seen below.
    Creating the primary partition on USB 2
    Creating the primary partition on USB 2
  12. Next, continue with the rest of the installation as normal.

    Ubuntu is being installed to USB 2
    Ubuntu is being installed to USB 2



  13. Once the installation has completed, make sure you click on “Continue Testing.” Because we need to finish up by putting the ESP flag back on the EFI partition for our hard disk.
    Click on 'Continue Testing'
    Click on ‘Continue Testing’
  14. Open gparted once again and repeat the steps from earlier, but this time adding the ESP flag back to the EFI (boot) partition of your hard disk.
    Re-enabing the ESP flag for hard disk
    Re-enabing the ESP flag for hard disk
  15. All done. You can power off the system from the GUI or use the following command:
    $ poweroff
    

Once the system is powered off, remove USB 1 from the computer (the USB drive which we used to install Ubuntu from). You can keep USB 2 in the PC, and try turning it on and booting to the USB stick. You should also be able to take your USB to other PCs and boot directly into Ubuntu. As mentioned earlier, keep in mind that you may have to disable secure boot inside of UEFI settings for each computer.

Closing Thoughts




In this tutorial, we saw how to install Ubuntu Linux on a USB stick. While the performance is not nearly as good as installing Ubuntu to a traditional hard disk, it is a unique solution that allows us to carry around a full, persistent Linux installation in our pocket, and we would say that is pretty cool.