What is Partition?
Partitioning means dividing a single hard drive into many logical drives. A partition is a contiguous set of blocks on a drive that is treated as an independent disk. A partition table is an index that relates sections of the hard drive to partitions. Each operating system has its own rule of using partitions as it wishes and doesn’t touch the other ones. This way the many operating systems can co-exist peacefully on the same hard disk.
CD-ROMs are usually also not partitioned, as it is easier to use them as one big disk, and there is a very rare case where it has to have several operating systems on one. Floppies are not usually partitioned. There is no technical reason against it, but since they’re so small, partitions would be useful only very rarely.
Why have multiple partitions?
- Increase disk space efficiency. You can format partitions with varying block sizes, depending on your usage. If your data is in a large number of small files (less than 1k) and your partition uses 4k sized blocks, you are wasting 3k for every file. In general, you waste on average one-half of a block for every file, so matching block size to the average size of your files is important if you have many files.
- Encapsulate your data. Since file system corruption is local to a partition, you stand to lose only some of your data if an accident occurs.’
- Limit data growth. Runaway processes or maniacal users can consume so much disk space that the operating system no longer has room on the hard drive for its bookkeeping operations. This will lead to disaster. By segregating space, you ensure that things other than the operating system die when allocated disk space is exhausted.
Structure of Disk Partition
- On the disk where O/S is installed, It has the first partition as MBR.
- MBR is a Master Boot Record, which contains two important utilities, IPL (Initial Program Loader) and PTI (Partition Table information).
- IPL is responsible for booting the operating system because it contains the boot loader.
- In earlier versions of Linux i.e. up to RHEL 4, the default boot loader was LILO (Linux Loader). But, since RHEL5 onwards it has been changed to GRub (Grand Unified Boot loader), which is far more superior to LILO.
- The PTI (Partition Table information) is the information about the number of partitions on the disk, sizes of the partition, and types of partitions.
Criteria of Disk Partitioning
- Every disk can have only 3 Primary Partitions.
- Primary Partition is a partition that usually holds the operating system. Only one of the 3 primary partitions can be active which will be booted by MBR to load the operating system.
- Extended Partition is a special type of primary partition that can be subdivided into multiple logical partitions. As there can be only 3 primary partitions per disk, and if the user is required to make further partitions then all the space remaining on the disk should be allocated to an extended partition, which can be used to create the logical partitions later. There can be only one extended partition per disk.
- Logical partitions are the partitions that are created under the extended partition, all the space in the extended partition can be used to create any number of logical partitions.
Different types of disks will have different initials in Linux.
- IDE drive will be shown as /dev/hda
- SCSI drive will be shown as /dev/sda
- Virtual drive will be shown as /dev/vda
It is a method of storing the data in an organized fashion on the disk. Every partition on the disk except MBR and Extended partition should be assigned with some file system in order to make them store the data. File system is applied to the partition by formatting it with a particular type of file system.
File system acts as a digital index that lets the computer instantly find a specific file, regardless of the size or configuration of the storage drive or where the data bytes associated with the file sit on the drive’s storage platters.
Types of File System in Linux
The file systems supported in Linux are ext2, ext3 and in RHEL 6 ext4, vfat, etc.
Ext file system is the widely used file system in Linux, whereas vfat is the file system to maintain common storage between Linux and Windows.
|1||Stands for Second Extended File System||Stands for Third Extended File
|Stands for fourth extended file
|2||It was introduced in 1993||It was introduced in 2001||It was introduced in 2008.|
|3||Does not have journaling feature.||Supports journaling feature.||Supports journaling feature.|
|4||Maximum ext2 file system size
can be from 2TB to 32TB
|Maximum ext3 file system size
can be from 2 TB to 32 TB
|Maximum ext4 file system
size is 1 EB (Exabyte). 1 EB
= 1024 PB (Petabyte). 1 PB =
1024 TB (Terabyte).
|5||Maximum file size can be from 16
GB to 2 TB
|Maximum file size can be from
16 GB to 2 TB
|Maximum file size can be
from 16 GB to 16 TB
|6||Cannot convert ext file system to
|You can convert an ext2 file
system to ext3 file system
|All previous ext file systems
can easily be converted into
ext4 file system. You can also
mount an existing ext3 f/s as
ext4 f/s (without having to
Commands used in partitioning
- To view the existing partitions
#fdisk –l or parted –l
- Partition Administration using fdisk
To enter into disk utility, the syntax is #fdisk <disk name> #fdisk /dev/sda Use m to list out various options that can be used in fdisk.
- Creating a new partition
#fdisk /dev/sda Use p to list out the partition information first and Use n to create a new partition.
- Deleting a partition
Use d to delete a partition and specify the device name
- Saving the partition changes
Every time you make a partition or delete a partition, the changes made have to be saved using w,
otherwise, the creation and deletion will not be considered to happen.
- Updating the partition table without restarting the system
After creating or deleting a partition the changes will be effected in the partition table only after
the restart of the system. But there is a way to avoid this circumstance. We can use partprobe or
partx command to update the partition information without restarting the system.
- Formatting a partition with ext4 filesystem
After creating a partition we need to assign some file system to it so that we can start storing the
data into it. To format a partition the following syntax is used.
# mkfs.<file system type> <partition name> #mkfs.ext4 /dev/sda5 (where sda5 is our newly created partition)
Likewise you can format the different partitions with different file systems like #mkfs.ext3 /dev/sda8 #mkfs.vfat /dev/sda9
Note: Even after formatting the partition we cannot add the data into the partition. In order
to add the data in the partition it is required to be mounted.
- Attaching a directory to the file system in order to access the partition and its file system is known as mounting.
- The mount point is the directory (usually an empty one) in the currently accessible file system to which an additional file system is mounted.
- The /mnt directory exists by default on all Unix-like systems. It, or usually its subdirectories (such as /mnt/floppy and /mnt/usb), are intended specifically for use as mount points for removable media such as CDROMs, USB key drives, and floppy disks.
Files which is related to mounting in Linux
- /etc/mtab is a file that stores the information of all the currently mounted file systems; it is dynamic and keeps changing.
- /etc/fstab is the file which is keeping information about the permanent mount point. If you want to make your mount point permanent, so that it will be mounted even after reboot, then you need to make an appropriate entry in this file.
Mounting a Partition
Mounting is a procedure where we attach a directory to the file system. There are two types of
mounting which will be used in Linux or any UNIX.
- Temporary Mounting
- Permanent Mounting
In a temporary mount point we will create a directory and mount it, but this mount point will last
only till the system is up, once it is rebooted the mounting will be lost.
Syntax: #mount <device name> <directory name (mount point)> #mount /dev/sda5 /kernel
To View all the mounted partitions
Unmounting a partition
#umount <mount point directory> #umount /kernel verify it with mount command.
Permanent mounting procedure is exactly the same as temp mounting, but here we will update the
/etc/fstab file with the mounting details, so that it will be mounted even after the system is
Steps to make a permanent mount point
- Make a directory or use an existing directory
- Add entry in /etc/fstab file
- Use mount –a command to check it is mounting. (mount –a will mount all the entry
placed in /etc/fstab)
Creating a Swap Partition
Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM. Swap space is located on hard drives, which have a slower access time than physical memory.
Recommended System Swap Space
|Amount of RAM in the system||Recommended amount of Swap Space|
|4GB of RAM or less||A minimum of 2GB of swap space|
|4GB to 16GB of RAM||A minimum of 4GB of swap space|
|16GB to 64GB of RAM||A minimum of 8GB of swap space|
|64GB to 256GB of RAM||A minimum of 16GB of swap space|
|256GB to 512GB of RAM||A minimum of 32GB of swap space|
The basic rule for the size of Swap
Apart from the above recommendation, a basic rule is applied to create the swap partitions
- If the size of the RAM is less than or equal to 2GB, then the size of SWAP=2 X RAM SIZE
If the size of the RAM is more than 2GB, then the size of SWAP= 2GB + size of the RAM
Swap space is compulsory to be created at the time of installation. But, additional swap spaces can be created and deleted at any point in time, when it is required. Sometimes we need to increase the swap space, so we create additional swap spaces which will be added to the existing swap space to increase the size.
Commands to be used in maintaining Swap spaces
To see the memory size and the swap space size
To see the swap usage use
To format the partition with swap file system use
#mkswap <parititon name>
To activate the swap space use
#swapon <partition name>
To deactivate the swap space use
#swapoff <partition name>
Making a newly created SWAP partition to mount after reboot
- In order to make the swap partition mount automatic after reboot, we need to make an
entry in /etc/fstab file.
You can read more about the operating system in my another post What is Operating System
I hope you like this post, if you have any questions? please leave a comment below!
Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing to my blog.