Home How to delete partition in Linux
Post
Cancel

How to delete partition in Linux

Identify the disk which contains the partitions

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ lsblk
NAME                         MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sr0                           11:0    1   9.5G  0 rom
nvme0n1                      259:6    0   1.5T  0 disk
├─nvme0n1p1                  259:7    0   200M  0 part /boot/efi
├─nvme0n1p2                  259:8    0     1G  0 part /boot
└─nvme0n1p3                  259:9    0   1.5T  0 part
  ├─centos_init500--c11-root 253:0    0    50G  0 lvm  /
  ├─centos_init500--c11-swap 253:1    0     4G  0 lvm  [SWAP]
  └─centos_init500--c11-home 253:2    0   1.4T  0 lvm  /home
nvme1n1                      259:10   0   1.5T  0 disk
├─nvme1n1p1                  259:13   0   100M  0 part
├─nvme1n1p5                  259:14   0     4G  0 part
├─nvme1n1p6                  259:15   0     4G  0 part
├─nvme1n1p7                  259:17   0 119.9G  0 part
└─nvme1n1p8                  259:18   0   1.3T  0 part
1
2
3
4
5
6
7
8
9
10
11
12
$ fdisk -l
[..]
Disk /dev/nvme1n1: 1600.3 GB, 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
Disk label type: dos
Disk identifier: 0x7f33a7d2

        Device Boot      Start         End      Blocks   Id  System
/dev/nvme1n1p1               1  3125627534  1562813767   ee  GPT
[..]

Delete the partitions

Select the disk that contains the partitions you intend to delete:

1
2
3
4
5
$ fdisk /dev/nvme1n1
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Delete the partition:

1
2
3
Command (m for help): d
Selected partition 1
Partition 1 is deleted

NOTE: The partition is automatically selected if there are no other partitions on disk. If the disk contains multiple partitions, select a partition that you want to delete.

Verify the paritions:

1
2
3
4
5
6
7
8
9
10
Command (m for help): p

Disk /dev/nvme1n1: 1600.3 GB, 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
Disk label type: dos
Disk identifier: 0x7f33a7d2

        Device Boot      Start         End      Blocks   Id  System

Save the change and quit fdisk:

1
2
3
4
5
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Verify the partitions with lsblk:

1
2
3
4
5
6
7
8
9
10
11
$ lsblk
NAME                         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0                           11:0    1  9.5G  0 rom
nvme0n1                      259:6    0  1.5T  0 disk
├─nvme0n1p1                  259:7    0  200M  0 part /boot/efi
├─nvme0n1p2                  259:8    0    1G  0 part /boot
└─nvme0n1p3                  259:9    0  1.5T  0 part
  ├─centos_init500--c11-root 253:0    0   50G  0 lvm  /
  ├─centos_init500--c11-swap 253:1    0    4G  0 lvm  [SWAP]
  └─centos_init500--c11-home 253:2    0  1.4T  0 lvm  /home
nvme1n1                      259:10   0  1.5T  0 disk
This post is licensed under CC BY 4.0 by the author.

Useful Elastic cluster APIs

-

Comments powered by Disqus.