Lesson 4.1: List, create, delete partitions on MBR and GPT disks
Partitions on a Disk
On a device, the type of the partition table determines the maximum number and size of individual partitions.
Maximum number of partitions:
On a device formatted with the Master Boot Record (MBR)
partition table, you can have:
- Up to four primary partitions.
- Up to three primary partitions, one extended partition
- Multiple logical partitions within the extended partition
On a device formatted with the GUID Partition Table (GPT)
, you can have:
- Up to 128 partitions, if using the parted utility.
- Though the GPT specification allows more partitions by increasing the reserved size of the partition table, the parted utility limits the area required for 128 partitions.
Partition Type | Maximum number of partitions | Maximum partition si |
---|---|---|
Master Boot Record (MBR) | 4 primary, or 3 primary and 1 extended partition with 12 logical partitions | 2TiB |
GUID Partition Table (GPT) | 128 | 8ZiB |
FDISK
Creating a MBR-Based Disk Partitioning Structure using fdisk
[root@sanjeeb ~]# fdisk /dev/nvme0n2 # Command to Print the drives Command (m for help): p Disk /dev/nvme0n2: 5 GiB, 5368709120 bytes, 10485760 sectors Disk model: VMware Virtual NVMe Disk 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: dos Disk identifier: 0x2797ea38 # Command to create partiton (Partition 1) Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): Using default response p. Partition number (1-4, default 1): First sector (2048-10485759, default 2048): +1G Value out of range. First sector (2048-10485759, default 2048): Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-10485759, default 10485759): +1G Created a new partition 1 of type 'Linux' and of size 1 GiB. # Command to create partiton (Partition 1) Command (m for help): n Partition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions) Select (default p): Using default response p. Partition number (2-4, default 2): First sector (2099200-10485759, default 2099200): Last sector, +/-sectors or +/-size{K,M,G,T,P} (2099200-10485759, default 10485759): +512M Created a new partition 2 of type 'Linux' and of size 512 MiB. # Command to create partiton (Partition 1) Command (m for help): n Partition type p primary (2 primary, 0 extended, 2 free) e extended (container for logical partitions) Select (default p): Using default response p. Partition number (3,4, default 3): First sector (3147776-10485759, default 3147776): Last sector, +/-sectors or +/-size{K,M,G,T,P} (3147776-10485759, default 10485759): +200M Created a new partition 3 of type 'Linux' and of size 200 MiB. # Command to create partiton (Partition 1) Command (m for help): n Partition type p primary (3 primary, 0 extended, 1 free) e extended (container for logical partitions) Select (default e): e Selected partition 4 First sector (3557376-10485759, default 3557376): Last sector, +/-sectors or +/-size{K,M,G,T,P} (3557376-10485759, default 10485759): Created a new partition 4 of type 'Extended' and of size 3.3 GiB. Command (m for help): p Disk /dev/nvme0n2: 5 GiB, 5368709120 bytes, 10485760 sectors Disk model: VMware Virtual NVMe Disk 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: dos Disk identifier: 0x2797ea38 Device Boot Start End Sectors Size Id Type /dev/nvme0n2p1 2048 2099199 2097152 1G 83 Linux #(Partition 1) /dev/nvme0n2p2 2099200 3147775 1048576 512M 83 Linux #(Partition 2) /dev/nvme0n2p3 3147776 3557375 409600 200M 83 Linux #(Partition 3) /dev/nvme0n2p4 3557376 10485759 6928384 3.3G 5 Extended #(Partition 4)
Changing the partition type of Partition Number 2
Command (m for help): t Partition number (1-4, default 4): 2 Hex code or alias (type L to list all): 82 Changed type of partition 'Linux' to 'Linux swap / Solaris'. # Print the partitions Command (m for help): p Disk /dev/nvme0n2: 5 GiB, 5368709120 bytes, 10485760 sectors Disk model: VMware Virtual NVMe Disk 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: dos Disk identifier: 0x2797ea38 Device Boot Start End Sectors Size Id Type /dev/nvme0n2p1 2048 2099199 2097152 1G 83 Linux /dev/nvme0n2p2 2099200 3147775 1048576 512M 82 Linux swap / Solaris # Changed to 82 (SWAP) /dev/nvme0n2p3 3147776 3557375 409600 200M 83 Linux /dev/nvme0n2p4 3557376 10485759 6928384 3.3G 5 Extended
In the partitions printed below , nvme0n2p5 is the container for (nvme0n2p6, nvme0n2p7)
Device Boot Start End Sectors Size Id Type /dev/nvme0n2p1 2048 4196351 4194304 2G 83 Linux # Partition 1 (Primary) /dev/nvme0n2p2 4196352 5220351 1024000 500M 83 Linux # Partition 2 (Primary) /dev/nvme0n2p3 5220352 6244351 1024000 500M 83 Linux # Partition 3 (Primary) /dev/nvme0n2p4 6244352 10485759 4241408 2G 5 Extended # Partition 4 (Extended) /dev/nvme0n2p5 6246400 6451199 204800 100M 83 Linux # Partition 4-1 (Extended / Container) /dev/nvme0n2p6 6453248 8296447 1843200 900M 83 Linux # Partition 4-2 (Extended) /dev/nvme0n2p7 8298496 10485759 2187264 1G 83 Linux # Partition 4-3 (Extended)
- Use the command
w
to save and exit. - Use the command
q
to unsave and quit.
To refresh partprobe
[root@sanjeeb ~]# partprobe /dev/nvme0n2
To delete all the partitions in a disk
[root@sanjeeb ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sr0 11:0 1 8G 0 rom /run/media/root/CentOS-Stream-9-BaseOS-aarch64 nvme0n1 259:0 0 20G 0 disk ├─nvme0n1p1 259:1 0 600M 0 part /boot/efi ├─nvme0n1p2 259:2 0 1G 0 part /boot └─nvme0n1p3 259:3 0 18.4G 0 part ├─cs-root 253:0 0 16.4G 0 lvm / └─cs-swap 253:1 0 2G 0 lvm [SWAP] nvme0n2 259:4 0 5G 0 disk ├─nvme0n2p1 259:12 0 2G 0 part ├─nvme0n2p2 259:13 0 500M 0 part ├─nvme0n2p3 259:14 0 500M 0 part ├─nvme0n2p4 259:15 0 1K 0 part ├─nvme0n2p5 259:16 0 100M 0 part ├─nvme0n2p6 259:17 0 900M 0 part └─nvme0n2p7 259:18 0 1G 0 part # Wiping off all the partitions of disk /dev/nvme0n2 [root@sanjeeb ~]# wipefs --all /dev/nvme0n2 /dev/nvme0n2: 2 bytes were erased at offset 0x000001fe (dos): 55 aa /dev/nvme0n2: calling ioctl to re-read partition table: Success [root@sanjeeb ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sr0 11:0 1 8G 0 rom /run/media/root/CentOS-Stream-9-BaseOS-aarch64 nvme0n1 259:0 0 20G 0 disk ├─nvme0n1p1 259:1 0 600M 0 part /boot/efi ├─nvme0n1p2 259:2 0 1G 0 part /boot └─nvme0n1p3 259:3 0 18.4G 0 part ├─cs-root 253:0 0 16.4G 0 lvm / └─cs-swap 253:1 0 2G 0 lvm [SWAP] nvme0n2 259:4 0 5G 0 disk
GDISK
Creating an GPT-Based Disk Partitioning Structure with gdisk
[root@server ~]# fdisk /dev/nvme0n2 #Creating a new partition Command (m for help): n Partition number (5-128, default 5): First sector (5425152-10485726, default 5425152): Last sector, +/-sectors or +/-size{K,M,G,T,P} (5425152-10485726, default 10485726): +50M Created a new partition 5 of type Linux filesystem and of size 50 MiB. # Viewing the partitions Command (m for help): p Disk /dev/nvme0n2: 5 GiB, 5368709120 bytes, 10485760 sectors Disk model: VMware Virtual NVMe Disk 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: E0095413-4144-47C5-86A9-E1553AFD5F65 Device Start End Sectors Size Type /dev/nvme0n2p1 2048 2099199 2097152 1G Linux filesystem /dev/nvme0n2p2 2099200 3123199 1024000 500M Linux filesystem /dev/nvme0n2p3 3123200 5220351 2097152 1G Linux swap /dev/nvme0n2p4 5220352 5425151 204800 100M Linux filesystem /dev/nvme0n2p5 5425152 5527551 102400 50M Linux filesystem # Save and Exit Command (m for help): w The partition table has been altered. Syncing disks. # Refreshing [root@server ~]# partprobe /dev/nvme0n2 #Viewing the partitions [root@server ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sr0 11:0 1 1024M 0 rom nvme0n1 259:0 0 20G 0 disk ├─nvme0n1p1 259:1 0 600M 0 part /boot/efi ├─nvme0n1p2 259:2 0 1G 0 part /boot └─nvme0n1p3 259:3 0 18.4G 0 part ├─cs-root 253:0 0 16.4G 0 lvm / └─cs-swap 253:1 0 2G 0 lvm [SWAP] nvme0n2 259:4 0 5G 0 disk ├─nvme0n2p1 259:5 0 1G 0 part /data1 ├─nvme0n2p2 259:6 0 500M 0 part /data2 ├─nvme0n2p3 259:7 0 1G 0 part [SWAP] ├─nvme0n2p4 259:8 0 100M 0 part └─nvme0n2p5 259:9 0 50M 0 part
Formatting (Creating Filesystems)
mkfs -t <filesystem type> <partition name>
# To create a filesystem [root@sanjeeb ~]# mkfs -t ext4 /dev/nvme0n2p2 mke2fs 1.46.5 (30-Dec-2021) Creating filesystem with 307200 1k blocks and 76912 inodes Filesystem UUID: f04e6fa2-ee3b-4d8c-922d-2accbb93892f Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729, 204801, 221185 Allocating group tables: done Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done # To check filesystem [root@sanjeeb ~]# blkid /dev/nvme0n2p2 /dev/nvme0n2p2: UUID="f04e6fa2-ee3b-4d8c-922d-2accbb93892f" TYPE="ext4" PARTLABEL="Linux swap" PARTUUID="889a041f-7012-4673-b70b-ffcc3cc3d4a6" [root@sanjeeb ~]# blkid /dev/nvme0n2p1 /dev/nvme0n2p1: UUID="399926fd-9ea0-4d14-92b0-8b579371f38e" TYPE="xfs" PARTLABEL="Linux filesystem" PARTUUID="a786964b-469f-491c-a0fd-7044d511f1bb"
Mounting
Temporary Mounting
Link with mount will be breaked if following this way :
# Mounting a Partition [root@sanjeeb data1]# mount /dev/nvme0n2p1 /root/data1 [root@sanjeeb data1]# mount /dev/nvme0n2p2 /root/data2 [root@sanjeeb data1]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sr0 11:0 1 8G 0 rom /run/media/root/CentOS-Stream-9-BaseOS-aarch64 nvme0n1 259:0 0 20G 0 disk ├─nvme0n1p1 259:1 0 600M 0 part /boot/efi ├─nvme0n1p2 259:2 0 1G 0 part /boot └─nvme0n1p3 259:3 0 18.4G 0 part ├─cs-root 253:0 0 16.4G 0 lvm / └─cs-swap 253:1 0 2G 0 lvm [SWAP] nvme0n2 259:4 0 5G 0 disk ├─nvme0n2p1 259:5 0 1G 0 part /root/data1 # Mounted ├─nvme0n2p2 259:6 0 300M 0 part /root/data2 # Mounted └─nvme0n2p3 259:7 0 512M 0 part # To check space utilized used df -h # You wont be able to see data if it is unmounted, but will be stored at partition # Unmounting a Partition [root@sanjeeb ~]# umount /dev/nvme0n2p1 [root@sanjeeb ~]# umount /dev/nvme0n2p2
Permanent Mounting
- File:
/etc/fstab
- Format:
<partition name> <mount point> <fstype> <mount options> 0 0
- Mount Options
Default | Non Default |
---|---|
rw | ro |
exec | noexec |
async | sync |
suid | nosuid |
dev | nodev |
auto | noauto |
nouser | user |
# MOUNTING PARTITION nvme0n2p1 # Add the command in fstab file [root@sanjeeb ~]# vim /etc/fstab /dev/nvme0n2p1 /root/data1 xfs defaults 0 0 [root@sanjeeb ~]# systemctl daemon-reload [root@sanjeeb ~]# mount -a [root@sanjeeb ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sr0 11:0 1 8G 0 rom /run/media/root/CentOS-Stream-9-BaseOS-aarch64 nvme0n1 259:0 0 20G 0 disk ├─nvme0n1p1 259:1 0 600M 0 part /boot/efi ├─nvme0n1p2 259:2 0 1G 0 part /boot └─nvme0n1p3 259:3 0 18.4G 0 part ├─cs-root 253:0 0 16.4G 0 lvm / └─cs-swap 253:1 0 2G 0 lvm [SWAP] nvme0n2 259:4 0 5G 0 disk ├─nvme0n2p1 259:5 0 1G 0 part /root/data1 ├─nvme0n2p2 259:6 0 300M 0 part └─nvme0n2p3 259:7 0 512M 0 part [root@sanjeeb ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 4.0M 0 4.0M 0% /dev tmpfs 1.8G 0 1.8G 0% /dev/shm tmpfs 718M 9.3M 708M 2% /run /dev/mapper/cs-root 17G 13G 3.4G 80% / /dev/nvme0n1p2 960M 375M 586M 39% /boot /dev/nvme0n1p1 599M 7.0M 592M 2% /boot/efi tmpfs 359M 100K 359M 1% /run/user/0 /dev/sr0 8.1G 8.1G 0 100% /run/media/root/CentOS-Stream-9-BaseOS-aarch64 /dev/nvme0n2p1 960M 40M 921M 5% /root/data1 # MOUNTING PARTITION nvme0n2p2 [root@sanjeeb ~]# vim /etc/fstab [root@sanjeeb ~]# tail -1 /etc/fstab /dev/nvme0n2p2 /root/data2 ext4 defaults 0 0 [root@sanjeeb ~]# systemctl daemon-reload [root@sanjeeb ~]# mount -a [root@sanjeeb ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sr0 11:0 1 8G 0 rom /run/media/root/CentOS-Stream-9-BaseOS-aarch64 nvme0n1 259:0 0 20G 0 disk ├─nvme0n1p1 259:1 0 600M 0 part /boot/efi ├─nvme0n1p2 259:2 0 1G 0 part /boot └─nvme0n1p3 259:3 0 18.4G 0 part ├─cs-root 253:0 0 16.4G 0 lvm / └─cs-swap 253:1 0 2G 0 lvm [SWAP] nvme0n2 259:4 0 5G 0 disk ├─nvme0n2p1 259:5 0 1G 0 part /root/data1 ├─nvme0n2p2 259:6 0 300M 0 part /root/data2 └─nvme0n2p3 259:7 0 512M 0 part [root@sanjeeb ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 4.0M 0 4.0M 0% /dev tmpfs 1.8G 0 1.8G 0% /dev/shm tmpfs 718M 9.3M 708M 2% /run /dev/mapper/cs-root 17G 13G 3.4G 80% / /dev/nvme0n1p2 960M 375M 586M 39% /boot /dev/nvme0n1p1 599M 7.0M 592M 2% /boot/efi tmpfs 359M 96K 359M 1% /run/user/0 /dev/sr0 8.1G 8.1G 0 100% /run/media/root/CentOS-Stream-9-BaseOS-aarch64 /dev/nvme0n2p1 960M 40M 921M 5% /root/data1 /dev/nvme0n2p2 272M 14K 253M 1% /root/data2
Remounting a Partition
- Command :
mount -o remount,<new mount option> <mount point>
# TEMPORARY REMOUNTING # Providing ro , noexec mount options [root@sanjeeb ~]# mount -o remount,ro,noexec /root/data1 [root@sanjeeb ~]# rm -rf * /root/data1 rm: cannot remove 'data1/secure': Read-only file system rm: cannot remove 'data1/secure-20240405': Read-only file system rm: cannot remove 'data1/secure-20240407': Read-only file system rm: cannot remove 'data1/secure-20240920': Read-only file system ... [root@sanjeeb ~]# mount | grep data1 /dev/nvme0n2p1 on /root/data1 type xfs (ro,noexec,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota) # PERMANENT REMOUNTING [root@sanjeeb ~]# mount | grep data2 /dev/nvme0n2p2 on /root/data2 type ext4 (ro,nosuid,nodev,noexec,relatime,sync,seclabel) [root@sanjeeb ~]# vim /etc/fstab [root@sanjeeb ~]# tail -1 /etc/fstab /dev/nvme0n2p2 /root/data2 ext4 rw,exec,async,suid,dev,auto,nouser 0 0 [root@sanjeeb ~]# umount /root/data2 [root@sanjeeb ~]# systemctl daemon-reload [root@sanjeeb ~]# mount /root/data2 [root@sanjeeb ~]# mount | grep data2 /dev/nvme0n2p2 on /root/data2 type ext4 (rw,relatime,seclabel)
Creating a GPT-Based and MBR-Based Partitioning with parted
[root@server ~]# parted /dev/nvme0n2 GNU Parted 3.5 Using /dev/nvme0n2 Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) mkpart Partition type? primary/extended? primary File system type? [ext2]? Start? 1MiB End? 200MiB (parted) p Model: VMware Virtual NVMe Disk (nvme) Disk /dev/nvme0n2: 5369MB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 210MB 209MB primary ext2
Viewing a GPT-Based Disk's Partition Table with gdisk
[root@server ~]# gdisk -l /dev/nvme0n2 GPT fdisk (gdisk) version 1.0.7 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. Disk /dev/nvme0n2: 10485760 sectors, 5.0 GiB Model: VMware Virtual NVMe Disk Sector size (logical/physical): 512/512 bytes Disk identifier (GUID): E0095413-4144-47C5-86A9-E1553AFD5F65 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 10485726 Partitions will be aligned on 2048-sector boundaries Total free space is 4960189 sectors (2.4 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 2099199 1024.0 MiB 8300 Linux filesystem 2 2099200 3123199 500.0 MiB 8300 Linux filesystem 3 3123200 5220351 1024.0 MiB 8200 Linux swap 4 5220352 5425151 100.0 MiB 8300 Linux filesystem 5 5425152 5527551 50.0 MiB 8300
Viewing a Disk's Partition Table with parted
[root@server ~]# parted /dev/nvme0n2 GNU Parted 3.5 Using /dev/nvme0n2 Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) p Model: VMware Virtual NVMe Disk (nvme) Disk /dev/nvme0n2: 5369MB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 210MB 209MB primary ext4
Deleting the GPT Based Partition with gdisk
[root@server ~]# gdisk /dev/nvme0n2 GPT fdisk (gdisk) version 1.0.7 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. Command (? for help): d Partition number (1-5): 5 Command (? for help): p Disk /dev/nvme0n2: 10485760 sectors, 5.0 GiB Model: VMware Virtual NVMe Disk Sector size (logical/physical): 512/512 bytes Disk identifier (GUID): E0095413-4144-47C5-86A9-E1553AFD5F65 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 10485726 Partitions will be aligned on 2048-sector boundaries Total free space is 5062589 sectors (2.4 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 2099199 1024.0 MiB 8300 Linux filesystem 2 2099200 3123199 500.0 MiB 8300 Linux filesystem 3 3123200 5220351 1024.0 MiB 8200 Linux swap 4 5220352 5425151 100.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/nvme0n2. Warning: The kernel is still using the old partition table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) The operation has completed successfully.
Deleting the Partition with parted
[root@server ~]# parted /dev/nvme0n2 GNU Parted 3.5 Using /dev/nvme0n2 Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) p Model: VMware Virtual NVMe Disk (nvme) Disk /dev/nvme0n2: 5369MB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 210MB 209MB primary ext4 (parted) rm 1 (parted) p Model: VMware Virtual NVMe Disk (nvme) Disk /dev/nvme0n2: 5369MB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags
Updating Disk Partition Information with partprobe
The command partprobe /dev/disk_name is used to inform the operating system kernel about changes to the partitions on a particular disk. When you add, remove, or modify partitions on a disk, the changes might not be immediately recognized by the operating system. By running partprobe, you're telling the system to re-read the partition table of the specified disk (/dev/disk_name) and update its records accordingly without requiring a system reboot. This is particularly useful in scenarios where you've made changes to disk partitions (e.g., creating, deleting, or resizing partitions) and need the system to recognize those changes without restarting.
[root@server ~]# partprobe /dev/nvme0n2
Updating the partition type with gdisk
[root@server ~]# gdisk /dev/nvme0n2 GPT fdisk (gdisk) version 1.0.7 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/nvme0n2: 10485760 sectors, 5.0 GiB Model: VMware Virtual NVMe Disk Sector size (logical/physical): 512/512 bytes Disk identifier (GUID): E0095413-4144-47C5-86A9-E1553AFD5F65 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 10485726 Partitions will be aligned on 2048-sector boundaries Total free space is 5062589 sectors (2.4 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 2099199 1024.0 MiB 8300 Linux filesystem 2 2099200 3123199 500.0 MiB 8300 Linux filesystem 3 3123200 5220351 1024.0 MiB 8200 Linux swap 4 5220352 5425151 100.0 MiB 8300 Linux filesystem Command (? for help): t Partition number (1-4): 4 Current type is 8300 (Linux filesystem) Hex code or GUID (L to show codes, Enter = 8300): L Type search string, or <Enter> to show all codes: 0700 Microsoft basic data 0701 Microsoft Storage Replica 0702 ArcaOS Type 1 0c01 Microsoft reserved 2700 Windows RE 3000 ONIE boot 3001 ONIE config 3900 Plan 9 4100 PowerPC PReP boot 4200 Windows LDM data 4201 Windows LDM metadata 4202 Windows Storage Spaces 7501 IBM GPFS 7f00 ChromeOS kernel 7f01 ChromeOS root 7f02 ChromeOS reserved 8200 Linux swap 8300 Linux filesystem 8301 Linux reserved 8302 Linux /home 8303 Linux x86 root (/) 8304 Linux x86-64 root (/) 8305 Linux ARM64 root (/) 8306 Linux /srv 8307 Linux ARM32 root (/) 8308 Linux dm-crypt 8309 Linux LUKS 830a Linux IA-64 root (/) 830b Linux x86 root verity 830c Linux x86-64 root verity 830d Linux ARM32 root verity 830e Linux ARM64 root verity 830f Linux IA-64 root verity 8310 Linux /var 8311 Linux /var/tmp 8312 Linux users home 8313 Linux x86 /usr 8314 Linux x86-64 /usr 8315 Linux ARM32 /usr 8316 Linux ARM64 /usr 8317 Linux IA-64 /usr 8318 Linux x86 /usr verity Press the <Enter> key to see more codes, q to quit: q Hex code or GUID (L to show codes, Enter = 8300): 8200 Changed type of partition to 'Linux swap' Command (? for help): p Disk /dev/nvme0n2: 10485760 sectors, 5.0 GiB Model: VMware Virtual NVMe Disk Sector size (logical/physical): 512/512 bytes Disk identifier (GUID): E0095413-4144-47C5-86A9-E1553AFD5F65 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 10485726 Partitions will be aligned on 2048-sector boundaries Total free space is 5062589 sectors (2.4 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 2099199 1024.0 MiB 8300 Linux filesystem 2 2099200 3123199 500.0 MiB 8300 Linux filesystem 3 3123200 5220351 1024.0 MiB 8200 Linux swap 4 5220352 5425151 100.0 MiB 8200 Linux swap 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/nvme0n2. Warning: The kernel is still using the old partition table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) The operation has completed successfully.
Erasing all the disk inside a partition
wipefs --all /dev/disk_name
Viewing the partition table type
We can see that the below is in msdos || dos || MBR based
[root@server ~]# fdisk -l Disk /dev/nvme0n1: 20 GiB, 21474836480 bytes, 41943040 sectors Disk model: VMware Virtual NVMe Disk 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: 028CCBBE-5452-4A7B-8FE9-542CBE517782 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 41940991 38612992 18.4G Linux LVM Disk /dev/nvme0n2: 5 GiB, 5368709120 bytes, 10485760 sectors Disk model: VMware Virtual NVMe Disk 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: dos #This one is DOS based Disk identifier: 0x6ca868d6 Disk /dev/nvme0n3: 6 GiB, 6442450944 bytes, 12582912 sectors Disk model: VMware Virtual NVMe Disk Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/cs-root: 16.41 GiB, 17620271104 bytes, 34414592 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 Disk /dev/mapper/cs-swap: 2 GiB, 2147483648 bytes, 4194304 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
Changing the partition table type
Changing this partition table from MBR (Master Boot Record) to GPT(GUID Partition Table) using gdisk
.
[root@server ~]# gdisk /dev/nvme0n2 GPT fdisk (gdisk) version 1.0.7 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 in memory. THIS OPERATION IS POTENTIALLY DESTRUCTIVE! Exit by typing 'q' if you dont want to convert your MBR partitions to GPT format! *************************************************************** Command (? for help): w # Use w to save as gdisk automatically converts MBR to GPT 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/nvme0n2. The operation has completed successfully. [root@server ~]# fdisk -l /dev/nvme0n2 Disk /dev/nvme0n2: 5 GiB, 5368709120 bytes, 10485760 sectors Disk model: VMware Virtual NVMe Disk 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: 247AAE98-5819-43EA-9265-AA6BA3BB742A
Changing the partition table from GPT(GUID Partition Table) to MBR(Master Boot Record) using parted
.
[root@server ~]# parted /dev/nvme0n2 GNU Parted 3.5 Using /dev/nvme0n2 Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) mklabel GPT # Viewing the partition table type of /dev/nvme0n2 [root@server ~]# fdisk -l /dev/nvme0n2 Disk /dev/nvme0n2: 5 GiB, 5368709120 bytes, 10485760 sectors Disk model: VMware Virtual NVMe Disk 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: 47638739-9F59-48AC-8437-89F1A6F72239
Changing the partition table from MBR(Master Boot Record) to GPT(GUID Partition Table) using parted
.
[root@server ~]# parted /dev/nvme0n2 GNU Parted 3.5 Using /dev/nvme0n2 Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) mklabel msdos # Viewing the partition table type of /dev/nvme0n2 [root@server ~]# fdisk -l /dev/nvme0n2 Disk /dev/nvme0n2: 5 GiB, 5368709120 bytes, 10485760 sectors Disk model: VMware Virtual NVMe Disk 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: dos Disk identifier: 0x4ebbff97