inside the mind of a linux admin

Virtualization: KVM equivalent to “vzctl enter” in OpenVZ

If you are used to using Virtuozzo or OpenVZ containers and are looking to make the switch to the full virtualization solution KVM (Kernel-based Virtual Machine), you may find one very convenient feature missing: the ability to enter into a virtual environment from the parent node.

Of course, the most popular solution used to access KVM VM is simply connecting via SSH. But what if your key gets removed or the SSH service becomes inaccessible? Rest assured, you can use this little trick to gain access directly to a root shell and manage your VM:

1. Inside the KVM VM edit /etc/default/grub and add the line:

GRUB_CMDLINE_LINUX_DEFAULT=”quiet console=tty0″

2. Update grub

update-grub

3. Next, add this line to the VM’s /etc/inittab file:

T0:23:respawn:/sbin/getty -l /usr/local/bin/autologin -n -L ttyS0 115200 vt102

4. Then create an executable file /usr/local/bin/autologin that will execute /bin/login:

echo ‘#!/bin/sh exec /bin/login -f root’ > /usr/local/bin/autologin
chmod +x /usr/local/bin/autologin

5. Restart the VM

6. Finally, enter the VM using the command:

virsh console vm_name

Related Posts

Touchpad stops working after sleep + resume (Fedora 26 on Dell XPS)

After recently upgrading my Dell XPS 13 w/Touchscreen to Fedora 26, the touchpad suddenly stopped working upon resuming from sleep mode. It was reproduced 100% of the time, and required a complete restart in order to get the touchpad working again. There have been several forum posts and bug reports regarding others experiencing these exact […]

Read More

Fun with fsck on Fedora – avoiding mounted partitions and handling LUKS encrypted ones

I run Fedora on a few of my machines, and inevitably over the course of time the filesystem will need to be repaired because of orphaned inodes, wrong free byte counts, etc. Typically when EXT4 errors are detected during boot, Fedora will detect this and offer to drop you into “Emergency mode” or continue. example: […]

Read More

Leave a Reply

Your email address will not be published. Required fields are marked *

Twitter: kireguy

Tweeter button Facebook button Myspace button