single
or init=/bin/bash
to the kernel boot line in GRUB do not work. The only option left is to boot from a rescue disc, but this is a virtual machine -- there is no DVD drive. Oh, no -- what to do?NEWS FLASH: I just learned from a colleague that there is a much easier method. It is possible to
chroot
directly into the VM from the virtualization host. Will post detailed instructions as soon as I get them. Until then, there is always the "long route" described below.Fortunately, it's not as difficult as it might seem. I already published a related blog entry entitled "KVM: boot VM from PXE or ISO image", but it doesn't quite do the trick. Here is a more complete description of the entire process:
- Obtain an ISO image of my preferred Rescue CD/DVD (pretty much any one will do for this operation)
- On the KVM virtualization server, put this ISO into a directory such as
/var/tmp
- Find the XML file with the definition of your VM -- let's say it's
/home/smithfarm/kvm/host.xml
- Open that file in your favorite editor
- In the
<os>
section, add aboot
stanza immediately above the existing boot stanzas:
<boot dev='cdrom'/>
- In the
<devices>
section, add adisk
stanza for the ISO:
<disk type 'file' device='cdrom'> <source file='/var/tmp/[FILENAME].iso'/> <target dev='hdc' bus='ide'/> <readonly/> </disk>
- Make sure the VM is down --
virsh shutdown [host]
or, failing that,virsh destroy [host]
- Now, at this point, I will need a way to watch the machine boot up. For this, I use "Virtual Machine Manager powered by libvirt". It has a website: http://virt-manager.org/ -- this needs to be installed, configured, and running
- Power it on:
# virsh create /home/smithfarm/kvm/host.xml
- As soon as the VM appears in Virt Manager, open it quickly. At this point I should see the rescue CD booting.
- When the rescue system boots, I will have a root prompt.
- Next step: determine on which device the root filesystem resides. The
blkid
command can be helpful. If there are multiple candidates, just mount them one by one and look for the telltale signs of a root filesystem. - Now I know the device name of the root filesystem -- let's say it's
/dev/sda2
- Mount and
chroot
into the root filesystem like so:
# mount -o rw /dev/sda2 /mnt # mount --bind /dev /mnt/dev/ # mount --bind /proc /mnt/proc/ # mount --bind /sys /mnt/sys/ # chroot /mnt target#
- Now I should have a root shell in the target system. From here, resetting the root password is a simple matter of executing the
passwd
command. - Exit from the target system and unmount the root filesystem:
target# exit # umount /mnt/sys # umount /mnt/proc # umount /mnt/dev # umount /mnt
- Shut down the rescue system:
# shutdown -h now
- Back on the KVM virtualization server, remove the lines we added to the XML file.
- Power on the VM using
virsh create
and enjoy logging in with new root password.
No comments:
Post a Comment