- 1. Disk partition
- 1. Tools for partitioning
- 2. Difference between the MBR and GPT
- 3. Checking the partitions’ information
- 2. LVM
1. Disk partition
1. Tools for partitioning
2. Difference between the MBR and GPT
MBR (Master Boot Record) and GPT (GUID Partition Table) are two different ways of storing the partitioning information on a drive. Including the which partitions for starting and beginning. So the operating system knows which sectors is bootable.
1. MBR (Master Boot Record)
MBR is a special boot sector located at the beginning of a drive. The partitioning and boot data is stored in one place. If this data is overwritten or corrupted, you’re in trouble.
- Only works within the 2TB disk.
- Only supports up to 4 primary partitions.
- If you want more that 4 primary partitions, you have to make one of your primary partitions as an “extended partition” and create the logical partitions inside it.
Bootloader(446 bytes) + Partition Table (64 bytes, 16 bytes for each partition, so only supports 4 partitions including primary and logic partitions) + Magic Number(2 bytes)= 512 bytes
2. GPT (GUID Partition Table)
GPT stands for GUID Partition Table. It’s a new standard that’s gradually replacing MBR. It’s associated with UEFI, which replaces the clunky old BIOS with something more modern. It’s called GUID Partition Table because every partition on your drive has a “globally unique identifier,” or GUID—a random string so long that every GPT partition on earth likely has its own unique identifier.
- GPT stores multiple copies of this data across the disk, so it’s much more robust and can recover if the data is corrupted.
GPT also stores cyclic redundancy check (CRC) values to check that its data is intact. If the data is corrupted, GPT can notice the problem and attempt to recover the damaged data from another location on the disk.
1. Protective MBR (LBA 0)
For limited backward compatibility, the space of the legacy MBR is still reserved in the GPT specification, but it is now used in a way that prevents MBR-based disk utilities from misrecognizing and possibly overwriting GPT disks. This is referred to as a protective MBR.
2. Hybrid MBR (LBA 0 + GPT)
In operating systems that support GPT-based boot through BIOS services rather than EFI, the first sector is also still used to store the first stage of the bootloader code, but modified to recognize GPT partitions. The bootloader in the MBR must not assume a sector size of 512 bytes.
3. Partition table header (LBA 1)
The partition table header defines the usable blocks on the disk. It also defines the number and size of the partition entries that make up the partition table.
4. Partition entries (LBA 2-33)
After the header, the Partition Entry Array describes partitions, using a minimum size of 128 bytes for each entry block. The starting location of the array on disk, and the size of each entry, are given in the GPT header. The first 16 bytes of each entry designate the partition type’s globally unique identifier (GUID). For example, the GUID for an EFI system partition is C12A7328-F81F-11D2-BA4B-00A0C93EC93B. The second 16 bytes are a GUID unique to the partition. Then follow the starting and ending 64 bit LBAs, partition attributes, and the 36 character (max). Unicode partition name. As is the nature and purpose of GUIDs, no central registry is needed to ensure the uniqueness of the GUID partition type designators.
3. Checking the partitions’ information
‘# sudo su’
‘# gdisk’ //starting the gdisk
- The physical media – assume it to be a simple hard disk, or a partition
PV: Physical Volume – assume it to be a simple hard disk, or a partition
PE: Physical Extents – like really big blocks, often with a size of megabytes
VG: Volume Group – A Logical Volume is the end result of our work, and it’s there that we store our information. This is equivalent to the historic idea of partitions.
LV: Logical Volume – A Logical Volume is the end result of our work, and it’s there that we store our information. This is equivalent to the historic idea of partitions.
1. Enlarge the /root
In the disk, in the LVM partition we have /root, /home and /swap in the logical volume. Due to ifs file system, it can not be shrink. If we want to change the size between /root and /home. We must destory the /home and enlarge the size of /root and rebuild the /home systems.
‘# df -h’ // show the detail of the partitions
‘# vgdisplay’ // show the detail of the Volume group
‘# lvdisplay’ // show the detail of the Logical volume
‘# tar -czvf /root/home.tgz -C /home .’ //Backup the contents of /home
‘# tar -tvf /root/home.tgz’ //Test the backup
‘# umount -fl /dev/mapper/rhel-home’ //forcing unmount the /rhel-home
‘# lsof | grep rhel-home’ // check is there open files
‘fuser -kuc /dev/mapper/rhel-home’ // And after that identify processes using files on this volume
‘# lvremove /dev/mapper/rhel-home’ //Remove home logical volume
‘# lvcreate -L 100GB -n home rhel’ //Now need to recreate new /home LV (lets say of 100GB), format and mount it
‘# mkfs.xfs /dev/rhel/home’
‘# mount /dev/mapper/rhel-home’
‘# lvextend -r -l +100%FREE /dev/mapper/home-root’ //Now extend your /root volume with all the remaining space
‘# tar -xzvf /root/home.tgz -C /home’ //Restore your backup
‘# blkid /dev/mapper/rhel-home’ //Check /etc/fstab entry of /home. Update the UUID of /home directory
‘# vim /etc/fstab’ (and update UUID of /home)