Partitioning Tools

fdisk

Program used to create, view, delete, modify partitions a a drive that uses MBR method of indexing partitions. However, fdisk does not allow resizing a partition. What you can do instead, is to delete existing partition and rebuild it from scratch. To boot system from a partition, set the boot flag with “a”. Use command fdisk -l to list all partitions on the system:

[root@arch ~]# fdisk -l
Disk /dev/sda: 223.57 GiB, 240057409536 bytes, 468862128 sectors
Disk model: KINGSTON SUV5002
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: F64AEA71-E097-634D-A060-F6AD601357E4

Device         Start       End   Sectors   Size Type
/dev/sda1       2048    206847    204800   100M EFI System
/dev/sda2     206848 209922047 209715200   100G Linux filesystem
/dev/sda3  209922048 468862094 258940047 123.5G Linux filesystem

As you can see, I have only one solid-state drive /dev/sda on my system. It has around 220GB, disk label is GPT since I am running UEFI system. There are three partitions on this SSD:

  1. /dev/sda1 – First partition, type EFI meaning it has GPT partition table, size 100MB, this is where GRUB2 bootloader lives.
  2. /dev/sda2 – Second partition, type Linux filesystem, size 100GB, this is / of the system
  3. /dev/sda3 – Third partition, type Linux filesystem, size 123GB, this partition contains /home/ and other subdirectories.

To actually create partitions, delete them, or modify, type fdisk followed by disk path:

# fdisk /dev/sda

Here are the most popular commands you will need when inside fdisk utility:

aSet partition as bootable
dDelete a partition
gCreate empty GPT partition
lList known partition types
mPrint help menu
nAdd new partition
pPrint partition table
qQuit without saving
tChange partition’s system ID
uChange display units
vVerify partition table
wWrite table to disk and exit

gdisk

If you are running system that uses GPT, you will need gdisk utility. It is quite similar to fdisk. If the drive does not use GPT method, gdisk will ofer the option to convert it to a GPT drive. However, method we select there must be compatible with system’s firmware (BIOS or UEFI). Here are common gdisk commands:

bBackup GPT data to a file
cChange partition’s name
dDelete partition
iShow partition detailed information
lList known partition types
nAdd new partition
oCreate new GUID Partition Table (GPT)
pPrint the partition table
qQuit without saving
sSort partitions
tChange partition’s type code
vVerify disk
wWrite table to disk and exit

To read more about gdisk, click here.

parted

GNU parted utility provides command-line interface for working with drive partitions. One of best features of parted utility is to resize existing partitions.

[root@arch ~]# parted
GNU Parted 3.3
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print                                                            
Model: ATA KINGSTON SUV5002 (scsi)
Disk /dev/sda: 240GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags: 

Number  Start   End    Size   File system  Name  Flags
 1      1049kB  106MB  105MB  fat32              boot, esp
 2      106MB   107GB  107GB  ext4
 3      107GB   240GB  133GB  ext4

(parted)                                                                  

That is it for now, I will come back as I finish other blog posts. Thank you for reading, I really hope you learned something. To read more from me, click here

Leave a Reply