Drive Management

Utilities

  • lsblk: List information about block devices

  • df: Report file system disk space usage

  • sgdisk: Command-line GUID partition table (GPT) manipulator for Linux and Unix

  • fdisk: Manipulate disk partition table

  • parted: GNU Parted - a partition manipulation program

Print Drive Information

  • Using sgdisk --print <device>

    [root@mawenzi-06 ~]# sgdisk --print /dev/nvme0n1
    Disk /dev/nvme0n1: 3125627568 sectors, 1.5 TiB
    Model: MZXL51T6HBJR-000H3
    Sector size (logical/physical): 512/512 bytes
    Disk identifier (GUID): EF3781EC-7B13-453B-9651-FE12C5375137
    Partition table holds up to 128 entries
    Main partition table begins at sector 2 and ends at sector 33
    First usable sector is 34, last usable sector is 3125627534
    Partitions will be aligned on 2048-sector boundaries
    Total free space is 2967095917 sectors (1.4 TiB)
    
    Number  Start (sector)    End (sector)  Size       Code  Name
       1            2048         1230847   600.0 MiB   EF00  EFI System Partition
       2         1230848         3327999   1024.0 MiB  8300
       3         3328000       158533631   74.0 GiB    8E00
  • Using fdisk --list <device>

    [root@mawenzi-06 ~]# fdisk --list /dev/nvme0n1
    Disk /dev/nvme0n1: 1.5 TiB, 1600321314816 bytes, 3125627568 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: gpt
    Disk identifier: EF3781EC-7B13-453B-9651-FE12C5375137
    
    Device           Start       End   Sectors  Size Type
    /dev/nvme0n1p1    2048   1230847   1228800  600M EFI System
    /dev/nvme0n1p2 1230848   3327999   2097152    1G Linux filesystem
    /dev/nvme0n1p3 3328000 158533631 155205632   74G Linux LVM
  • Using lsblk

    [root@mawenzi-06 ~]# lsblk
    NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sr0          11:0    1  2.1G  0 rom
    nvme2n1     259:0    0  1.5T  0 disk
    nvme0n1     259:1    0  1.5T  0 disk
    ├─nvme0n1p1 259:5    0  600M  0 part /boot/efi
    ├─nvme0n1p2 259:6    0    1G  0 part /boot
    └─nvme0n1p3 259:7    0   74G  0 part
      ├─rl-root 253:0    0   70G  0 lvm  /
      └─rl-swap 253:1    0    4G  0 lvm  [SWAP]
    nvme4n1     259:2    0  1.5T  0 disk
    └─nvme4n1p1 259:8    0  100G  0 part
    nvme3n1     259:3    0  1.5T  0 disk
    nvme1n1     259:4    0  1.5T  0 disk

Clear/Delete Partitions

Whenever deleting partitions make sure to either reboot or run partprobe to inform the kernel of the partition changes.
  • Using sgdisk --zap-all <device>: zap (destroy) all GPT and MBR data structures

    [root@mawenzi-06 ~]# sgdisk --zap-all /dev/nvme4n1
    GPT data structures destroyed! You may now partition the disk using fdisk or
    other utilities.
  • Using sgdisk --delete <partnum> <device>, delete the second partition on the /dev/nvme4n1 drive

    [root@mawenzi-06 ~]# sgdisk --delete 2 /dev/nvme4n1
    The operation has completed successfully.

Create Partitions

Whenever creating partitions make sure to either reboot or run partprobe to inform the kernel of the partition changes.
  • Using sgdisk, create a new partition on the /dev/nvme0n1 drive, converting MBR partitions to GPT, 0 MiB from the last partition’s end, 100 GiB in size, change the partition label from 2 to dpapi

    [root@mawenzi-06 ~]# sgdisk --mbrtogpt --randomize-guids --new 2:+0M:+100G --change-name 2:dpapi /dev/nvme4n1
    Setting name!
    partNum is 1
    The operation has completed successfully.

This creates an entry /dev/disk/by-partlabel/dpapi → /dev/nvme0n1p2.

  • Using fdisk /dev/nvme0n4, an interactive CLI, create a new GPT partition table, and a single partition of size 100 GiB

    [root@mawenzi-06 ~]# fdisk /dev/nvme4n1
    
    Welcome to fdisk (util-linux 2.32.1).
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
    
    Device does not contain a recognized partition table.
    Created a new DOS disklabel with disk identifier 0xcfa29f92.
    
    Command (m for help): g
    Created a new GPT disklabel (GUID: EAA1BB8B-AF62-C948-9332-376F905FE637).
    
    Command (m for help): n
    Partition number (1-128, default 1): 1
    First sector (2048-3125627534, default 2048): 2048
    Last sector, +sectors or +size{K,M,G,T,P} (2048-3125627534, default 3125627534): +100G
    
    Created a new partition 1 of type 'Linux filesystem' and of size 100 GiB.
    
    Command (m for help): p
    Disk /dev/nvme4n1: 1.5 TiB, 1600321314816 bytes, 3125627568 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: gpt
    Disk identifier: EAA1BB8B-AF62-C948-9332-376F905FE637
    
    Device         Start       End   Sectors  Size Type
    /dev/nvme4n1p1  2048 209717247 209715200  100G Linux filesystem
    
    Command (m for help): w
    The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Syncing disks.