:: Re: [Dng] How to bust into a broken…
Top Page
Delete this message
Reply to this message
Author: Peter Maloney
Date:  
To: dng
Subject: Re: [Dng] How to bust into a broken Qemu VM?
On 05/16/2015 02:00 AM, Adam Borowski wrote:
> On Fri, May 15, 2015 at 07:37:57PM -0400, Steve Litt wrote:
>> When you accidentally bork a Qemu VM such that it won't boot to a
>> virtual terminal, how do you bust back in. I doubt System Rescue CD
>> would help, unless you can boot from the "cdrom" but somehow also
>> access the existing "hard disk" borked VM image.
> Well... you use the exact same arguments as you used for installing the
> system in the first place. That is, give qemu both the hard disk image and
> the CD. Then -boot d to boot from the first attached CD.
>

Or you can have more fun and mount it on the host...


losetup /dev/loop0 disk1.img
kpartx -av /dev/loop0
Konsole output
Output looks something like:
Konsole output
add map loop0p1 (253:27): 0 9949184 linear /dev/loop0 2048
add map loop0p2 (253:28): 0 2 linear /dev/loop0 9953278
add map loop0p5 : 0 530432 linear /dev/loop0 9953280

Now you know that /dev/dm-27 and /dev/dm-28 are your partitions. Also
there is /dev/mapper/loop0p1 and p2 which are symlinks to those.

Then mount and chroot to fix whatever you want.

#if there was lvm in there, (sometimes) you also need:
#vgchange -an vgname
#vgchange -ay vgname

mount /dev/dm-28 /mnt/test
mount /dev/dm-27 /mnt/test/boot
for d in dev proc sys; do
    mount -obind /"$d" /mnt/test/"$d"
done
chroot /mnt/test



Then do some things to fix it... like fix fstab:

blkid
vim /etc/fstab

And refresh the bootloader and related:

grub-install /dev/loop0
update-initramfs -u
update-grub


you can also use apt-get as long as resolv.conf is right.

Then exit and clean up.

exit or ctrl+d (logout of chroot)


umount /mnt/test/*
umount /mnt/test

#if there was lvm there, also:
#vgchange -an vgname

kpartx -d /dev/loop0
losetup -d /dev/loop0