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:
Tweetvirsh console vm_name
Erik
Friday, August 1, 2014
linux administration - tips, notes and projects
No Comment