A few days back, when my non-techie friend came to visit me at home, he was amazed to see me booting into multiple OSes (4 to be exact) on my machine. He then wanted to know how I accomplished this feat. I told him about creating partitions and how these partitions play a vital role in installing multiple operating systems on ones machine. But this conversation with my friend set me thinking; why is there so much fuss on creating partitions? I think the primary reason that people face this issue of re-partitioning is because they do not think ahead about their future needs.
Even I have faced this problem of re-partitioning my hard disk many a times. And each time, it was a fine balancing but time consuming act of shifting important data from one partition to another, sometimes taking backup and also at times wiping the disk clean and starting afresh.
At present, I run 4 OSes on my machine. Them being Windows XP, FreeBSD, Ubuntu Breezy and Gentoo Linux. For the curious ones, my hard disk is partitioned as follows :
# fdisk -l
Disk /dev/hda: 40.0 GB, 40020664320 bytes
16 heads, 63 sectors/track, 77545 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 38745 19526976 7 HPFS/NTFS
/dev/hda2 38745 47461 4393336+ a5 FreeBSD
/dev/hda3 47462 48466 506047+ 82 Linux swap
/dev/hda4 48466 77536 14651280 5 Extended
/dev/hda5 48467 65902 8787523+ 83 Linux
/dev/hda6 65902 77536 5863693+ 83 Linux
As you can see above, I have divided my entire 40 GB hard disk into three primary partitions and one extended partition and the extended partition is further divided into two logical partitions (See figure below).
You must be aware that one can create only 4 primary partitions per hard disk. The big question is why just 4 ? Why can't we create more than that number? The reason lies in the boot sector. In your primary hard disk, the first 512 bytes is reserved for storing the partition table also called the Master Boot Record (MBR). The problem is that this space fills up after storing just 4 records. So to create multiple partitions, a work around was found out. That is creating an extended partition whose address was stored in the partition table and then creating any number of sub partitions (called logical partitions) inside the extended partition.
Creating partitions is also dependent on the type of file system and OS used
For example, way back when I used to install Windows 95/NT, I remember having to split the hard disk into partitions of 2 GB size. This was because the file system used at that time FAT16 could not reside in partitions with sizes over 2.1 GB. Though the newer version FAT32 or NTFS does not have this limitation.
Similarly, OSes like Sun Solaris and FreeBSD can be installed only in primary partitions.
Deep thought should be given prior to creating partitions
The major work in creating partitions is to decide how many partitions to create and how much space to allocate to each of them. If too little is allocated, within no time, all the space will be filled up. And if too much space is allocated, then there will be a lot of unused space being wasted left around.
Generally speaking for Linux/Unix mail servers, you put the /var directory in a separate partition. This is because the users mail box resides in this directory. And if you are allowing the public to create email accounts on your machine, then in no time, the /var directory will get filled up and will eat up the remaining space on the hard disk and in the process bring the server down. This will not happen if /var resides in its own partition.
Should /tmp reside in a separate partition ?
A few people believe that the /tmp directory in Linux/Unix should reside in its own separate partition. There is a good reason for it. That is, the /tmp directory is world writable. If you do a long listing of the /tmp directory ...
$ ls -ld /tmp
drwxrwxrwt 14 root root 4096 2006-01-28 16:32 /tmp
... you will find that the directory is having read, write and execute permissions for all. Now why is that a bad thing? It is not exactly bad and has its uses. But a hacker (if he knows your IP address and is able to access your machine behind the firewall), will be able to upload and execute programs in the /tmp directory thus making your system vulnerable. For one, he can upload a tiny program to your /tmp directory, which when run will create a core dump.
Core dumps are files of huge sizes (some can be 1 GB size) which are generated when a faulty program is run on a Linux/Unix machine. A core dump can be used by a developer for finding out what is wrong with his program, but that is besides the point. One can imagine what will happen if the hacker repeatedly executes his tiny program and creates a series of core dumps on your machine. In no time, all the space on the hard disk will be filled and your system will crash.
Core dumps are files of huge sizes (some can be 1 GB size) which are generated when a faulty program is run on a Linux/Unix machine. A core dump can be used by a developer for finding out what is wrong with his program, but that is besides the point. One can imagine what will happen if the hacker repeatedly executes his tiny program and creates a series of core dumps on your machine. In no time, all the space on the hard disk will be filled and your system will crash.
Note: I have found out that in Ubuntu the functionality of creating core dumps is disabled by default. So people using Ubuntu can have the /tmp directory in the same partition as the '/' .
Another thing I feel positive about is creating a separate partition for the /home directory. This way, one can easily reinstall the operating system or switch distributions without worrying about creating backups. More over if you are using multiple Linux distributions like I do (see figure above), then you can have the same /home directory for both distributions.
How do you create a partition ?
There are a variety of tools available right from the ubiquitous fdisk to ranish partition manager, qparted, cfdisk to commercial products like Partition Magic. But as a long time Linux user, I would recommend learning to use fdisk. This is because even though it uses cryptic commands, once you master it, partitioning becomes a piece of cake. Also in emergencies, you will not be left high and dry for want of your favourite partitioning tool because fdisk is bundled with all Linux distributions and Unixes alike.
Will partitions ever go out of vogue ?
I think we will have to put up with partitioning for a couple more years. But with the recent interest in virtualisation technologies (like Vmware, Xen, Usermode Linux and QEMU), which allow one to run any operating system over another at the same time, and also taking into consideration the increase in processing power and availability of cheap memory, I feel, may be in 10 years or so, people will opt out of partitioning their hard disks all together.
Update: I forgot to mention that the partition housing FreeBSD (see figure above) was originally a FAT32 partition which I was using to share data between Linux and Windows. Because I felt a bit lazy or just didn't feel like it, I opted for converting the FAT32 primary partition to UFS2 to install FreeBSD. If you are considering dual booting between Windows and Linux, it is beneficial to have atleast a small FAT32 partition to facilitate sharing of data between the two OSes.
Also Read:
Creating and resizing a Logical Volume Manager in Linux
Update: I forgot to mention that the partition housing FreeBSD (see figure above) was originally a FAT32 partition which I was using to share data between Linux and Windows. Because I felt a bit lazy or just didn't feel like it, I opted for converting the FAT32 primary partition to UFS2 to install FreeBSD. If you are considering dual booting between Windows and Linux, it is beneficial to have atleast a small FAT32 partition to facilitate sharing of data between the two OSes.
Also Read:
Creating and resizing a Logical Volume Manager in Linux
No comments:
Post a Comment