0

So I repartitioned a Windows 11 wsl2 Ubuntu partition without a backup. I still have the ext4.vhdx. How to extract important files from this file? Subquestion: Testdisk now shows the files I search for. When copying them it says Copy done! 0 ok, 0 failed. However, in the specified place on the filesystem I do not see the files (see update 2025/05/29 below). How to solve this?

I wanted to shrink the partition. Therefore I tried these steps in the then running wsl2 Ubuntu:

After fdisk is running, go through the following steps:

Type n for creating a new partition.

Type p for a primary partition (this is my case, yours can be a different one).

Type the value of the first sector of your partition (you can get this value from the "Start" column of the sudo parted /dev/sda unit s

print free command.

Type the value of the final sector of your partition (...) Type w to write the changes to disk

After this, you will have to reboot your system or run the sudo partprobe command to make the partition changes available for the kernel.

Well, WSL2 was unable to boot anymore.

Therefore I made a backup of the ext4.vhdx file of the Ubuntu distribution and wonder how to extract files from it.

I have tried

  • converting vhdx file on another debian to qcow2 format and mounting it.
# modprobe nbd max_part=8
root:~# qemu-nbd --connect=/dev/nbd0 /media/
cdrom/  stefan/ 
root:~# qemu-nbd --connect=/dev/nbd0 /media/stefan/tmp/
$RECYCLE.BIN/              System Volume Information/
ext4.qcow2                 wslext4.vhdx
ext4.vhdx                  
root:~# qemu-nbd --connect=/dev/nbd0 /media/stefan/tmp/ext4.qcow2 
root:~# fdisk /dev/nbd0 -l
Disk /dev/nbd0: 256 GiB, 274877906944 bytes, 536870912 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: 0x87fbf43f

Device Boot Start End Sectors Size Id Type /dev/nbd0p1 2048 536870911 536868864 256G 83 Linux root:~# ount /dev/nbd0p1 /mnt/wslubuntu/ -bash: ount: command not found root:~# mount /dev/nbd0p1 /mnt/wslubuntu/ mount: /mnt/wslubuntu/: mount point does not exist. dmesg(1) may have more information after failed mount system call. root:~# mkdir /mnt/wslubuntu root:~# mount /dev/nbd0p1 /mnt/wslubuntu/ mount: /mnt/wslubuntu: wrong fs type, bad option, bad superblock on /dev/nbd0p1, missing codepage or helper program, or other error. dmesg(1) may have more information after failed mount system call.

$ guestmount --add /media/stefan/tmp/ext4.vhdx --inspector --ro /mnt/wslubuntu/
guestmount: no operating system was found on this disk

If using guestfish ‘-i’ option, remove this option and instead use the commands ‘run’ followed by ‘list-filesystems’. You can then mount filesystems you want by hand using the ‘mount’ or ‘mount-ro’ command.

If using guestmount ‘-i’, remove this option and choose the filesystem(s) you want to see by manually adding ‘-m’ option(s). Use ‘virt-filesystems’ to see what filesystems are available.

If using other virt tools, this disk image won’t work with these tools. Use the guestfish equivalent commands (see the virt tool manual page).

My next try could be to reimport the distro in place. However, I do not expect this to help and rather reproduce the non starting system.

--- Update 2025/05/29 start ---

Because working in a train from the Linux notebook was easier, I was able to get a step further. Now I face:

Testdisk now shows the files I search for. When copying them it says Copy done! 0 ok, 0 failed. However, in the specified place on the filesystem I do not see the files. How to solve this?

Heres are the actions in testdisk:

TestDisk 7.1, Data Recovery Utility, July 2019
Christophe GRENIER <grenier@cgsecurity.org>
https://www.cgsecurity.org
   P ext4                           0  536870911  536870912
Directory /home/myuser
                                                   Previous
>drwxr-xr-x  1000  1000      4096  9-May-2025 12:18 Development

I type C to copy the files.

TestDisk 7.1, Data Recovery Utility, July 2019

Please select a destination where the marked files will be copied. Keys: Arrow keys to select another directory C when the destination is correct Q to quit Directory /home/mylocaluser/backups/work >drwxr-xr-x 0 0 4096 29-May-2025 11:45 . drwxr-xr-x 0 0 4096 29-May-2025 11:45 ..

C to copy there.

TestDisk 7.1, Data Recovery Utility, July 2019
Christophe GRENIER <grenier@cgsecurity.org>
https://www.cgsecurity.org
   P ext4                           0  536870911  536870912
Directory /home/myuser
Copy done! 0 ok, 0 failed                          Previous
>drwxr-xr-x  1000  1000      4096  9-May-2025 12:18 Development

Howver, there is no file:

root:/home/mylocaluser/backups/work# ls
root:/home/mylocaluser/backups/work#

--- Update 2025/05/29 end --- I am glad for any suggestions.

0 Answers0