I wanted to add a partition to the /dev/sda mistakenly, I started fdisk with /dev/sda2 and treated It like a disk. How do i revert it?
ghostrider@dev1:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 800G 0 disk
├─sda1 8:1 0 953M 0 part /boot
└─sda2 8:2 0 399.1G 0 part /
ghostrider@dev1:~$ sudo fdisk /dev/sda2
Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
The old ext4 signature will be removed by a write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x1d9559e3.
Command (m for help): p
Disk /dev/sda2: 399.7 GiB, 428495339520 bytes, 836904960 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: dos
Disk identifier: 0x1d9559e3
Command (m for help): F
Unpartitioned space /dev/sda2: 399.7 GiB, 428494290944 bytes, 836902912 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
Start End Sectors Size
2048 836904959 836902912 399.1G
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-836904959, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-836904959, default 836904959):
Created a new partition 1 of type 'Linux' and of size 399.1 GiB.
Command (m for help): w
The partition table has been altered.
Failed to add partition 1 to system: Invalid argument
The kernel still uses the old partitions. The new table will be used at the next reboot.
Syncing disks.
ghostrider@dev1:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 800G 0 disk
├─sda1 8:1 0 953M 0 part /boot
└─sda2 8:2 0 399.1G 0 part /
Edit: After the server restarted later, server got stuck in initramfs with error message
Gave up waiting for root
ALERT! UUID=xx-xx-xx-xx-xx doesn't exist dropping to shell
The kernel still uses the old partitions. The new table will be used at the next reboot.This made me believe that something terrible has happened with the root partition.
– Sudip Bhattarai Feb 19 '21 at 04:17