I've gotten myself in a bit of a bind, here.

A while ago I set up an encrypted Unbuntu 13.04 under Xen. It's virtual disk is an LVM LV.

This LV was presented to the DomU as a (whole) physical disk during installation, and I let Ubuntu's installer set up encrypted root and swap (using LVM).

However, I forgot to write down the root pw. Or I wrote it down wrong. After a power failure the other day I cannot get back into the machine as root.

I have the passphrase for the DomU:s LVM partition though, so the DomU goes up. I just can't log in. Booting with init=/bin/bash does not work, since init needs to unlock the encrypted partition.

I can't figure out how to open the LVM-containg partition the LVM LV from Dom0, either, since ´cryptsetup luksOpen´ won't accept an offset in the LVM LV.

Does anyone know how to get into the LV - Partition - (LVM) - LV and reset the root password?

1 Answer 1


I'm not familiar with Xen. With KVM, I'd just make the VM boot up in a rescue or live CD, and chroot from there. As you would do if you had this problem on your real desktop.

If all you need is an offset, in general you can use losetup for that. Or more specifically offsets for partition tables, you can use partx or kpartx.

If you have a partitioned LV, you could get the offsets using parted:

parted /dev/mapper/lvm-vmfoobar unit b print

and it would print partition offsets (in bytes) like so

Number  Start         End           Size          Type      File system  Flags
 1      1048576B      2148532223B   2147483648B   primary   fat32        lba
 2      2149580800B   3223322623B   1073741824B   primary   ext2         boot
 3      3224371200B   13961789439B  10737418240B  primary   ext2

So suppose you wanted to access the partition 3 more direct like, using the offset 3224371200, you could do it with losetup like this:

# losetup -f --show -o 3224371200 --sizelimit 10737418240 /dev/mapper/lvm-foobar

(sizelimit is optional, for safety so you can not write past the end of the partition)

and verify that it's the correct thing

file -s /dev/loop0
/dev/loop0: Linux rev 1.0 ext2 filesystem data, UUID...

Alternatively if you have partx or kpartx, a simple

partx -a /dev/mapper/lvm-foobar

should work and you'd find the mapped partitions like /dev/mapper/lvm-foobarp1 or similar (kpartx may use different names from partx).

And then you can work with that mapped device (cryptsetup luksOpen, vgchange, ...) so you should eventually be able to mount the root filesystem of the VM, chroot, and passwd a new root password.

  • Yes! losetup was the key. Then I got file -s /dev/loop0 /dev/loop0: LUKS encrypted file ... (which contained the LVM, and the rest was a piece of cake.) Thank you!
    – uvesten
    Jul 2, 2013 at 7:54

You must log in to answer this question.

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