Managing Partitions and File Systems Using gdisk

Managing GPT Partitions with gdisk.

In this post, I am going to explaining how to create and remove partitions on disks with a GPT partition scheme using gdisk.

I already covered that the how to create disk MBR partitions, making the file systems, deleting a partition, Mounting the Filesystems and some troublestooting steps while unmount the file systems, refer the following link.

Managing MBR Partitions and File Systems Using fdisk

For those systems that are running Unified Extensible Firmware Interface (UEFI) firmware, GPT is the standard for laying out partition tables on physical hard disks. GPT is part of the UEFI standard and addresses many of the limitations imposed by the old MBR-Based Scheme.

Advantages to GPT:

  • GPT defaults to supporting up to 128 partitions.
  • GPT uses 128-bit GUIDs to uniquely identify each disk and partition.
  • Provides duplicate partition table structures at the start and end of the disk, which makes recovery from some types of user errors, bugs, and disk damage possible.
  • Supports partitions larger than 2TiB.
  • Provides checksums of important data structures, which enables detection of some types of partition table damage.
  • Used natively by EFI/UEFI firmware.

Creating GPT Disk Partitions

1.) Specify the Disk name.

#gdisk <disk name>

[root@server1 ~]# gdisk /dev/sdb
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):?
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): 

Note: Use “?” to list various options that can be used in gdisk.

2.) Creating the new partition.

Enter “n” to create the new partition.Then specify the partition number (by default is 1),then specify the disk location that new partition will start from, and then also specify the last sector on the disk that new partition will end on, at last define partition type.

Command (? for help): n
Partition number (1-128, default 1): 1

First sector (34-20971486, default = 2048) or {+-}size{KMGTP}: 2048
Last sector (2048-20971486, default = 20971486) or {+-}size{KMGTP}: +8G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): L   
0700 Microsoft basic data  0c01 Microsoft reserved    2700 Windows RE          
4200 Windows LDM data      4201 Windows LDM metadata  7501 IBM GPFS            
7f00 ChromeOS kernel       7f01 ChromeOS root         7f02 ChromeOS reserved   
8200 Linux swap            8300 Linux filesystem      8301 Linux reserved      
8e00 Linux LVM             a500 FreeBSD disklabel     a501 FreeBSD boot        
a502 FreeBSD swap          a503 FreeBSD UFS           a504 FreeBSD ZFS         
a505 FreeBSD Vinum/RAID    a580 Midnight BSD data     a581 Midnight BSD boot   
a582 Midnight BSD swap     a583 Midnight BSD UFS      a584 Midnight BSD ZFS    
a585 Midnight BSD Vinum    a800 Apple UFS             a901 NetBSD swap         
a902 NetBSD FFS            a903 NetBSD LFS            a904 NetBSD concatenated 
a905 NetBSD encrypted      a906 NetBSD RAID           ab00 Apple boot          
af00 Apple HFS/HFS+        af01 Apple RAID            af02 Apple RAID offline  
af03 Apple label           af04 AppleTV recovery      af05 Apple Core Storage  
be00 Solaris boot          bf00 Solaris root          bf01 Solaris /usr & Mac Z
bf02 Solaris swap          bf03 Solaris backup        bf04 Solaris /var        
bf05 Solaris /home         bf06 Solaris alternate se  bf07 Solaris Reserved 1  
bf08 Solaris Reserved 2    bf09 Solaris Reserved 3    bf0a Solaris Reserved 4  
bf0b Solaris Reserved 5    c001 HP-UX data            c002 HP-UX service       
ed00 Sony system partitio  ef00 EFI System            ef01 MBR partition scheme
ef02 BIOS boot partition   fb00 VMWare VMFS           fb01 VMWare reserved     
fc00 VMWare kcore crash p  fd00 Linux RAID            
Hex code or GUID (L to show codes, Enter = 8300): 8e00
Changed type of partition to 'Linux LVM'

Command (? for help):

 Note: “L” is used to list all codes.

3.) Save partition tables changes.

“w” command is used to finalize creation request.

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/sdb.
The operation has completed successfully.
[root@server1 ~]#

4.) Updating the new partition table without reboot.

Run the “partprobe” command with the disk device name as an argument to force a re-read of its partition table.

# partprobe <device name>

[root@server1 ~]# partprobe /dev/sdb
[root@server1 ~]#

Making the File system

5.) Creating the file systems with xfs.

After creating the block device, we need to assign some file system to it so we can start storing the data into it.

# mkfs.xfs /dev/sdb1

[root@server1 ~]# mkfs.xfs  /dev/sdb1
meta-data=/dev/sdb1              isize=256    agcount=4, agsize=524288 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=2097152, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@server1 ~]#

 Deleting a Partitions

7.) Delete Disk Partitions.

Now we have learnt how to create and format the partition with particular file system. Let’s see how delete a partition.The steps for removing a partition is shown below.

[root@server1 ~]# gdisk /dev/sdb
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/sdb: 20971520 sectors, 10.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 31D87D49-0538-4CC9-8423-BCE74D653751
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 4194237 sectors (2.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048        16779263   8.0 GiB     8E00  Linux LVM

Command (? for help): d
Using 1

Command (? for help): p
Disk /dev/sdb: 20971520 sectors, 10.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 31D87D49-0538-4CC9-8423-BCE74D653751
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

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/sdb.
The operation has completed successfully.
[root@server1 ~]#

8.) Mounting a Partition.

To make a permanent mount point the steps are:

  • Make a directory or use existing directory(/Softwarebackup).
  • Find out the UUID using “blkid” command.
  • Add entry on fstab file(/etc/fstab).
  • Use mount -a command to check it is mounting.

Find out the UUID number of device using,

# blkid <Device Name>

[root@server1 ~]# blkid /dev/sdb1
 /dev/sdb1: UUID="a6dc4f16-35fc-42a6-8d03-7ccb73df203f" TYPE="xfs" 
 [root@server1 ~]#

# vim /etc/fstab

#
 # /etc/fstab
 # Created by anaconda on Sat Sep 17 02:26:32 2016
 #
 # 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
 #
 /dev/mapper/centos-root                         /                       xfs     defaults        0 0
 UUID=107451a1-3675-46bf-9074-dd9fd19ca2f9       /boot                   xfs     defaults        0 0
 /dev/mapper/centos-home                         /home                   xfs     defaults        0 0
 /dev/mapper/centos-var                          /var                    xfs     defaults        0 0
 UUID=0fc8a8f0-641c-42fd-8f06-34e40adb15ea       swap                    swap    defaults        0 0
 UUID="a6dc4f16-35fc-42a6-8d03-7ccb73df203f"     /Softwarebackup         xfs     defaults        0 0
~
~
!wq

Note: Here we will be using existing /Softwarebackup directory as mount point earlier.

Now mount the file system using “mount -a” command.

#mount -a

[root@server1 /]# df -h
 Filesystem               Size  Used Avail Use% Mounted on
 /dev/mapper/centos-root  7.0G  824M  6.2G  12% /
 devtmpfs                 487M     0  487M   0% /dev
 tmpfs                    497M     0  497M   0% /dev/shm
 tmpfs                    497M  6.6M  490M   2% /run
 tmpfs                    497M     0  497M   0% /sys/fs/cgroup
 /dev/mapper/centos-home  2.0G   33M  2.0G   2% /home
 /dev/mapper/centos-var   1.9G  184M  1.7G  10% /var
 /dev/sda1                297M  114M  184M  39% /boot
 tmpfs                    100M     0  100M   0% /run/user/0
 [root@server1 /]# mount -a
 [root@server1 /]# df -h
 Filesystem               Size  Used Avail Use% Mounted on
 /dev/mapper/centos-root  7.0G  824M  6.2G  12% /
 devtmpfs                 487M     0  487M   0% /dev
 tmpfs                    497M     0  497M   0% /dev/shm
 tmpfs                    497M  6.6M  490M   2% /run
 tmpfs                    497M     0  497M   0% /sys/fs/cgroup
 /dev/mapper/centos-home  2.0G   33M  2.0G   2% /home
 /dev/mapper/centos-var   1.9G  184M  1.7G  10% /var
 /dev/sda1                297M  114M  184M  39% /boot
 tmpfs                    100M     0  100M   0% /run/user/0
 /dev/sdb1                5.0G   33M  5.0G   1% /Softwarebackup
 [root@server1 /]#

As shown above “/Softwarebackup” directory has been mounted.!!!!

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz