Centos – Restore corrupted partition table in emergency mode without fdisk command

centosfdiskpartition

When I manage a VPS, I used fdisk to adjust partitions. But when I reboot, the server complained that the block count 2780624 exceeds size of device (2441472 blocks) and entered emergency mode.

I have backed up the partition but the emergency mode did not have a fdisk command for restoring partitions.

Currently, I could either enter the emergency terminal or before it enter the grub terminal via VNC. In the emergency mode, available commands include:
/bin commands screenshot, /sbin commands screenshot

It's my first time dealing with such issue, so if you need any further information, I would provide it asap.

Edit:

  • The system is CentOS 7.
  • I have backed up the privious partition. Partition screenshot
  • No tools fdisk, gpart, cfdisk, sfdisk available.
  • What I concern most is retrieving some important data in the disk.

Edit: I found that the server snapshot can be captured and downloaded. Is it easier to restore data locally?

Best Answer

Based on the information posted, I can't make up a way forward, in case your problem is really the partition table.

You could bring up network (ip an dhclient are there) but there is no tool to get something from the web or another server.

Still I doubt that fdisk shown on your screenshot is what is saved, as the blocks indicate that sda2 should be within the disk limits (except you shrunk your disk somehow). In order to dig deeper on that it would be helpful to see the dmesg & mount output. Typically / is mounted during initrd stage on /sysroot when CentOS is booting, and with chroot inside the initrd it is often possible to use utilities in the root disk for recovery purposes. Still this way forward, would require beeing able to mount the root partition.

As long as the partition start sectors in the partition table are correct it could be possible.