While creating UML instances on nova, I noticed I wasn’t able to ssh into my instances using the keypair I previously created. Looking at the logs on the nova-compute node, I saw:
2011-07-13 21:15:22,256 INFO nova.virt.libvirt_conn [-] instance instance-0000003d: injecting key into image 3 2011-07-13 21:15:22,256 DEBUG nova.utils [-] Running cmd (subprocess): sudo losetup --find --show /var/lib/nova/instances/instance-0000003d/disk from (pid=838) execute /usr/lib/pymodules/python2.7/nova/utils.py:143 2011-07-13 21:15:22,424 DEBUG nova.utils [-] Running cmd (subprocess): sudo kpartx -a /dev/loop0 from (pid=838) execute /usr/lib/pymodules/python2.7/nova/utils.py:143 2011-07-13 21:15:22,509 DEBUG nova.utils [-] Running cmd (subprocess): sudo kpartx -d /dev/loop0 from (pid=838) execute /usr/lib/pymodules/python2.7/nova/utils.py:143 2011-07-13 21:15:22,563 DEBUG nova.utils [-] Running cmd (subprocess): sudo losetup --detach /dev/loop0 from (pid=838) execute /usr/lib/pymodules/python2.7/nova/utils.py:143 2011-07-13 21:15:22,604 WARNING nova.virt.libvirt_conn [-] instance instance-0000003d: ignoring error injecting data into image 3 (Mapped device was not found (we can only inject raw disk images): /dev/mapper/loop0p1)
I tried running the kpartx commands above, but they didn’t return anything. This was because the image I was using had no partition table.
To fix, I effectively created a new image and copied data from the original one.
To begin, create a spare file (see this for more info):
# cd /root # dd if=/dev/zero of=CentOS5.6-AMD64-new-root_fs bs=1 count=0 seek=1024M
Now, create a partition to span the entire disk (replace /dev/loop0 with whatever losetup returns):
# losetup --show --find CentOS5.6-AMD64-new-root_fs /dev/loop0 # fdisk /dev/loop0
Now, use kpartx to make the partition visible to the host, and create a filesystem on that partition:
# parted # kpartx -a /dev/loop0 # mke2fs -j /dev/mapper/loop0p1
Mount the original image and copy data over:
# losetup --show --find CentOS5.6-AMD64-root_fs
/dev/loop1
# mkdir /mnt/loop{0,1}
# mount /dev/mapper/loop0p1 /mnt/loop0
# mount /dev/loop1 /mnt/loop1
# cd /mnt/loop1
# rsync -a . /mnt/loop0Update the fstab on the new image (this is necessary as the partition layout has now changed):
# cd /mnt/loop0/etc
# sed -i 's/ubda/ubda1/g' fstab
# cd /
# umount /mnt/loop{0,1}
# kpartx -d /dev/loop0
# losetup -d /dev/loop{0,1}Modify /etc/nova/libvirt.xml.template, changing this line from:
<root>/dev/ubda</root>
to:
<root>/dev/ubda1</root>
That should be about it.