0

I'm doing a couple of tests of Ubuntu autoinstall using cloud-init. In order to do so, I am following an example that's presented in the Autoinstall QuickStart page. In the given example, the presented password hash corresponds to the encrypted ubuntu passphrase and that works flawlessly. However, if I try to use my own encrypted hash, it doesn't seem to work (I can't login with the plain text password I feed the encryption algorithm with).

I know it probably has something to do with the encryption algorithm I'm using, but I think it should work and I would love to be able to check the /etc/shadow of the QEMU virtual machine to check what is being written there.

As per the example, I boot the VM with the following command:

kvm -no-reboot -m 2048 \
    -drive file=image.img,format=raw,cache=none,if=virtio

Is there a way to mount the filesystem of the VM to my local machine and check /etc/shadow?

TIA!

1 Answer 1

2

If image.img is indeed the image containing the Ubuntu root partition and it is indeed raw, things are very simple.

sudo losetup --find --show --partscan /path/to/image.img
# This will print something like /dev/loop0
sudo mount /dev/loop0p3 /mnt/ubuntu

You need to use the correct partition number, of course, which may not be p3.

Your version of losetup may not support --partscan. Instead, you can use sudo partprobe /dev/loop0. You can list partitions using sudo fdisk -l /dev/loop0 (or using similar tools).

Once you’re done:

sudo umount /mnt/ubuntu
sudo losetup --detach /dev/loop0

If it’s a different image format, you may try qemu-nbd or libguestfs-tools, both of which I unfortunately have no experience with. If you’re using QEMU, you probably already have qemu-nbd.

5
  • Thanks for replying! However, after selecting the correct device and partition, I'm getting mount: /mnt/ubuntu: special device /dev/loop3p3 does not exist.. Any idea what might be the issue? Commented Dec 19, 2022 at 8:56
  • Like I wrote: You may have to run partprobe. Also do make sure it’s the correct partition!
    – Daniel B
    Commented Dec 19, 2022 at 9:04
  • 2
    You need to use losetup --partscan to activate partition support for a loop device. It's not enabled by default. Commented Dec 20, 2022 at 10:45
  • @user1686 Interesting, I was not aware of this option. Maybe it’s a somewhat recent addition. I added it to the answer.
    – Daniel B
    Commented Dec 20, 2022 at 13:19
  • It's a 2011 addition, although I was wrong about "partition support" as it turns out the exact same commit also made it possible for partprobe etc. to manually add partitions even without kernel partition scanning being enabled. Commented Dec 20, 2022 at 14:13

You must log in to answer this question.

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