How to Partition for Performance & Security

13 09 2008

Since I didn’t find any sound partitioning advice in one single place, I decided to bundle the different tips & tricks and wrote a little guide on partitioning your system. This guide is geared towards linux and a multiple drive and OS setup, but the general tips apply to most systems.

There are several things I want to emphasize. For performance reasons I put the swap partition(s) at the beginning of the harddisk(s). For security reasons – among other – I reserved a separate /home, /download & /media partition. Depending on your personal preferences, hardware setup & data you might want to personalize here. Besides performance and security gains, this well thought-out setup will allow for fluent management, automated backups & synchronizing.

The only sound advise is to try these tips out and test them for yourselves. Check if these translate into performance gains. The tips & tricks provided here are by no means definitive or the only ones available.

Swap

  • Put the swap partition at the beginning of (each one of) your hard drive(s).
    • Hard Disk Drives (the official term) work with magnetics platters. These spin and data access (read & write) times are faster on the end of each platter.
    • Alternatively, you might want to place the swap partition in the middle of your drive. This should reduce seek times
    • Different linux distro’s can use the same /swap partition(s). But if you want to create a separate swap partition for windows, you’ll need to format it as ntfs or fat32. Then don’t forget to modify your settings in the virtual memory tab in windows system settings.
      • If you’re a heavy Photoshop user, you might also benefit of placing photoshop’s pagefile (named scratchfile or scratch disk) on a separate partition, preferably on a drive that doesn’t need to be accessed at the time you’re working in photoshop. Not on the same partition that contains your windows swapfile (pagefile.sys). The same rule applies to other heavy applications that use some form of swap / paging / virtual memory.

Separate Partitions

We’re going to separate the Operating System and applications from normal data. We’ll create different partitions for various operating systems (different linuxes & windows xp ) and for various data (music, video, backups, shared) or system services (swap, boot):

  • /os
    • Logically we need one partition for each operating system. ext3 file systems work well just up to 90% full. So you need to reserve some free space for each os. Generally I always take 20 to 40 GB for an OS, which is way more than enough.
    • To gain performance you might want to trim this down – depending on the OS and how much applications you want to install. The smaller the OS partition is, the faster it can perform a search. This is one reason why we’re separating all these partitions.
    • Since I plan on installing more than one linux distro, I pre-emptively created various partitions called /testareaX where I’ll install some Alpha or Beta distro’s
  • /home
    • I’ll use one single home partition for the several linux distributions I’ll install. But to play on the safe side – to avoid possible conflicts – I’ll create a different user for each OS, so that each one will have it’s own directory in that single /home partition.
    • In case of an OS crash, your /home partition will be unaffected. Or at least you’ll be able to recover it more easiliy.
  • /boot
    • A separate boot partition allows for an easy management of your various OS’s.
  • /download
    • this partition is for all downloads from the net. Since these files might be security risks, I advise a separate partition.
  • /media (/music ; /video ; /photos)
    • If you have large quantities of media like I do, then creating separate partitions for them might be useful later on. This also allows for faster searching: suppose you don’t want to index your films & music, but you do want your /home folder to be searchable, then separating these beforehand allows for an easy configuration in whatever search application you use.
  • /shared
    • If you have a home network, use this place to share files. For this I wanted a LAN-disk, but I screwed up it’s firmware and it’s only usable as an external drive now.
  • /backup
    • Even with all these security precautions in place, you’ll always need a backup. I prefer (and advise) to keep your backups on an external drive. It’s easier than managing DVD’s and possibly cheaper too.
    • You can also put image files of your OS’s here. CloneZilla is one of the many possibilities. A separate /image partition is also a possibility (preferably on another harddisk than which your default OS is installed).

You can only create 4 primary partitions on each drive. But you could for example create an extended partition – next to three primary partitions – that contains several logical partition. Some OS’s (BSD, Solaris, …) have to be installed into a primary partition.

Other guides advise you to create separate /var, /tmp or /opt partitions. Generally this is a good idea, but as long as you’re not planning on running a server it’s not really necessary.

Fstab parameters

Another thing linux users might want to do is to modify the fstab file (/usr/fstab). This is the file linux uses to mount hard drives when booting. Here you can specify some parameters that’ll translate in performance gains.

The noatime options disables the harddrives function of writing access times to your files. You might want to enable this options, depending on your types of files: just add the ‘noatime’ option somewhere between the others. I recommend to disable this for your /media and /backup partitions. Let it enabled for your /home and /root partitions. Some criticial OS systems or other applications might depend on the access-time dates of files. Keep in mind that access-time dates are not the same as writing-time dates, so this won’t pose any problems later for synchronizing.

See the linkdump at the end of this post for further information on fstab. The How to fstab post at Ubuntu Forums provides a decent & thorough introduction. If you’re unfamiliar with it, you’ll need to read up on its uses & possiblities: noatime isn’t the only option that could translate into performance gains. There’s also nodiratime (for directories). And there are other parameters you can specify, for example which filesystems to be checked at boot.

If you’re unfamiliar with fstab, first read up on it (man page, above link). You can also use the application Pysdm, a GUI frontend to change your fstab file.

What more?

I applied this philosophy to my system, which has 3 SATA-II drives: a 300 GB, 320 GB and 500 GB drive. For backups I use an external 750 GB drive. While I might have almost 2 TB storage, that’s possibly not true for you, so you might want to think a bit more thorough on your partition structure.

Keep in mind that this advise is specified for HDDs (Hard Disk Drives). For SSD (Solid State Disk) drives most of these rules do not apply. But do remember to place your OS and possibly also your core applications like Open Office and Firefox on it. These drives are faster than HDDs.

So, the most important part of this post, the first step of any sound guide into partitioning your system is to back it all up. Applying changes in your partition structure may destroy all your files. The easiest & fastest way is to back everything up onto one single drive – preferably external – and format all your internal drives. With tools as GParted or QtParted you can easily move or resize existing partitions when needed, but with large quantities it takes a very long time. If possible, start anew: delete all partitions & begin from scratch.

First some command line goodiness:

If you’re on a Ubuntu system, copy the following into your .bash_aliases file in your /home directory. If the file doesn’t exist, just create it and copy these commands into it.

alias diskid='ls /dev/disk/by-id -lah'
alias disklabel='ls /dev/disk/by-label -lah'
alias diskuuid='ls /dev/disk/by-uuid -lah'

In your terminal, the command diskid will give you al list of your harddrive ID number; disklabel the label, and diskuuid the UUID of your harddrives. If not on a ubuntu system, just use type into your terminal whatever is between the quotes. Remember it’s that easy to make aliases.

The following command will give you an overview of your total and free hard drive capacity (watch out, this is a single-line command:

df | egrep -v "(Filesystem|\/dev$|shm$|dvd|cdrom)" | awk '{totalu += $2 ; totalf += $4} END {print "Total space in devices: " (totalu/1024/1024) " GB\nFree space total: " (totalf/1024/1024) " GB"}'

If you have different types of harddrives, you might want to check which one is the fastest (and install your OS & applications on that drive). The easiest way to find out is with the application hdparm. The command:

hdparm -Tt /dev/sda

will show you the read & write performance of your harddrives. You’ll want to use that command with no applications running, so don’t boot into GUI mode, or just run a live CD and run the command from there. If necessary replace the path (IDE disk use /dev/hda, if you have multiple disks, these will be named /dev/sda, /dev/sdb, /dev/sdc, and so on).

Partition & Directory Structure

You can use GParted to format, add, delete, move or resize partitions, be they windows (ntfs, fat32, …) or linux (ext3, …) or other file-systems.

The image on the left shows a tree I made (with kdissert), representing my different disks & partitions. Click the picture to view it full-size.

You’ll notice i took into account the above guidelines. However, I did not create a /boot partition, but instead 2 /rescue partitions. One will serve as a simple small linux install (maybe damn small linux, slitaz, slax, or Puppy Linux), and another one I reserve for a later project: a personalized boot loader (Grub, or SuperGrub disk) that can load any OS installed and also applications such as GParted or QtParted, SystemRescueCD, Partimage, DriveImage XML, Ultimate Boot CD, …

I also prematurely planned in a /shared partition on a non-existent NAS (mobile LANdisk), since I plan on rolling out a home network.

So now a few screenshots that clarify my specific setup:

  • /dev/sda (300 GB)

  • /dev/sdb (320 GB)

  • /dev/sdc (500 GB)

  • /dev/disk (750 GB)
    • One single partitions that contains predominantly backups:
      • /home, /media, /music, /imglinux & /imgwin

In the above screenshots, the partitions that have a key-icon, are the ones that are automatically mounted at boot (/swap partitions, /ubuntu (root), /home, /download, /music & /media).

You can see that I have an ntfs-swap partition for windows xp. It’s important to know that – if you have only sata drives – windows will not install without an ntfs (or fat32/fat16) partition on your first harddisk. This is where windows will boot from. Your first disk is the /sda one, the one connected to your first SATA port on your motherboard. I installed windows xp on the /sdb disk (which needs to a primary partition), which follows the guideline to place your swap on another drive than your OS is installed.

If you want to access (read & write) ext2/ext3 partitions from within windows, you’ll need the application/driver Ext2 IFS. Contrary to what you might expect, this driver will enable read & write access not only to ext2 file-systems, but also ext3 file-systems.

I created 6 /testareaX partitions, where I’ll install different linux distributions (probably beta versions of Fedora, OpenSUSE, Debian & Ubuntu Server Edition among others). Such a setup is useful for geeky people like me who want to try out different distributions or plan on participating in the open source development.

I also created a /virtual partitions, where I’ll put the virtual OS’s installed with VirtualBox. The /image partition contains image files of my 2 freshly installed correctly configured OS’s: Ubuntu & Windows.

On the two /rescueX partitions I’ll install either damn small linux, slitaz, slax, or Puppy Linux. I’ll also experiment with GRUB & SuperGrub for bootloader/recovery tool. In the ideal case I’d like to be able to start applications such as GParted, CloneZilla, TestDisk, Ultimate Boot CD, etc. from a bootloader, without needing Live CD’s.

Conclusion

To summarize:

  • Put the swap partition at the beginning of your hard disks. 4 GB is more than enough. Multiple swap partitions could mean a performance gain.
  • Separate your data from your applications and os. (/ubuntu from /home & /media, /music, /video, … ; /winxp from /windata)
  • Create a separate /home partition, /download (or /tmp), /backup (preferably external), /network (preferably on a lan-disk) and possibly a separate /boot partition.
  • Limit the size of your OS partition, but make sure you run out of free space.
  • If you plan on trying out different OS’s, pre-emptively create some /testarea partitions. (And if any of these OS’s might be BSD or Solaris, then create that partition in a primary partition, not a logical one, or you won’t be able to install them.)

Many of these ‘tips & tricks’ might & will be misunderstood if interpreted in the simple way they’re described here. Expanding on them would’ve brought us too far from our goal, but if you do plan on following through on this, you should at least take a glance into the link dump first. Most of above advise is based on these articles:

Linkdump: