How to convert a vritual disk (zvol) to a bootable physical disk !?

I have a virtual ubuntu machine which I can not access any more. Some how the admin password does not work.

On a physical machine you could change the root/admin password in the early boot phase. Issue is that I do not manage to access the VM in that early boot stage.

So the only option seems to be to convert the VM-disk to a phyical disk and boot that disk on a physical machine.

So the big question is how to convert a ZVOL to a (bootable) physical disk.

Not sure you need to copy it to a physical disk.

I think I would use a loop back mount in TrueNAS SCALE / CE and then substitute the encrypted password with one I created elsewhere.

Something like this:

mkdir /mnt/temp
mount -t ext4 -o loop=/dev/loop1 /dev/zd0 /mnt/temp
cp -p /mnt/temp/etc/shadow /mnt/temp/etc/shadow.`date +%Y%m%d_%H%M`
vi /mnt/temp/etc/shadow
umount /mnt/temp
rmdir /mnt/temp

Note my wording, “Something like this”. There a bunch of user specific items that you need to make sure are suitable for YOU.

  • Select a mount point that is not in use, I’ve used /mnt/temp. But modify if needed.
  • Change the file system to match your Ubuntu VM. I’ve used ext4, modify if needed.
  • I’ve used loop1, but if you have that already in use, change it.
  • Last, I’ve used /dev/zd0 as the ZVol. If yours is different, change it.

None of this works if you’ve encrypted the client. Plus, if you don’t know the client file system, you might have to poke around to figure it out.

Good luck

A zvol is just a big “file”. You can simply copy the data and put it back in the SAME order (boot files).

But you can certainly do this in a VM too.

Add a display vnc or spice and catch the boot screen etc.

During a few weeks I have been working on rebuilding the lost VM. Not yet done. What ever!

There should be a simple way to access a VM from the very first moment the VM starts. As it is now you start the vm and only after the moment the VM has become active you can access the VM-console or gui. That is to late to make changes as .e.g. required to recover the root password the way which should be possible on a physical machine.

As it stands now all kind of tricks to get to the VM via editing or moving the VM to a physical machine are just to complicated.

So I will rebuild the VM from the start, a lot of work! I will do some improvements during the process that is the positive part.

Normally this situation would not occur since normally you reload a snapshot. But I did delete snapshots not foreseeing this issue, in order to return to a more stable situation a months back.

What ever I would highly appreciate an option to have vm access in the very early phase of the boot process.

How would you do this?

In the bad old days, Linux let you add “single” to the kernel line in Grub. That booted single user mode, which did not require a password.

Don’t think that has been an option for at least 10 years. At work we had to boot a RHEL ISO image, which allowed recovery of the VM’s data. (Even if on LVM or MD-RAID devices…) Which did occasionally include resetting the “root” password, or other OS related work.

Depending on security options, even just editing the Grub kernel line could be prevented without the Grub password. That was another reason I’ve used RHEL ISO images for VM recoveries.

Thank you. Well, concerning the OPs problem, booting the VM from another ISO image is perfectly possible in TrueNAS. For that, the ISO just has to be added as another device in the VM with lower device order than the original disk.

1 Like

Yes, that probably is the better option than the one I listed. Just did not think of it at the time.

1 Like