Home Learn Linux Linux Documentation How to Bulletproof Linux for Mad Experimentation

How to Bulletproof Linux for Mad Experimentation

Everyone knows that keeping regular backups of our data is the No. 1 best insurance against mishaps. The No. 2 best insurance is smart partitioning on your Linux PC that puts your data on a different partition from the root filesystem. Having a single separate data partition is especially useful for distro-hoppers, and for multi-booting multiple distros; all your files are in one place, and protected from mad installation frenzies. And why not distro-hop and multi-boot random distros? Unlike certain inexplicably popular expensive fragile, low self-esteem proprietary operating systems it's easy and fun. No hoops to jump, no blurry eleventy-eight digit registration numbers, no mother-may-I, no phoning your activities home to the mother ship: just download and start playing.

Just to keep it simple let's start with a clean new empty hard disk. Thanks to SATA and USB adding new hard drives is dead-easy, which I know is totally obvious, but we should regularly take time out to be thankful for cool things like SATA and USB. Because adding new hard disks in the olden days was not easy, and we made do with megabytes. That's right, not giga- and terabytes. Oh, the hardships.

But I digress. So here we are with our new hard disk all ready to be populated with Linuxes and reams of data files. (Why not reams of data? We still dial our phones.) The first thing to do is to write a new partition table to your hard disk with GPT, the GUID partition table. This is the new replacement for the creaking and inadequate old MS-DOS partition table. So how do you install a new GUID partition table? Gparted provides a pleasant graphical interface, and command-line commandos might enjoy GPT fdisk. Use a nice bootable rescue distro to format your new drive, like SystemRescue, or use the partitioning tool in the installer of whatever Linux you are installing.

You may also elect to stick with the musty old MS-DOS partition table if you prefer; the point is to use a partitioning scheme that puts your data files off in their own little separate world.

Partitioning Scheme

You could do it this simply: root, data, and swap (figure 1).

Fig. 1: Simple partitioning scheme to separate root filesystem and data.

Using labels helps you know what's on each partition. This particular partitioning scheme is simple: just map your home directory to the data partition. Your home directory could even be on a separate hard disk. How do you do this? Do it with the installer's partitioning tool when you install a new distro. Or do it post-installation in /etc/fstab, which thankfully is the same as it's always been and has not been "improved" to the point that only a kernel hacker understands how to use it. Like this example:

# /home on sdb4
UUID=89bc6f52-fa07-45a9-b443-25bb65279d6a  /home  ext4  defaults

Now you can muck with the root filesystem all you want and it won't touch /home. This has one flaw, and that is dotfiles are stored in the same place as your data files. This has the potential to create a configuration mess when you have even slightly different versions of the same desktop environment, whether it's on a multi-boot setup or installing a different distro with the same DE. Another potential problem to look out for is your mail store-- some mail clients default to putting your messages in a dotfile. I recommend creating a normal, not-hidden directory for your mail store.

Clever Partitioning Scheme

So here is my clever tweak to avoid dotfile hassles, and that is to keep /home in the root filesystem. Then create a symlink from your homedir to your data partition, which contains only your data files and no dotfiles. This creates an extra level in your filepaths, which is a bit of an inconvenience, but then you get the best of all worlds: your personal dotfiles in /home, and the root filesystem cleanly separated from your data files.

But, you say, I want the same configs in multiple distros! No worries, just copy your dotfiles to your different homedirs. Though the reason for not sharing them in the first place is to avoid mis-configurations and conflicts, so don't say I didn't warn you.

More Clever Partitioning

You can share /boot/tmp and swap on a multiboot system (figure 2). Just remember, when you install a new Linux, to map it to these partitions. It's nice to have /tmp on its own partition in case some process goes nuts and fills it. /var is also a good candidate to have its own partition, but you can't share it-- each Linux installation must have its own /var.

Figure 2: Sharing /boot and /tmp partitions

I give my /boot partition 500MB to a gigabyte on a multi-boot system. The Linux kernel and run around 3-5MB, but initrd on some of my systems hits 30MB and up. I'm not interested in finicky housekeeping and keeping old /boot files cleaned up, so it hits 150MB for a single distro easily.

But What If

What if you already have a separate /home partition, complete with dotfiles, and you want to overwrite your root partition with a different Linux, or install some new distros to multi-boot, and still share your homedir? Easy peasey, though a bit of work: first move all your dotfiles into a new directory in your homedir. Rename your original /home directory to something that doesn't conflict with the root filesystem like /data or /myfiles or whatever. Then install your new Linux or Linuxes and keep /home in the root directory, rather than putting it on a separate partition. Then symlink/data inside your new homedir, like this:

$ ln -s  /data /home/carla/data

You'll want to create an entry in /etc/fstab to make sure your /data partition is mounted at boot, like this example:

# /data on sdc3
UUID=3f84881f-507a-4676-8431-7771a6bc6d39 /data ext4 defaults

When you install a new Linux it automatically installs a set of default dotfiles, and also when you install new applications. If there is anything you need from your original set of dotfiles just copy them to wherever you need them.

What if everything is in your root filesystem and you don't have a separate /home partition? Again all you do is create new partitions, symlinks, and appropriate entries in /etc/fstab.

Be sure to consult du Know How Big Your Linux Files Are? and Linux Tips: The Misunderstood df Command for cool ways to manage filesystems and see what's going on in them, and GPT, the GUID partition table to learn more about GPT and UUIDs.



Subscribe to Comments Feed
  • Nyne Laeven Said:

    I would recommend Logical volumes instead of partitions... create a single "/boot" partition as a primary partition and the rest of the disk to a type 8e partition. create a LVM2 PV, then a bunch of LVs...

  • AleX Swanson Said:

    Yeah. Step One: Create 4 primary partitions... Step Two: Start over with something that makes sense. It also doesn't really work with the sym linking the way the author describes because the path for something like fluxbox config files isn't /home/username/data/.fluxbox Makes no sense.

  • erinn Said:

    You're not understanding how to make symlinks. First you make sure your data partition is mounted and configured to automount at boot, and then make your symlink. If Fluxbox has some kind of odd convention then you merely name the symlink to keep it happy.

  • hameid Said:

    پىروزى هسته اى مبارک باد

  • Karthik Said:

    Hmm... I normally create sda1 (swap), sda2(root), sda3(new-root-empty), sda4(home). Once I install a distro in sda2 use it normally. When I want to experiment with a new distro, install it in sda3 (do not share sda4-home but use a local home inside sda3). Once it looks good, I just change fstab, start using sda3 as my primary root. Erase, sda2 and play with another distro or upgrades...

  • Brandon Said:

    I use a similar approach for mixing a solid-state disk with a traditional spinning hard disk. I install most of the system, including /home, on the smaller, faster, and more expensive SSD with my large amounts of data on the slower, cheaper HDD. I add symlinks in my home directory to the data. That mixed with booting my laptop directly to Linux with the EFI boot stub provides stunningly fast boot times and fast execution. I also recommend LVM2.

  • Tom Pino Said:

    The easiest way to share a /home partition is to take advantage of the multi user capability of Linux. Simply use a different user name. Doesn't need to be a big difference. tom and thom for instance is fine. pete and pete0 would be fine. This way you have 2 / partitions with separate installs, say Jessie and Sid, sharing a common /home with directories /home/pete (jessie) and /home/pete0 (sid). Your ~/.foo files are safely separate. Having a large common Data partition is a good idea so that the data is completely sharable. In many installers it is possible to set up that data partition with installer tools. Manjaro handles this nicely in the text installer and Debian handles it well in their installer. Both do this in the partitioning portion of installation. In both you simply point the installer at the Data partition, give the mount point and tell it not to format the partition. This presents you with a mounted Data partition when you do your first boot into your new install. You can do this with as many installs as you want sharing /home and /Data. The gpt partition table removes the need for an Extended partition full of Logicals. This is great. LVM appeals to many people too. If you have a clean drive, however, the old MSDos system is not all that bad if you simply create one Extended partition covering the entire drive. This does give a rather strange partition numbering sequence. Sda1 Extended and then sda5 for the first Logical and sda6 and so on. Works.

  • Christos Kontas Said:

    Great piece of advices, once again! Of course, I think, one can use the same partitioning scheme with virtual machines, too, where the partitions are now virtual drives. For example, a single swap virtual disk for many different virtual distros. The only drawback here is that only one and single instance of each virtual machine must be activated each time. Yet, it's still a nice walkthrough while testing and evaluating many different distros and setups.

  • Noald Goak Said:

    Looks like it's time to start looking at managed logical volumes using the versatile (if somewhat complicated to begin with) LVM disk partitions. Resize, move and otherwise play around with volumes to your hearts content without affecting the stored data or system utilization of file-system mount points. Flexibility + Stability = Happy User You can even have volumes span multiple physical disks, LVM abstracts your file-system away from your physical hardware. An LVM solution might seem 'over-kill' for a desktop set-up, but if you want maximum 'mess-a-bility' with your file-system then it's really a 'no-brainer'.

  • raugh Said:

    OK, I have a question about the "But What If" section of the article. The goal is to share a data folder (pictures, music, documents, etc) amongst 2 or more Linux installations. But we don't want to share the original distro's configuration .dotfiles that are normally put into a /home directory with the new distro b/c it'll lead to problems. We move any dotfiles to something like /home/dotfiles. After renaming the original distro's home folder to "something that doesn't conflict with the root filesystem like /data or /myfiles", don't I have to I change the home directory on my original distro? Ig so, would I do it like this? usermod -m -d /newhome/username username And if we're moving the dotfiles of the first distro elsewhere, how do we make sure those files are still being used by the first distro? The way I understand this now, the original distro sees no configuration files in /data/user (because those are now in /data/user/dotfiles), and creates new config files.

Check out the Friday Funnies

Sign Up For the Newsletter

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Linux Training / Board