A Flexible Partition Layout for your Linux PC

There's an option in fstab that I think is relatively new. It lets you mount devices by label. The label it uses corresponds to the label you can give a partition with the e2label command. In KDE the labels also show up in the "My Computer" view in Konqueror.

The reason I mention this is that I think I've hit on a nice way to make your system more flexible. Normally when you install SuSE it defaults to creating a swap partition, a ReiserFS partition for the OS, and another ReiserFS partition for your /home folder. Or something like that. If you look at the advanced options, the installer plans to set up your fstab to mount devices by their names, like /dev/sda2. I leave the swap partition as is, but I change the others. First off, I use ext3 because it's more backwards compatible with ext2. Next I create a few partitions for OS installations. This time I made 3 so that I have one for OpenSuSE 10.1, another to try out a different OS if I feel like it and still one more for my next upgrade. Each OS partition is 20GB. When I say "OS" partition I really mean the space to install a Linux distro and all the apps that I use for that particular installation. It also includes the home folder for the root user - /root. Everything that's not on an OS partition is in /home. On my last install I also made partitions specifically for holding backups (of my web server) and other specific types of data. That worked out for that PC but this time I'm not sure what I'll need so I'll resize my partitions with parted when I figure it out.

Now comes the clever part.

In the fstab options for the installer (and in the Expert Partitioner in YaST) you can decide to mount in /etc/fstab by volume label.
To choose this option you'll also need to enter a volume label for the partition. I choose labels that completely ignore my current intended purpose for the volume. That avoids the situation where I have a volume labelled "centos" which later actually contains a Fedora Core 5 install or a bunch of photos. So I pick volume labels based on geographical features of one of my favourite places, Georgian Bay. I mean, if you need an arbitrary name, why not look at Honey Harbour? So I come up with a plan for partitions of my 320GB Seagate that looks like this:

Partition    Size     Name Purpose
/dev/sda1 2 GB    swap
/dev/sda2 20 GB   Deer - OpenSuSE 10.1
/dev/sda5 20 GB   Honey - planned for Kubuntu
/dev/sda6 20 GB   Mermaid - planned next upgrade
/dev/sda7 216 GB Royal - home partition

There's an important distinction between being flexible and not planning. It's critical to write down a plan like this on paper or in a text file before you start your install. Otherwise you'll stare at the installer and have to sit there until you figure out. Then when something goes wrong and you start the install over you'll have to figure it out all over again. My notes are here in my blog, put yours in the comments if you like ;).

For each partition except the root of the current OS, I tell the installer to mount under /mnt in a directory with the same name as the volume label. Depending on the purpose of the partition it might get mounted somewhere else as well, but I can always find it under /mnt/<name>. This has been an invaluable convenience in the past when I have a feature that works in one OS and not in another. It also means I can keep the previous install of my Linux that I was using - it's live so I don't have to dig up a backup to see how something worked.

Here's a concrete example of how this helped me out on my old desktop. That system has four 14GB OS partitions. Mauriat suggested keeping several concurrent OS partitions and helped me come up with the layout. I originally intended to install CentOS to mimic my VPS and Fedora for day-to-day use. Another partition was expected to run TrixBox so I could try it out. one more would have the next version of CentOS so that I could plan an upgrade for the VPS. Well as things turned out I turfed the VPS and TrixBox doesn't install without wiping the hard drive (even though the Anaconda installer will install CentOS and none of TrixBox). While I messed with all this stuff I always had a stable FC4 installation to work with. When in FC4 all the files of the other OS installations were avaiable at all times to poke around in. Not only that, but as I changed the versions of Linux that I was running, my boot menu always offered me choices of Beausoleil, Portage, McQuade or Centennial (islands in Georgian Bay again). That gave me a distinct name for a specific installation of CentOS 3.4 when I had two of them. People need names for things, it's fundamental to being able to abstract a problem and talk about it.

That desktop is still up and running with the same names for the partitions. I also try to update the boot menu with a comment that has the date of the install. Now I've got my old FC4 install, an FC5 install that I tried out for a short while, and my OpenSuSE 10.1. My upgrade was painless because I was able to look at all the config files in /mnt/beausoleil/etc/ and copy snippets that I needed. Even months later, when I finally got around to setting up dual display in SuSE, I still had /mnt/beausoleil/etc/X11/xorg.conf look back at and run a diff on.

Jeff just had one of his computers go down. It was a dual-boot Windows 2000 / SuSE box. He replaced the hard drive and so we talked about the easiest way to get the SuSE install (which was probably still there) back up and running. Moving the hard drives around changes their place in /dev, for example /dev/hda might become /dev/hdb just as C: becomes D: in MS Windows. While discussing it I realized that mounting by volume label may have simplified the situation greatly.

Okay, so if you're convinced that mounting by label is a great idea and you want to do it but you're already set up some other way then I think you can change stuff around as you like. Be aware doing things wrong here might leave you with a system that won't boot. Make sure you read up on this stuff elsewhere. If you haven't done anything like this before then I don't recommend just following my instructions - I'm not even testing these out. I don't worry about it for two reasons: 1. Mine's already done 2. I have another computer if this one breaks.

If you look at YaST2 there's a Partitioner option under System that launches the Expert Partitioner. It looks like that has the same options as you're given during installation. You might be able to change the label and set the mount options for fstab from that interace just by choosing your partitions and editing them. Note that you don't really know if it worked until you reboot (and you see if your system even comes up).

The other option is the command line. Look at e2label to label the volume then edit your /etc/fstab directly. The relevant lines in my /etc/fstab look like this

LABEL=deer      /       ext3    acl,user_xattr 1 1
LABEL=honey     /mnt/honey      ext3    acl,user_xattr 1 2
LABEL=mermaid   /mnt/mermaid    ext3    acl,user_xattr 1 2
LABEL=royal     /home   ext3    acl,user_xattr 1 2
/dev/sda1       swap    swap    defaults 0 0

Remember, this is another one that works for me. I just want to share the idea and hope it helps. If you decide to try it be sure you understand exactly what each command will do before you try it and make sure you can recover from a command shell. Good luck.

5
Your rating: None Average: 5 (2 votes)

You should have at least told people to backup their fstab file before doing anything, then they can use a grub or opensuse boot disk to restore it if they really screw something up. Matter of fact, I guess I just did that...

Okay: backup your fstab before doing anything. In my defense, I did say "Be aware doing things wrong here might leave you with a system that won’t boot."

How did you modify fstab, through YaST or did you edit it directly?

Didn't do anything, actually. But I would suggest a simple:

cp /etc/fstab /etc/fstab.backup

How about telling something about error codes that might be encountered. This would be especially helpful if you are labelling your root drive

I would but I didn't run into any. Generally I try to stick to things that I actually did that worked for me. If I speculate too much then I could end up misleading people.