Wednesday, November 11, 2009

HOWTO: Setup a Linux Storage Partition

Anyone who has use a computer for an extended length of time knows that reformatting now and again is inevitable. For a distro hopper such as myself reformats come much more frequently than they do for most others. At any given point it is not uncommon for me to have two or more Linux distros installed on each of my laptops at the same time. While I like testing new things I also enjoy my laptop being fully functional in the processes and for it to be so I need access to my files regardless of whether I am booted into the latest Ubuntu, Sabayon, Fedora, or what ever other new distro I might be trying that week. While it is possible to share a single home directory for these different distros it can get messy to say the least - different versions of different programs all trying to save settings to the same places (You can see where this can cause issue).

The solution I have come to for such a dilemma is partitioning off a section of my hard drive as a "storage" partition. Essentially this is a large section of the hard drive that is not set to a default mount point for any of the installed distros (on my system I have this partition set to the first part of my extended partition, so sda6, that is formatted as ext3). Once you have your distro installed you can setup your storage partition to be the default save location for many things with a few simple commands. The first thing we need to do is create a location to mount your storage partition to, I like to use the point /mnt/storage (but you can use what ever floats your boat) to create such a point run the following in your favorite terminal: sudo mkdir /mnt/storage Next we have to tell your distro what to put at that mount point - to do this we are going to add a line to our /etc/fstab to do so open the file as super user in your favorite text editor by running something like: sudo gedit /etc/fstab Once you have the file open we are going to add a new line that looks something like this: /dev/sda6 /mnt/storage defaults,exec ext3 0 0 Now assuming you used the first partition on your extended partition for your storage space and the mount point you created is located at /mnt/storage upon rebooting your system it will auto mount your partition for you. (If you need to use a different partition, mount point, or file system type scroll down to the second to last section to see the edits you need to make for the above listed fstab entry to work).

Now that we have your partition setup to mount properly lets configure it so it stores (or looks for) your data there! Things I like to keep on my data partition are my Documents, Pictures, Videos, Downloads, and large game installs (namely Steam). Take any folders you want to keep on the storage partition and cut and paste them there. The last step is to make these folders we have now moved to the storage partition point to their original location using a symbolic link or symlink for short. For example to link a your Documents folder from your storage partition back to your home folder run the following: ln -s /mnt/storage/Documents ~/Documents Lets take a look at this command for a moment ln is the link command and the -s argument tells it to make a symbolic link, then the next two arguments are the source of the actual folder and then the destination to place the link. The result of running the above command is the creation of a folder in your user's home directory called "Documents" that when clicked into shows the contents of the Documents folder on the storage partition. You should repeat the above listed symlinking command for each folder you want to keep on the storage partition.

If you used a different hard drive/mount point/file system than the ones I initially suggested, it is easy enough to change you fstab entry so it works for your particular configuration. The syntax for an fstab line is: [file system] [mount point] [type] [options] [dump] [pass] The important ones are the first three [file system] is the location on your hard drive of your storage partition, for example if it is the first primary partition it would be /dev/sda1. The second part [mount point] is where you want to mount your partition to, just replace this with what ever path you created. The last one we care about is [type] this is simply the file system type you have your partition formatted to (ext3, ext4, ect.). What the remaining three arguments do is a bit beyond the scope of this article take a look here for further reading on them.

Personally I find having a storage partition extremely useful in the case of both multiple distros installed and when reformatting (I do not like to reuse a home folder). All in all it cannot hurt to set one up so - give it a try and let me know what you think!

~Jeff Hoogland


  1. Thanks for the post. Even though its a few years old, I came across it via Google and it helped me out. Thanks again.

    1. Almost 3 years later this is still a setup I use myself - just makes sense!

  2. Good advise! Thanks for your sharing!