Partitioning is very important task and regular task for the Linux / Hadoop admins. Usually when we start doing the build activity when come to work with disks first tasks is to create the disks and partitions.
What is Partitioning?
In simple terms, process of dividing a single hard drive into many logical drives. In process terms, A partition is a continuous set of blocks on a drive that are treated as an independent disk.
1. MBR Disk partitioning
2. GPT DIsk Partitioning
MBR Disk Partitioning
MBR – Master Boot Record
Each disk has 4 Partitions. (3 Primary + 1 Extended).
Primary partition is a partition which usually holds the operating system.
Extended partition is subdivided into multiple logical partitions. There can be only one extended partition per disk.
From extended partition we can create upto 15 partitions.
Usually it locates at where the OS is installed. It contains two important utilities.
1. IPL (Initial Program Loader)
2. PTI (Partition Table Information).
IPL is responsible for booting the OS. because it contains boot loader.
– RHEL 4 the default boot loader is LILO (Linux Loader).
– RHEL 5 onwards boot loader is Grub (Grand Unified Boot Lodader).
– RHEL 7 onwards boot loader is GRub2.
The PTI (Partition Table Information) is the information about the no. of partitions on the disk, sizes of the partition and types of partitions.
GPT Disk Partitioning
It supports up to 128 partitions per disk.
IDE drives will be shown as – /dev/hd
SCSI/SATA drives shown as – /dev/sd
Virtual drives shown – /dev/vd
Types of File Systems
The supported file systems are ext2, ext3, ext4, vfat and xfs in RHEL 6 and 7.
vfs – The file system is used to maintain a common storage between linux and windows.
ext4/xfs – Widely used file system.
|1||Second Extended FS||Third Extended FS||Fourth Extended FS||Xtents FS|
|3||Does not have journaling Feature||Supports Journaling Feature*||Supports Journaling Feature*||Supports Journaling Feature*|
|4||Max. File size can be 16GB to 2TB||Max. File size can be 16GB to 2TB||Max. File size can be 16GB to 16TB||Max. File size can be 16TB to 8EB|
|5||Max. ext2 FS size can be from 2TB to 32TB.||Max. ext3 FS size can be from 2TB to 32TB.||Max. ext4 FS size can be from 1EB.||Max. xfs file system size is 16EB. 1EB = 1024PB|
|6||Cannot convert ext FS To ext2||Convert from ext2 to ext3||All ext FS can be converted to ext4||NA|
Journaling: It will keep track of changes which are not committed to FS. This can be used to reconstruct if incase of any corruptions which occur due to the system crash or power failures.
How to create a partition?
To see the existing partitions
In linux we have two commands to see the existing partitions.
1. fdisk -l
2. parted -l
fdisk – It will display the cylinders information
Physical disks info in the server:
Physical and Logical disks info in the server:
parted – It will show the disk type information.
To enter into the disk utility, the syntax is fdisk <disk name>
ex: fdisk /dev/sda
|l||List the partitions|
|n||Create a new partition|
|p||Print the partition table|
|d||Delete a partition|
|v||Verify the partition table|
|w||Write table to disk and exit|
|q||Quit without saving changes|
Print partition table
Creating the partition:
Verify the partition:
Check remaining disk space in disk:
Saving the partition table to disk:
Delete a partition in disk:
Updating the partition table
By default, partition table is updated after the restart. We can use partprobe or partx command to update the partition information with out restarting the system.
Even though it is deleted still it is showing in partition table. Now check with partprobe or partx command to update the partition table.
1. partx -a <disk name> # When added the new partition.
2. partx -d <disk name> # When deleted the partition.
3. kpartx <disk name> # It will update automatically irrespective of addition /deletion of partition.
4. partprobe <disk name> # It will update automatically.
Formatting the Partition
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>
ex: mkfs.ext4 /dev/sdd2
It is a method of attaching a directory to the file system for accessing the partitions.
/etc/mtab – It is a file which stores the information of all the currently mounted file systems.
/etc/fstab – It is a file which keeps information about the permanent mount points.
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.
1. Temporary Partition
2. Permanent Partition
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.
mount <partition name> <mount point>
mount /dev/sdd2 /mnt_sdd2
i. First create a directory
ii. Second mount the directory
To unmount a partition
umount <mount point directory>
Permanent mounting procedure is exactly same like temp mounting, but here we will update the /etc/fstab file with mounting details.
i. create a mount directory.
ii. Get the block id of a disk or disk name directory. but the recommended one is blkid.
iii. Add the entry to the /etc/fstab.
|Device name/Device ID||Mount point||Type of File system||Mount Options||Dumping||Check Sequence|
Use mount -a command to check whether it is mounted or not.
Sometimes a directory reflects error while unmounting, the possible causes for it are.
1. Check pwd before going further, you may be in the mount directory and trying to unmount it. It wont happen.
2. Some users are still present on the server and using the contents in it.
3. Check with fuser -cu <mount point> or lsof <mount point>
4. Kill the processes using fuser -ck <mount point>.