Home » Computing » Linux » Installing GNU/Linux over multiple paritions or disks

Installing GNU/Linux over multiple paritions or disks

Installing software is generally a breeze – run the installer, select the defaults, and hey presto, software installed! Even when installing a new operating system, be it Windows, Mac, or user-oriented GNU/Linux distributions, there are generally sensible and useful defaults provided. But sometimes, the defaults are not enough. Sometimes you need a manual install.

GNU/Linux systems allow you to install your system such that the system files, programs and suchlike all reside on one partition, and the user files, preferences, settings, browsing histories etc reside on another. This is useful at least in two typical scenarios:

  1. Isolating the user files (which live under the /home section of the GNU/Linux filesystem) from the rest of the OS allows you to reinstall the operating system any time, without affecting the user data
  2. If you have a SSD (solid state drive)/HDD (hard disk drive) pair in your computer, you can put your system and swap space on the faster but smaller Solid State Drive, and keep your user files on the slower but significantly larger Hard Disk Drive

This post is aimed at answering the following questions:

  • What are the differences and advantages of SSDs and HDDs each?
  • How do I install Linux using manual partitioning?
  • How do I use mount points in a manual install?
  • How do I reinstall Linux without changing my /home directory?
  • How do I install one Linux system on two different disks?
  • How do I isolate my /home directory on a different partition?
  • What is a SWAP partition/virtual memory?

Solid State Drives (SSD) vs Hard Disk Drives (HDD)

First off, a quick overview of the differences between SSDs and HDDs.

HDDs are the older technology that we used pretty much exclusively in home computers from the 80s to the mid-2000s. They function by having stacks of disk platters spinning at high speeds and a reading head searches for information on it. Compared to SSDs they are:

[+] Inexpensive (20-30 GB per £)
[+] Large (1000-3000 GB not uncommon)
[-] Slower
[-] Use more energy

SDDs are much newer technology. As opposed to their physical spinning disk counterparts, they work purely electrically and have no moving parts, no spinning plates, no reading heads. This has predictable consequences versus HDDs, being:

[+] Faster
[+] Use less energy
[-] Expensive (~2 GB per £)
[-] Small (Generally around 60-120 GB max size)

Desktop tower systems can be equipped with both, or you can custom order one easily with both; and whilst a dual-disk configuration is uncommon on laptops, it’s certainly not impossible. In a dual-disk configuration then, it makes sense to have the operating system on the speedier drive, and the mass storage on the larger drive.

Partitioning

Every GNU/Linux should in principle provide a way for you to perform manual partitioning. If you’re not familiar with hard disk partitions, here’s the basics:

A single disk can be setup as a “single partition,” such that you see its entire space as one disk – this is the most common with flash drives where when you insert it, one extra disk shows up in your list of connected devices.

A disk can however contain multiple partitions. By analogy of the term, a partition in a room allows you to divide a room into two distinct spaces – in this situation the “partition” is the divider. In disks, creating partitions allows you to divide a disk into multiple separate spaces, but the word “partition” designates these spaces themselves, not the dividers.

A disk with two partitions then has two spaces, and if you connect a flash drive with two partitions, it will show up as if you had just connected two disks simultaneously.

You can format each partition independently of eachother (FAT32, ext4, HFS+ etc – you’ll become more familiar with these later) on the same disk, and treat them for all intents and purposes software-wise as indeed different disks.

Mount points and the *nix filesystem

A full description of a *nix (= “any UNIX-like system”) filesystem is beyond the scope of this section, but to simplify: through use, you will know that the filesystem is represented as a single tree, onto which any connected device gets attached.

The top of the tree is the root node, whose path is “/”. Under this there are various directories such as “/bin”, “/var”, “/dev” etc… When disks are inserted into the computer, they often get automatically mounted to one location of “/media”, or “/mnt”, or “/media/<user>”, etc… but alternatively you can manually mount them to somewhere else entirely. In fact, any empty directory will do as a place to designate as “this directory will now contain <removableDiskX>.”

If you have an empty directory for example in “/home/alice/documents/disks/emptyfolder”, you can mount a disk to it, and when you check it again, it will show the contents of the disk (or rather, the partition) that you mounted there. When you unmount it, the directory will be empty again, but any changes to files and folders will have taken effect on the removable disk itself.

One special location in modern GNU/Linux systems is the “/home” directory which holds the user home folders. From the property that any disk can be mounted to any location (so long as that location is an empty directory), you can in effect mount an external disk to an empty /home directory, so that the external disk effectively IS the /home directory.

This is what we’ll be doing in the rest of this tutorial.

Installing GNU/Linux with manual partitioning on two disks

VBox setup 2 disks

For the purpose of this tutorial, I will be using

  • A VirtualBox virtual machine with two virtual hard drives
  • Xubuntu

The choice of Xubuntu is arbitrary – of course, any distro will do, and to follow these specific instructions, you could use any Ubuntu or Ubuntu derivative (including elementary OS, Bodhi, Mint 14 or previous…) and see mostly the same screens. For the rest of these notes, I’ll simply call the system “the distro.” [Note: the more recent Fedora and Korora distros ship with Anaconda as the system installer, which makes the install process less intuitive (in my view) – see here for an overview of how it works differently; I’ll add extra notes in the “reinstall” section soon].

The use of VirtualBox is also of course arbitrary, and the following can be done in any virtual machine, and on any real machine.

The use of two disks is also for the sake of demonstration. Instead of, further down, using three partitions over two disks, you could do this on 3 partitions on one disk, or 3 partitions on 3 disks. The choice is yours.

Start the installer

Load the ISO to your virtual machine, or put the CD/DVD in your computer and start the machine. When prompted to, choose to install the distro. Progress along the screens until you are asked whether to use the entire disk or custom partition. Choose custom partitioning (Ubuntu-based installers: this is “something else”).

Custom paritioning: something else

You will now be presented with the current partitions and drives available to you. You may find that the distro disk is listed, but not necessarily. You will certainly find that all other attached disks are listed. Figure out which ones are the disks you want to install on.

Install on SSD / first partition

Select the correct disk

In my image, both disks are empty and unpartitioned. You may have partitions already present on your disks. Any changes to the partition table will erase the partitions and their contents, so BE CAREFUL if you’re not using empty disks.

In my case, the /dev/sda disk is the smaller SSD (I can see this by checking the other list, the dropdown about the bootloader), and it currently has no partition table. I select it in the top list of partitions, and click “New partition table.”

WARNING: creating a new partition table on a disk erases that disk!

A new table is created for me, and I get a list indicating free space under /dev/sda. I can now select the line indicating “free space”, then click the “+” button to add a partition on the free space.

Add partition

An aside about Swap space

CORRECTION – in the below text I advise to use the SSD for swap. DON’T do that. I’ll re-write the article soon, but DO NOT use the SSD for swap as it will wear the SSD down through excessive read/write operations; HDDs do not suffer in the same way, so put your swap an a HDD.

The first partition I am going to create is the swap space. Swap space is a special location on disk that you never see, that the system can use in emergency to store running programs and resources that normally remain in RAM.

Accessing live memory data from disk is excessively slower than using it from RAM, which is why it’s a system’s last resort; this is also why we are creating this space on the SSD and not on the HDD, which is itself massively slower than the SSD. In older Macs this was known as “virtual memory”; in Windows systems this is known as “page file”.

We say the system is “swapping” in Linux and OS X contexts, and we say that Windows is “paging”, when there is not enough memory to load more files or programs, at which point the system offloads some running programs to swap/page file. The system then swaps applications in and out as needed – leading however to a drastic drop in performance.

Choose “swap space” as filesystem type, and set the size to be equal to the amount of RAM in your system, or double that. Google “ideal size for swap” to read some more pertinent discussions on swap size versus RAM. I normally use double amount as a rule of thumb.

Click OK to create the partition.

Back in the partition list, you will now see a line stating that there is a swap space, and a line indicating more free space. Select the free space line, and click the “+” button to add another partition.

If you are installing 3 partitions only on one disk, set the size of this partition to about 60 GB. If you’re installing on the SSD, and using a HDD in the next step, choose to use up the remaining free space (which is the default)

Choose “ext4” as filesystem type (ideal for Linux, though you could choose any of the others, including FAT32 if you really must – the only benefit this will have is allowing a Windows system to read this partition if it boots the computer, but that should never be a necessity anyway). Choose “/” as mount point. Click OK to apply.

This will be the location where all system files are installed. If you click install now, even the user files will be set up on the SSD and the HDD will remain untouched.

However, we want “/home” to live on the HDD.

If you already have a “/home” directory partition on the HDD, you can select it and simply choose to mount it to “/home” but NOT format it. Note that this is the only way to reinstall Linux without overwriting your /home directory: the /home directory must already have been set up on a separate partition, like we’re otherwise doing now.

In my case there is nothing on the disk, so I can create a new partition table on it, and select the free space to add a partition to. Use the entire disk to be mounted on “/home,” or any size you want. Since this is where personal files will be stored, including web cache, music and videos, documents — all your stuff — this space should be as large as you can allow.

At this point:

  • If you’re only going to boot this machine under Linux, set the filesystem to ext4
  • If you expect you’ll want to dual boot into Windows or Mac OS X and still have access to these files, choose a FAT32 filesystem.
  • If you expect only to dual-boot to Windows, use NTFS if available

Note that FAT32 has limitations on file sizes (max 4 GB for an individual file, which is typically only relevant to servers, or large DVD ISOs).

Click OK to apply. Your setup should now look like this:

Final partition state

Any swap partition will be recognised as such by the system. Any partition that is not marked to be mounted to a mount point will be left untouched.

Ensure that the bootloader dropdown menu points ta the disk on which you are installing the “/” filesystem, and that it is pointing at the disk (eg “/dev/sda”) and not the partition (eg “/dev/sda1”)

Hit the install button. You will be taken through the rest of your installer’s configuration screens at this point. Fill these in as appropriate and wait for the installer to complete. When prompted to restart, do so, and remove the install medium.

When you boot up again, log in to your newly installed system, start a terminal, and run the “lsblk” command.

Lsblk two drives

“lsblk” lists the block devices (storage media) currently connected to the machine, and the partitions contained thereunder, as well as where they are mounted to (if at all). As you can see, “/home” is indeed on a separate drive from “/”

Reinstalling a GNU/Linux

Install a few programs, create a few files in your Documents folder, download a couple of items to your Pictures folder etc.

When you’re ready, install a different distro to the machine – say, Manjaro if you followed along with my Xubuntu – using the same steps.

Most notably, check the note about simply mounting the existing “/home” partition rather than creating it, and NOT formatting (erasing) it.

You can also use the existing “/” partition by simply mounting it to “/” again, and choosing to format it (I have no idea what will happen if you don’t format it, but I suspect it’ll be Funky Chet, so don’t do it on a real system without doing proper testing).

You can leave the swap partition alone.

Once you do that and have a new system, you’ll find that

  • The programs you had previously installed are no longer present. Given the nature of the filesystem, where various libraries are installed (and the differences from system to system), it is rather difficult to separate the “programs” from the “system”; this can vary from distro to distro even.
  • Your program settings and personal documents will however be intact! For example, if you used Firefox under the first system, and use it again under this system, you should find that your browsing history, cookies, and suchlike should still be as before.

Conclusion

If you haven’t done so before, I would urge you to take the time now to back up all your data, and perform a reinstall of your operating system whilst isolating your /home directory.

If anything should happen to your running system, and you need to reinstall it, or if you need to frequently perform a system reinstallation (I’m looking at you Fedora and derivatives!) at least you can ensure that you don’t need to restore your data every single time (though DO back up before a reinstall – always backup!)

Posted in Linux, Tai's FWA

Leave a Reply

Your email address will not be published. Required fields are marked *