When installing a Linux distribution one one of your company’s Servers, you will need to setup and configure System partitions. Disk partitions are logical subdivisions of you hard drive which contain individual File Systems. Partitions are used to store data within your Operating System.
There are many reasons why you should create several partitions on your hard drive. You may want to place the /home directory in a different partition thus ensuring that user data is isolated from other directories. You would also want to create a separate swap partition for maximizing the swap speed. Remember that in Linux, the swap partition is not mandatory and you can run your OS without it. If you do want to add a swap partition then, the size can be configured from 1B to 16 TB. I recommend always creating a separate swap partition that is at lest 1.5 the size of your RAM memory thus ensuring that all RAM data can be swapped if needed. The way you partition the hard drive depends on the purpose of the System and the hardware configuration.
Linux Systems support several partition type, as follows:
- primary partition – the main partition type that exists in Linux, it’s usually used for storing OS data. Unlike Windows, the OS can also be booted from a logical partition.
- extended partition – because the MBR architecture supports only 4 primary partitions, the extended partition was created to surpass this limitation.
- logical partition – a partition created on an extended partition. Remember that you can also install the Linux OS on such partition. You can create a lot of logical partitions on a hard drive. I don’t know the exact number but, I’ve heard it’s around 255
We’ve learned from a previous article that in Linux, everything is treated and displayed as files. The same principle is applied with hardware devices. Every physical component is presented as a file and it’s stored under /dev directory. There are several hard-disk types that Linux supports and you can visualize each of them in /dev:
IDE devices – can be either hard-drives or CD/DVD readers/writers. In older Systems there were two IDE controllers, each one supporting two devices (one primary and one slave). In the recent years, IDE devices have been replaced by SATA but, you should know how are displayed in the OS:
/dev/hda – primary master
/dev/hdb – primary slave
/dev/hdc – secondary master
/dev/hdd – secondary slave
I’m using a Virtual Machine on which I’ve installed CentOS distribution. If I navigate to the /dev directory, this is how my hard drives are displayed:
SATA, SCSI and USB devices are seen in the OS as /dev/sda, /dev/sdb and so on. This is the order in which they were connected.
You are probably wondering why is there sda1, sda2 and sda3. Well, I’m using a hard drive with three partitions. In Linux, when you create a primary partition it will be something like /dev/sda1, /dev/sda2, /dev/sda3 and/or /dev/sda4. These are the four primary partitions (including the extended partition) that you can create on a Linux distribution.
Logical partitions have names similar to /dev/sda5, /dev/sda6 and so on. Note that even if you haven’t created all the primary partitions, the logical partition naming will still start from sda5. These identifiers are reserved and cannot be used otherwise.
Remember that in Linux, there is only one file system tree presented to the user. You are probably wondering what happens when you create a partition for / (file system root), one for /home directory and one for /var. The / (root) partition will contain both /home and /var directories but, they will be empty and the real content will be placed in the individual partitions. Upon booting the OS, the root directory of each partition will be mounted to the / partition thus creating a singe file system tree. Those empty folders from the / partition will become the mount points for other partitions.
But how does the OS know how to mount partitions and which are part of the file system? The root partition (/) is recognized by the kernel because the boot manager contains the necessary information regarding it. After the / partition is mounted, the kernel will look in /etc directory for the fstab (/etc/fstab) file which contains all the info regarding the file system and the mount points. Linux offers the possibility of mounting file systems and partitions from other OS like Windows. The protocol used to “export” files in Linux is NFS (In Windows, “file sharing” is made using SMB). Mounted partitions for other OS and are located under /mnt directory. CDs and DVDs will be mounted under /media directory.
I think we’ve covered the main aspects regarding Linux partitions and how these are visible from the OS. Don’t hesitate to post a comment with anything that’s relevant on this topic. I’m always opened to suggestions and because I’m still at the beginning with Linux, any advice is more than appreciated. Enjoy your day folks!