DEV Community

Stack All Flow
Stack All Flow

Posted on • Originally published at stackallflow.com on

How to Install Ubuntu on a Portable External Hard Drive?

external-hddsystem-installation

OS: Windows 7. I want install Linux Ubuntu on portable external Hard Drive USB 2.0.

I read a variety of methods, but I’m confused by contradictory advices and methods. Actually, installing Ubuntu on anything other than clean PC looks much more complicated than installing Windows.

I need to have Ubuntu package + Python 2.7 + C compiler installed. My external hard drive is partially filled, I need to keep all files.

Will Ubuntu run entirely on external hardrive, without writing anythinhg to Windows system folders and to registry?

Can anyone post detailed guide how install Ubuntu on external hard drive?

Accepted Answer

A very detailed answer would be beyond the scope of a single question, but here’s the general outline. It’s very easy, but success will partly depend on the ability of your computer to boot from an external hard drive. This depends on the bios.

Before starting, make sure your bios has an option to boot from a USB HD.

If all you need is the basic install, Python 2.7, and the C compiler, you can get away with installing Ubuntu to a fairly small partition. I forget the literal minimum Ubuntu needs to install, but it’s roughly 8 GB. I would recommend 10 GB as a minimum, plus another 2-4 GB if you want a swap drive.

Create space for a partition

It’s best in your case to create the new partition before doing the install. You will need to shrink the existing partition on your external hard drive first.

I would recommend backing up the USB HD; but if you had a second one, you could just install to that one. Depending on how full the drive is, you may not be able to back it completely; but try at least back up any important files. This is just a general warning and precaution since your data should be safe.

You have two options to shrink the existing partition:

  1. Use the Windows partition manager in administrative tools. I believe these are available in Home Premium. If the partition won’t shrink by enough, you may need to delete files to make room. If you have more than enough available but it still doesn’t shrink enough, use a free defrag tool like MyDefrag to defrag and move the files to the start of the partition.
  2. Use gparted from the Ubuntu live install media. This is probably the easier way to do it.

Create a new partition

Create the Ubuntu live installation media and use it to boot your computer. Choose Try Ubuntu.

Plug in the external hard drive. Start the program gparted. If you have not already shrunk the partition on the external HD, do it now.

In most cases, the internal HD will show up as sda and the external as sdb, but this is not guaranteed. Be sure you are looking at the correct HD in gparted.

Shrinking the partition will leave unallocated space. Use this to create a new partition. Format it to ext4. Jot down the partition number. This will be used for /.

You don’t need a swap partition, but if want one, shrink the new partition by the size you want (or just make it a little smaller in the first place). Format that space to linux-swap.

Note down the numbers of the new partitions.

Run the Installer

Start the installer from the icon on the desktop or on the launcher. When asked how you want to install, choose: Somethine Else.

This will start the partitioner within the installer. This is different than gparted and may look a little intimidating to a beginner.

Carefully highlight the new partition (check the number and drive carefully) and click Change.

Follow the dialogs to a. Use the partition as ext4, b. mount to /, and c. format.

Highlight the swap partition and click Change. Choose use a linux-swap and that’s all for that one.

Very important: change the installation of the bootloader to the USB HD. This will most likely be /dev/sdb. This will prevent you from overwriting the master boot record on your hard drive. (If you do this by accident, it’s easily fixed).

Double-check your partition choices, then click Install Now.


That’s it. To run Ubuntu, boot the computer with the USB plugged in. Set your bios order or otherwise move USB HD to the first boot position. The boot menu on the usb will show you both Ubuntu (on the external drive) and Windows (on the internal drive). Choose the one you want. If you boot without the usb, you will boot into Windows normally.

Ubuntu has Python 2.7 installed by default. To install the C comiler, open the terminal, any run:

sudo apt-get install gcc

Enter fullscreen mode Exit fullscreen mode

or

sudo apt-get install build-essential

Enter fullscreen mode Exit fullscreen mode

(if you want some additional programs helpful for C programming).


To run Ubuntu in a virtual machine instead, install VirtualBox or VMWarePlayer in Windows. Both are free. Create a new VM and use the installer media to install to the VM. But this time, don’t worry about partitions. Choose Install Ubuntu to the entire virtual drive. This doesn’t affect the rest of the hard drive.

If you want to put the VM on the external hd, be sure to override the default location when creating the VM and put it on a folder on the external drive.

Creating your installation media with persistence through a Windows program like LiveUSBCreator will also work, but this option will be very slow.

The post How to Install Ubuntu on a Portable External Hard Drive? appeared first on Stack All Flow.

Top comments (3)

Collapse
 
geraldew profile image
geraldew

Ok, with time spare again I've now read the whole post. I see this has been written as a posed question along with a provided answer, which I hadn't realised on a first reading.

Nonetheless, the solution then given takes a different tack compared to my stock method. So that's what I'll now cover.

So in short, the question asked was:

  • Will Ubuntu run entirely on external hard drive, without writing anything to Windows system folders and to registry?

And in short, the answer to that is yes. It is quite possible.

A thing to note however, is that once the booting technology in use is EFI (otherwise known as UEFI), there is more than just the "Windows system folders and .. registry" to worry about. If this distinction is overlooked, then you can find yourself in a situation where updates of either system will interfere with the other (by rewriting the ESP partition).

The other thing to note is that relying on settings on one hard drive (the one internal to the computer) to control how you boot the other (external USB) can cause problems when you don't have both of those in place. Say:

  • when the USB drive is elsewhere, you now have a boot option that won't work (somewhat obviously)
  • a USB drive with Ubuntu Linux on it that can't (easily) be booted in another computer.

Aside: the original question doesn't make it clear if the "OS: Windows 7" is also on a USB drive - or even perhaps the same one. As I don't use Windows much I don't have any experience of installing it to external drives. For this context I'll assume that was internal.

However, another part of the situation given just before that question was:

  • "My external hard drive is partially filled, I need to keep all files."

I would concur with the given answer that it is much better to copy that material off to another drive, perform the new setup and test it, then copy the files back. Assuming the requirement is to have those files instantly accessible to both the Linux and Windows boot, then my method would need adjusting to carve out a partition for them (probably at the end) and formatted as NTFS.

It would be possible to do it all without copying them off and back, but I can't imagine that as being worth the complications involved.

Some other points I'd make:

  • Will USB2 be ok for this? Yes. Will USB3 be noticeably better? Yes.
  • What size USB drive is required? While my article is mainly about using hard drives, I do also use the same technique with USB "thumb" drives - i.e. memory sticks. I have a 16GB one with Ubuntu 20.04 on it, and have had to run a cleanup script a couple of times to make room for updates to work. FWIW the culprit is Snap. I also maintain a 64GB thumb drive with Ubuntu 20.04 without that problem. At a guess, a 32GB might be minimum size to recommend.
  • lately, USB hard drives on the market are coming as Shingled Magnetic Recording (SMR) rather than the older Conventional Magnetic Recording (CMR). I can vouch that SMR drives are NOT suitable for use as bases for a running system. The symptom you'll encounter is that your system will just pause for ten seconds at a time while the drive reshuffles the shingles on write. Alas, like EFI, that becomes a whole other topic and is controversial as manufacturers are being neither open nor clear about which they are using.
Collapse
 
stackallflow profile image
Stack All Flow

Excellent Explanation.

Collapse
 
geraldew profile image
geraldew

Well, I did write this:

for the similar reason of not being happy with the methods that I'd seen.

When I have another moment I'll come back and read your piece in detail to see if I can give a better reply.