One question people often ask me is
“What is the best way to partition a hard drive?”
With graphical installations becoming more popular often hard drive partitioning is overlooked.
If you already have a working installation you can check how your system is currently partitioned by running the command:
bash-3.1# fdisk -l /dev/hdX (depending on your drive)
If you are happy with the performance of your system then reinstalling is not really needed. If you would like to possibly gain a performance increase then you may want to consider reinstalling with a better partitioning method.
Repartitioning your drive
The first thing that I recommend doing when deciding how to partition the hard drive is to figure out what the system is for. Is the system going to be a Linux workstation, desktop, server or application. Knowing this information is not necessary as sometimes computer often have multiple roles but it is good start into setting up your hard drive properly.
There are many ways that a hard drive can be partitioned. Depending on the role of the computer I have different partitioning methods.
bash-3.1# fdisk -l /dev/hda
Disk /dev/hda: 60.0 GB, 60011642880 bytes
255 heads, 63 sectors/track, 7296 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 1 124 995998+ 82 Linux swap
/dev/hda2 7236 7296 489982+ 5 Extended
/dev/hda3 125 7235 57119107+ 83 Linux
/dev/hda5 * 7236 7296 489951 83 Linux
Firstly, my hda1 is swap. I always make my swap disk the first primary partition on the hard drive. This is because its the fasted to access. If your currently running an install, check to make sure your swap is hda1.
My hda2 is not used, this is just a preference that I have, to my knowledge there is nothing wrong with using hda2 as root. I just like to use /dev/hda3 as my root. My root file system for this particular machine is about 95% of the total drive. The other 5% is used for my swap partition and my /boot/ partition. I used /dev/hda5 for my boot partition as this is not so important as it only gets accessed at boot time and when copying kernels to the partition. You don’t have to have a separate boot partition, but I like to just in case I want to export it as an NFS share.
Once your happy with your disk partitioning scheme, the next thing that needs to be done in the partitioning manager is to choose a file system. The file system type for Linux Swap partition is 82 and 83 for the Linux type.
Choosing a filesystem and formatting it.
Most installations will take care of the formatting and adding swap, you just have to choose what type of file system you want to use. I would advise to use the ext3 or Reiser file systems for your root and boot partition. Ext2 is depreciated and has been replaced with ext3. If ext2 is still in your distributions setup it is for legacy reasons and should not be used. I like to use ext3 because its more mature, but I have no problem with using Reiser. Choose one and install your distro as usual.
Once your install has finished and is booted it is good to check to make sure your disk is being used correctly.
I like to double check this because I want to make sure that I am getting the most out of my system. Some times certain distributions don’t set up the drive correctly for stability issues (I’m not pointing any fingers here).
To do this I use the hdparm tool. Quote [man pages]:
hdparm provides a command line interface to various hard disk ioctls
supported by the Linux SATA/PATA/SAS "libata" subsystem and the older
IDE driver subsystem. Some options may work correctly only with the
The first thing to do is run hdparm /dev/hdX (depending on your drive)
I have changed some options for the purpose of this tutorial but here is my current setup:
bash-3.1# hdparm /dev/hda
multcount = 0 (off)
IO_support = 0 (default 16-bit)
unmaskirq = 0 (off)
using_dma = 0 (off)
keepsettings = 0 (off)
readonly = 0 (off)
readahead = 256 (on)
geometry = 16383/255/63, sectors = 117210240, start = 0
Turning DMA on.
Notice, that IO_support and using_dma are set to off.
For performance reasons this should change.
As I know my controller supports DMA I should turn this on. If your unsure if your controller supports DMA you should refer to your motherboard specifications or try it at your own risk.
bash-3.1# hdparm -d1 /dev/hda
setting using_dma to 1 (on)
using_dma = 1 (on)
If you just try it without knowing if DMA is supported, it will either error or may become unstable. Whenever installing a new system, if DMA or 32-bit transfers are turned off, I like to keep the system running for a while and copy large files around to make sure there are no stability issues.
Turning 32-bit transfers on
Now that DMA has been turned on successfully and the system is still stable, I will turn 32-bit transfers on. The same applise for 32-bit transfers as to DMA. The command is the same as before but with the -c1 switch.
bash-3.1# hdparm -c1 /dev/hda
setting 32-bit IO_support flag to 1
IO_support = 1 (32-bit)
Now the basic hard drive tuning has been set up I will run stability tests for a while and make sure the settings work as desired. If the system is not stable, you can try using 32-bit transfers or DMA independently and try to find out which one is guilty or if they both work separately. Which one to use should probably be measured with a bench mark test. This can be done with a benchmarking script, or just by copying a file and measuring the time it takes with both.
Check out your hard drive settings and partitioning scheme and make sure you are happy with the way its set up. If you have the time and want to tweak your system these basic steps should help you with your quest of having lean mean Linux machine.