Disk partitioning allows a hard-drive to be divided in to multiple logical partitions on Redhat Enterprise Linux. The multiple partitions can be used to create filesystems and it can be mounted in different mount points. Most of the operating systems are still using the MBR partitioning scheme and it has dictated how disks should be partitioned on systems running BIOS firmware. But it has lot of limitations since it stores the partition data in 32-bit values.
MBR Partitioning Limitations:
- Can’t create more than 4 primary partitions from one disk.
- With the help of extended partition, you can create up to 15 partitions.
- Can’t partition the disk which more than 2TB
To overcome this limitations , We need to use GPT (GUID partitioning table) partitioning scheme. The systems which are using UEFI(Unified Extensible Firmware Interface) firmware, GPT is the standard for laying out partition tables on hard disks.
Here is the advantage of GPT table over MBR.
- GPT supports up to 128 partitions
- GPT allocates 64bits for logical block address
- GPT supports disks up to 8 Zebibyte.
By default , MBR partitions must be managed by fdisk command. To manage the GPT disk , you need to use gdisk command.
If you would like to know that how to use the fdisk command, please go through this article.
In this article ,we will be experimenting with gdisk command.
1. Execute gdisk command for /dev/vda disk to list the existing partitions.
[root@server1-UA ~]#gdisk -l /dev/vda GPT fdisk (gdisk) version 0.8.6 Partition table scan: MBR: MBR only BSD: not present APM: not present GPT: not present *************************************************************** Found invalid GPT and valid MBR; converting MBR to GPT format. *************************************************************** Disk /dev/vda: 20971520 sectors, 10.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): 2525D738-DCC5-4E3E-BC30-677E43607CD4 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 20971486 Partitions will be aligned on 2048-sector boundaries Total free space is 3168 sectors (1.5 MiB) Number Start (sector) End (sector) Size Code Name 1 2048 20970332 10.0 GiB 8300 Linux filesystem [root@server1-UA ~]#
In the above command output , you can see the warning message like “Found invalid GPT and valid MBR; converting MBR to GPT format” . It says that , if you modify the partition using gdisk , it will convert the MBR partition to GPT partition. This conversion will corrupt the existing filesystems on the disk. Also , you should not use the gdisk command if the disk has MBR partition tables on it.
2. Execute gdisk command for /dev/vdb disk to list the existing partitions.
[root@server1-UA ~]#gdisk -l /dev/vdb GPT fdisk (gdisk) version 0.8.6 Partition table scan: MBR: not present BSD: not present APM: not present GPT: not present Creating new GPT entries. Disk /dev/vdb: 20971520 sectors, 10.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): 51A0F8D7-09BF-47D6-B84F-5BAE888EB534 Partition table holds up to 128 entries First usable sector is 34, last usable sector is 20971486 Partitions will be aligned on 2048-sector boundaries Total free space is 20971453 sectors (10.0 GiB) Number Start (sector) End (sector) Size Code Name [root@server1-UA ~]#
In the above output , we can see that there is no MBR partition exists on that and also there is no warning about it.
3. Create a new partition with the size of 1GB on /dev/vdb.
[root@server1-UA ~]#gdisk /dev/vdb GPT fdisk (gdisk) version 0.8.6 Partition table scan: MBR: not present BSD: not present APM: not present GPT: not present Creating new GPT entries. Command (? for help): m b back up GPT data to a file c change a partition's name d delete a partition i show detailed information on a partition l list known partition types n add a new partition o create a new empty GUID partition table (GPT) p print the partition table q quit without saving changes r recovery and transformation options (experts only) s sort partitions t change a partition's type code v verify disk w write table to disk and exit x extra functionality (experts only) ? print this menu Command (? for help): n Partition number (1-128, default 1): First sector (34-20971486, default = 2048) or {+-}size{KMGTP}: Last sector (2048-20971486, default = 20971486) or {+-}size{KMGTP}: +1G Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): Changed type of partition to 'Linux filesystem' Command (? for help): p Disk /dev/vdb: 20971520 sectors, 10.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): 6BE88D5A-0E83-44A6-B1BD-5A2C064E24EC Partition table holds up to 128 entries First usable sector is 34, last usable sector is 20971486 Partitions will be aligned on 2048-sector boundaries Total free space is 18874301 sectors (9.0 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 2099199 1024.0 MiB 8300 Linux filesystem Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): y OK; writing new GUID partition table (GPT) to /dev/vdb. The operation has completed successfully. [root@server1-UA ~]#
Let me verify the newly created partition table.
[root@server1-UA ~]#gdisk -l /dev/vdb GPT fdisk (gdisk) version 0.8.6 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. Disk /dev/vdb: 20971520 sectors, 10.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): 6BE88D5A-0E83-44A6-B1BD-5A2C064E24EC Partition table holds up to 128 entries First usable sector is 34, last usable sector is 20971486 Partitions will be aligned on 2048-sector boundaries Total free space is 18874301 sectors (9.0 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 2099199 1024.0 MiB 8300 Linux filesystem [root@server1-UA ~]#
4.Inform to the kernel to re-read the partition table of /dev/vdb.
[root@server1-UA ~]#partprobe /dev/vdb [root@server1-UA ~]#
5.Create a new filesystem on top /dev/vdb1 partition which we have created now.
[root@server1-UA ~]#mkfs.ext4 /dev/vdb1 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 65536 inodes, 262144 blocks 13107 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=268435456 8 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376 Allocating group tables: done Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done [root@server1-UA ~]#
5.Mount the partition .
[root@server1-UA ~]#mkdir /gdisk_exp [root@server1-UA ~]#mount -t ext4 /dev/vdb1 /gdisk_exp [root@server1-UA ~]#df -h /gdisk_exp Filesystem Size Used Avail Use% Mounted on /dev/vdb1 976M 2.6M 907M 1% /gdisk_exp [root@server1-UA ~]#
6.Let me add new partition on the same disk.
[root@server1-UA ~]#gdisk /dev/vdb GPT fdisk (gdisk) version 0.8.6 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. Command (? for help): p Disk /dev/vdb: 20971520 sectors, 10.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): 6BE88D5A-0E83-44A6-B1BD-5A2C064E24EC Partition table holds up to 164 entries First usable sector is 43, last usable sector is 20971477 Partitions will be aligned on 2048-sector boundaries Total free space is 18874283 sectors (9.0 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 2099199 1024.0 MiB 8300 Linux filesystem Command (? for help): n Partition number (2-164, default 2): First sector (43-20971477, default = 2099200) or {+-}size{KMGTP}: Last sector (2099200-20971477, default = 20971477) or {+-}size{KMGTP}: +1G Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): Changed type of partition to 'Linux filesystem' Command (? for help): p Disk /dev/vdb: 20971520 sectors, 10.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): 6BE88D5A-0E83-44A6-B1BD-5A2C064E24EC Partition table holds up to 164 entries First usable sector is 43, last usable sector is 20971477 Partitions will be aligned on 2048-sector boundaries Total free space is 16777131 sectors (8.0 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 2099199 1024.0 MiB 8300 Linux filesystem 2 2099200 4196351 1024.0 MiB 8300 Linux filesystem Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): y OK; writing new GUID partition table (GPT) to /dev/vdb. The operation has completed successfully. [root@server1-UA ~]#
Re-read the partition and create the new filesystem .
[root@server1-UA ~]#partprobe /dev/vdb [root@server1-UA ~]#[root@server1-UA ~]#mkfs.ext4 /dev/vdb2 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 65536 inodes, 262144 blocks 13107 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=268435456 8 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376 Allocating group tables: done Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done [root@server1-UA ~]#mount -t ext4 /dev/vdb2 /gdisk_exp2 [root@server1-UA ~]#df -h -F ext4 Filesystem Size Used Avail Use% Mounted on /dev/vdb1 976M 2.6M 907M 1% /gdisk_exp /dev/vdb2 976M 2.6M 907M 1% /gdisk_exp2 [root@server1-UA ~]#
6. Update the /etc/fstab file to mount the filesystems across the system reboot.
In RHEl 7 , fstab will be looking like below.
[root@server1-UA ~]#cat /etc/fstab # # /etc/fstab # Created by anaconda on Wed May 7 01:22:57 2014 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=9bf6b9f7-92ad-441b-848e-0257cbb883d1 / xfs defaults 1 1 [root@server1-UA ~]#
Note: It is recommend to use “UUID” instead of directly specifying the device name in the fstab. The device name might get change when you do SAN migration or modifying the underlying physical machine. Normally UUID stores in the super-block and it remain intact in the superblock of the device irrespective of those changes.
Let’s see that how we can find the UUID for the newly created filesystem.
Use blkid command to find the UUID for all the filesystems .
[root@server1-UA ~]#blkid /dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs" /dev/vdb1: UUID="fee52e0a-25b5-470e-a946-ecb385a493fd" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="199829ed-108e-4ce3-a9c1-080a10c6296b" /dev/vdb2: UUID="0f52dc0c-21c8-471e-a63a-fbca9ebbb66c" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="adf6934c-a6c3-4e26-9247-22401fc9b462" [root@server1-UA ~]#
Let me update the /etc/fstab using the UUID information for /dev/vdb1 and /dev/vdb2 .
[root@server1-UA ~]#cat /etc/fstab # # /etc/fstab # Created by anaconda on Wed May 7 01:22:57 2014 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=9bf6b9f7-92ad-441b-848e-0257cbb883d1 / xfs defaults 1 1 UUID=fee52e0a-25b5-470e-a946-ecb385a493fd /gdisk_exp ext4 defaults 1 1 UUID=0f52dc0c-21c8-471e-a63a-fbca9ebbb66c /gdisk_exp2 ext4 defaults 1 1 [root@server1-UA ~]#
Let me re-mount the filesystem using mountpoint.
[root@server1-UA ~]#umount /gdisk_exp [root@server1-UA ~]#umount /gdisk_exp2 [root@server1-UA ~]#mount /gdisk_exp [root@server1-UA ~]#mount /gdisk_exp2 [root@server1-UA ~]#df -h -F ext4 Filesystem Size Used Avail Use% Mounted on /dev/vdb1 976M 2.6M 907M 1% /gdisk_exp /dev/vdb2 976M 2.6M 907M 1% /gdisk_exp2 [root@server1-UA ~]#
The above output confirms that /etc/fstab entries are correct .
Hope this article is informative to you.
Share ! Comment it !! Be Sociable !!!
Leave a Reply