Need help recovering ext4 partition Topic is solved

How to use TestDisk to recover lost partition
Forum rules
When asking for technical support:
- Search for posts on the same topic before posting a new question.
- Give clear, specific information in the title of your post.
- Include as many details as you can, MOST POSTS WILL GET ONLY ONE OR TWO ANSWERS.
- Post a follow up with a "Thank you" or "This worked!"
- When you learn something, use that knowledge to HELP ANOTHER USER LATER.
Before posting, please read https://www.cgsecurity.org/testdisk.pdf
Locked
Message
Author
goftari
Posts: 2
Joined: 07 Jun 2022, 03:04

Need help recovering ext4 partition

#1 Post by goftari »

Hello to all respectful members,
I did make a mistake last week and have spent the last doom days in hell figuring out how to get out of this situation.
I have a VMware ESXi virtual machine running Ubuntu 18.04 with LVM configured partitions.
I was trying to extend one of the logical volumes mount as / but mistakenly and foolishly deleted the LVM partition using cfdisk (the partition was formatted as ext4)
Here is what I did which caused the problem:
1. Increased the VM disk size in vSphere ESXi
2. Performed a rescan on SCSI device to make it recognize the disk resize without reboot
3. Confirmed the new disk disk using fdisk -l
4. Foolishly deleting the LVM partition (sda2) using cfdisk and recreating it with the new size (actually don't remember whether I changed the new partition type to LVM or not)
5. Tried to increase the PV size using pvresize /dev/sda2
6. Tried running partprobe to check why the PV was not resized where I got a message indicating that partition where in use by system
7. Performed a reboot and the OS did not boot as it was not able to mount the partitions
This is where the issue began.
What I tried:
1. I did boot the system using GParted bootable disk, restored the LVM partitions using pvcreate with the same UUID and vgcfgrestore (I recovered the old lvm backups using testdisk tool) with no success as the volume containing root partition was not mountable (unknown filesystem)
2. I tried running testdisk to recover important directories and files, but some restored files (I did check some text files, e.g. config and php files) have scrambled contents.
Please help with this issue if you have any similar experience.

Please excuse me for any inconvenience caused by my not natural English.

goftari
Posts: 2
Joined: 07 Jun 2022, 03:04

Re: Need help recovering ext4 partition

#2 Post by goftari »

The resolution was easy but took time for me to figure it out:

- Ran testdisk /dev/sda (the whole disk)
- Did a quick search and found two partitions (one 500 MB ext2 /boot partition and one 60 GB LVM2 partition)
- Wrote the found partition table on disk
- Performed a pvscan, vgscan and vgchange -ay (encountered an error indicating that the VG size was larger than the PV an therefore lvs shows the root lv with suspended flag).
- Extended the /dev/sda2 (LVM partition) to consume the remaining free space on disk using cfdisk
- Performed vgchange -ay one again and voila the system was able to reboot normally.

Locked