0

I am having a CentOS7 VM.

During fdisk /dev/sda delete to resize partition, we deleted the primary partition and during recreation extended was chosen instead of primary. Changes were saved and reboot was given.

All actions are shown below, while the system boots the below are shown on the Console.

I am looking a way to make the system bootable again, and have better understanding what happed.

1. Console Output:

[ OK ] Started Show Plymouth Boot Screen.
[ OK ] Reached target Paths.
[ OK ] Started Forward Password Requests to Plymouth Directory Watch.
[ OK ] Reached Target Basic System.

....
dracut-initqueueu[262] Warning: dracut-initqueueu timeout - starting timeout scripts
....

Starting Dracut Emergency Shell...
Warning /dev/mapper/rootvg-rootlv does not exist
Warning /dev/rootvg/rootlv does not exist

2. Actions Performed to VM and become unbootable:

[root@Server ~]# lsblk
NAME              MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                 8:0    0   25G  0 disk
├─sda1              8:1    0    1G  0 part /boot
├─sda2              8:2    0    1G  0 part
│ └─swapvg-swaplv 253:1    0    1G  0 lvm  [SWAP]
└─sda3              8:3    0   23G  0 part
  └─rootvg-rootlv 253:0    0   23G  0 lvm  /
sr0                11:0    1 1024M  0 rom
[root@Server ~]# fdisk /dev/sda
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.


Command (m for help): p

Disk /dev/sda: 26.8 GB, 26843545600 bytes, 52428800 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: 0x000ea6ab

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200     4202495     1051648   8e  Linux LVM
/dev/sda3         4202496    52428799    24113152   8e  Linux LVM

Command (m for help): d
Partition number (1-3, default 3):
Partition 3 is deleted

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): e
Partition number (3,4, default 3):
First sector (4202496-52428799, default 4202496):
Using default value 4202496
Last sector, +sectors or +size{K,M,G} (4202496-52428799, default 52428799):
Using default value 52428799
Partition 3 of type Extended and of size 23 GiB is set

Command (m for help): t
Partition number (1-3, default 3):
Hex code (type L to list all codes): 8e

You cannot change a partition into an extended one or vice versa.
Delete it first.

Type of partition 3 is unchanged: Extended

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@Server ~]# reboot
0

1 Answer 1

3

What happened?

The layout of an extended partition boot record differs from a primary: it's onion layered, resulting in a partition-inside-the-partition and thus different data offsets.

Also creating an extended partition without adding one inside (don't add it!) is useless: the OS just sees there's not any partition available, because it's just a container, very crude compared to other storage containers available like LVM you were using. Linux would also start naming such new partition inside the EPBR from the 5th partition (eg: /dev/sda5) which wouldn't cause much trouble as long as LVM is still auto-detected. The fact that you didn't then create an extended type partition has probably prevented further damage.

What to do?

As it's a VM and it's thus easy, you should first do anyway a backup including the complete disk image, in case further actions cause additional damages.

You should revert your changes and use again a primary partition the same way you did: deleting the partition and recreating it in-place, using the previous offsets and length, hoping that no actual data overwrite actually happened (that's not guaranteed). You have all the data needed to put back this primary partition as it was.

You can't easily switch from primary to extended, as the fdisk tool warned about and as you discovered.

How to do it since it can't boot?

Like would be done with a real system having a problem: if it can't boot, use a rescue disk. Any Live CD/USB distribution can do, it doesn't have to be CentOS, it could be a Debian Live CD image for example.

You'll have to get such live disk image, and attach it as disk to the VM, and make it bootable. Then boot on it, find a menu to get a shell and become root, find your disk: for example it might have been renamed from /dev/sda to /dev/sdb or not depending on how this was done, and run fdisk again. If fdisk isn't available, find a way to get the command or an equivalent one. Be careful, newer tool versions offer to wipe partition/filesystem signatures, don't allow it to wipe anything.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .