Lets say that we have to remotely reinstall a server and it doesnt have a KVM over IP like iLO (https://en.wikipedia.org/wiki/HP_Integrated_Lights-Out) so we cant access the console and theres no way to plug a USB key remotely either.
The solution is to use Virtualization and VNC, specifically Linux KVM (https://www.linux-kvm.org/page/Main_Page) .
We need first to get the server booted with an OS that supports KVM such as the install CD from ArchLinux (https://www.archlinux.org/download/)
Then we need to download a set of tools to use KVM that are statically linked so they can run on the rescue environment:
$ wget https://www.dropbox.com/s/t6mem4rqphk89n5/kvm-static.tar.gz $ tar zxvf kvm-static.tar.gz
We test if we can use KVM acceleration:
INFO: Your CPU does not support KVM extensions KVM acceleration can NOT be used
(Acceleration won’t be used but you can still use KVM, you may need to execute: modprobe kvm_intel to enable it)
INFO: /dev/kvm exists KVM acceleration can be used
Then we need to upload the ISO of the OS we are about to install, in this example we use Proxmox 5 (https://www.proxmox.com/en/downloads)
Tip: You can use your browser to generate a download command that you can use from the command line by selecting “Copy as cURL”.
Its very important to download the ISO /tmp or there won’t be enough space.
$ cd /tmp $ wget http://.../proxmox-ve_5.0-0d270679-2.iso
Finally we run the VM with the installer as cdrom, remove “-enable-kvm” if you don’t have acceleration support.
$ qemu-system-x86_64 -L /root/share/qemu -net nic \ -net user,hostfwd=tcp::80-:80,hostfwd=tcp::443-:443 \ -m 1024M -localtime -enable-kvm -hda /dev/sda -vnc 127_0_0_1:0 \ -cdrom /tmp/proxmox-ve_5.0-0d270679-2.iso -boot d &
* Replace _with . on the vnc address , Linkedin mangles the address .
Then in your PC use ssh port forwarding to access the VNC console:
$ ssh root@server -L 5900:localhost:5900 -f -N $ vncviewer localhost:5900
One thing to keep in mind is that the hardware is virtualized inside the installer that means that the network interface may have a different name when you boot into the real OS.
One way to fix this is by disabling predictable network device names by adding this to the kernel command line: “net.ifnames=0 biosdevname=0″
When we boot to the real OS the first network interface will always be eth0 .
By using KVM we can install almost any OS that will run under our temporary VM and this include almost all the popular OSs.
If you have any question, just send us an email!