Categories
Unix

Restoring damaged /boot from XEN guest

I have a number of XEN and KVM virtual machines and I just had a case where one XEN guest had a problem with the new kernel I upgraded to. It would not boot, showing Error: (2, ‘Invalid kernel’, ‘xc_dom_parse_elf_kernel: ELF image has no shstrtab\n’) when the “xm create” was performed.

So I had to get into the /boot and fix the kernel and the grub.conf. How to do that safely on an image? Well it seems you CAN mount ext3 and other filesystems, but you CANNOT mount LVM or swap partitions. So fortunately the boot partition was ext3. Here are the set of commands I used to mount the image, vm01.img:

losetup -a

losetup /dev/loop5 vm01.img

fdisk -l /dev/loop5

lomount -t ext3 -diskimage vm01.img -partition 1 /mnt

Then you can go into /mnt and alter the kernels and edit grub/grub.conf. Once mounted, you can copy over new kernel files, but typically the /boot partition is a smaller size than the rest of the disk. I actually had some files I wanted to also copy over into /lib later, and they were needed for the networking to work. So I put them in gzipped tarballs in /boot a portion at a time and then when I would boot into the uncomplete setup I could copy them into place. A hack for sure, but that’s how I got more files over throughout the process.

Then, when done:

umount /mnt

losetup -d /dev/loop5

You need to do this to cleanly close the image. Then you can “xm create” your fixed up image!