Advanced

How to Defensively Partition Your Hard Drive in Linux

Posted by Jonquil on · 14 comments
xjonquilx | Linux for the Masses; By Jonquil McDaniel
Mail this story
Print this story

Hardly a day goes by that I don't see a post in Yahoo Answers about how someone installed Linux, messed up the installation beyond repair, and now is facing the possibility of losing all their personal files. This doesn't need to be an issue in Linux, however. In this article I'm going to tell you how you can defensively partition your hard drive in Linux.

Hardly a day goes by that I don't see a post in Yahoo Answers about how someone installed Linux, messed up the installation beyond repair, and now is facing the possibility of losing all their personal files. This doesn't need to be an issue in Linux, however. In this article I'm going to tell you how you can defensively partition your hard drive in Linux.

This is the custom partition layout you want to have:

- One EXT4 formatted 10-20 GB partition with the mount point / - One swap formatted partition that is the same size as your RAM or larger - One EXT4 formatted partition that takes up the rest of space left with the mount point /home

Why do I need this?

You need this so that if you have to reinstall the operating system you won't have to reinstall on top of your personal files. By moving your personal files to a separate partition, we are isolating them so when it comes time to reinstall the operating system you can just format the / and swap partitions and install to them.

What does this mean?

The / partition is kind of like the C:Windows and the C:Program Files folders in Windows. It contains all your operating system and program files. 10 GB should be plenty of space for most users needs, but if you plan on installing a large amount of software you may want to bump that up to 20 GB.

The swap partition is kind of like the "pagefile" in Windows. It is used as space for memory when your available RAM is getting low or when your computer goes in to hibernation. Since it's a substitute for your RAM, it needs to be the same size or larger.

The /home partition is kind of like C:Documents and Settings in Windows. It contains all your personal files and program settings. Since this will take up the majority of space on your hard drive you want to make it as large as possible.

How do I Reinstall The Operating System?

All you have to do is set up the mount points again and format the / and swap partitions. Because of this you need to pay careful attention to the size and order of your partitions. Additionally make sure that you use the same username in the new install as you used in the old install.

Conclusion

If you set up your partitions correctly you should never have to lose your personal files due to a reinstallation of Linux. Once you have your partitions set up correctly after a reinstall of Linux your files will be exactly where you left them, your program settings will remain the same, and even your desktop wallpaper will be the same as when you left it.

  Nav
» Read more about: Story Type: Tutorial

» Get new stories by e-mail: nightly or as they are published

« Return to the newswire homepage

  Related stories
» More like this

Comments (14)

Jonquil

I am unable to load your site, in order to add the missing link. It has never done this before, but Firefox's ABE won't let me load pages from your site.
I cant find the link either, it was there I swear. All the google searches pull the LXer page..

Suggestion: include a /tmp partition also.

I like to also include a /tmp partition of about 15 GB for all of the temporary data when working with audio and video. Great tutorial though, thanks for taking the time to share with everyone.
Right, because we all do video editing on our desktops. Sensible programs (like Audacity) will use on-disk temporary directories.

I concur with the /tmp partition (using tmpfs if possible), but 15 gigs is a bit much for files that aren't intended to survive a reboot.
Confuscius say, "Man who think hard drive space is free, think money grow on directory tree!"
@gus3

Apparently gara3987 works with some pretty hefty audio/video files. And with 500GB being about the smallest disk drive you can buy at most computer stores, 15GB is only 3% of the disk space; a small price to pay when running out of temp space could ruin your work.

Q: Are there distributions that automatically clear /tmp when rebooting? I haven't seen any systems do that by default that since I administered an early version of AIX (back in the early/mid '90s).

If I'd written the article, I think I would have recommended using three disks: one smallish disk for the OS (with current disk sizes that'd still give you an ocean of temp space) and disks two and three configured as a RAID 1 and mounted on /home. (I do this for some of other mount points, too, to keep them safely out of the way of an upgrade or reinstallation.) But for the typical computer user new to Linux it's good to let them know that they don't need to put their personal files at risk by using a single partition. IMHO, distributions that automatically do that as part of their "quick" installation option should be shunned.
rnturn wrote:Are there distributions that automatically clear /tmp when rebooting?
Any system with /tmp mounted as tmpfs. I'm not sure which distributions use that by default, but it's a trivial edit to /etc/fstab.
Archlinux will wipe /tmp at boot, I know because I see a warning about /tmp/lost+found being created every time that filesystem is checked. I know it's not exactly necessary to check an empty filesystem but allowing it to happen wastes less of my time than adjusting the configuration.

Having /tmp on disk is good when some scripts build packages there by default and you don't have a lot of RAM. Apparently you can't build a kernel in 1GB.

By the way,
article wrote:Additionally make sure that you use the same username in the new install as you used in the old install.
I don't think this is necessary, but you should create your users in the same order so they will get the right numeric IDs. And if you mess that up or your new distribution starts counting at a different number it's easy enough to fix with a few variations on
chown -R user:group /home/user
.

partitioning

I have additional partitions called MyDocuments, MyMusic, and MyMisc. That way even if my /home partition gets screwed up, my data is still safe. Don't forget that the desktop settings for YOU will be in the /home/YOU directories. And NEVER NEVER forget to back them up some where off of your machine, just in case your hard drive goes to NEVERNEVER land.
You have a nice suggestion,... Only,... The issue would be where those partitions fill up,... By defining the size of the media partitions separately as you do, you limit the the storage space for that type of media to be no more than that size (assuming you rigidly enforce where that type of media goes). It might be better to simply define a "multimedia" partition, with the users' "Pictures," "Music," "Video" and "Documents" directories point to sub directories on that partition... You could even allow the space to be shared by all users, but enforce file policies to not allow deletion or editing of another user's files, but allow for read only use...
yeah, i keep running into that problem. i am defining less and less partitions in order to make the most of the space. especially on smaller disks. i am now down to /,/boot, /local and /var. only on my largest, 1TB disk i have some extra partitions to separate critical archives from random downloads.

(edit: /home is linked to /local/users)

greetings, eMBee.
I always keep /home separate. On a server having /var separate to preserve logs is important. /boot is legacy for the most part unless you intend on encrypting the root partition.
I always use /, /swap, /home, and /data -- then I use NFS to share /data, which holds all of my data and email/browser settings/data, so that all of my PCs can access them.
@caitlyn, if we can dodge this execrable UEFI cr@p, it may make sense to keep a separate /boot, at least as a "better safe than sorry" thing.

Plus, the Raspberry Pi's CPU is spec'd to load "start.elf" from the SD card's first partition, which must be a FAT partition. That isn't particular to the RPi; it's how Broadcom made it.

Post a comment

A free account is needed to post. Write your comment here first: your text is kept in this browser while you sign up or log in, and is waiting for you when you come back.

Your message:
|||||
10
Markdown: **bold**, *italic*, [text](https://link), - lists, > quotes, $x^2$ for math. Formatting help

Sign up and post (it is free)  or  Log in and post