PV and HVM Virtualization

From PrgmrWiki

Introduction

Over the years, in Linux hardware virtualization (HVM) support for Xen has become much better than Paravirtualization (PV) support. Other operating systems like NetBSD or some unikernals only work well under PV mode. For new systems, use HVM if your operating system supports it.

Our legacy VPSes were all provisioned using Xen PV mode, so we've added a method for converting existing Linux VPSes from PV to HVM mode. You may request this by contacting support.

Below is a description of the differences between PV and HVM and the conversion process from PV to HVM.

Differences between PV and HVM Virtualization

Booting

PV Mode

PV systems all boot using a version of either legacy GRUB or GRUB2 provided by prgmr.com.

HVM Mode

HVM systems have an emulated BIOS and can boot from either the VPS disk or a CDROM image provided by prgmr.com. To change this, go to the "set bootloader or rescue mode" option of the Management Console.

Serial Console

PV Mode

Paravirtualized (PV) mode systems use a paravirtualized serial console named hvc0. Because there is no virtual display by default, PV systems will default to using hvc0 if no "console=hvc0" is defined on the kernel command line.

HVM Mode

HVM systems have both an emulated hardware serial port and a paravirtualized serial port. Under Linux the emulated hardware serial port is named ttyS0 and the paravirtualized serial port is named hvc0. The bootloader only can use the emulated serial port. For the operating system, HVM systems must explicitly be told to use a serial port or there will be no output after the operating system is loaded. Linux has drivers for both ttyS0 and hvc0, however we will only expose hvc0 if needed. New installs always use ttyS0. For HVM systems you may need to press enter to get output from Linux, which is not necessary with PV mode systems.

Converting from PV to HVM

Typically we will convert your GRUB config file and fix the login shell for sysvinit, systemd, and upstart. Custom installs, such as those with an encrypted disk or a root other than /dev/xvda1, will only have their GRUB config file updated, and you will need to perform a manual conversion to avoid having to switch from the HVM to PV console during boot.

If GRUB isn't already installed, it is installed for CentOS 6 and CentOS 7 only. Otherwise we set your VPS to boot from CDROM using the version of GRUB the VPS was originally using. The bootloader uses the emulated hardware serial port ttyS0. Like before, this bootloader chain-loads the GRUB configuration file from the VPS disk. If and when a bootloader is installed directly to the VPS disk, you will need to change your boot configuration from the "set bootloader or rescue mode" option of the Management Console.

During the conversion we will edit the primary GRUB configuration so that the kernel boot messages to go to ttyS0. But the login prompt will still go to hvc0 if you are using an init system not explicitly handled. Also for GRUB2, which has /etc/default/grub, with a custom install running update-grub will overwrite changes to /boot/grub(2)/grub.cfg to either not include a "console=" option or to set the console option back to "console=hvc0".

If your VPS was set to use a GRUB CDROM during the conversion process, when you use the out of band console from Management Console, you'll get a different menu with options for both the PV (hvc0) and HVM (ttyS0) consoles until you do a new clean install of a preconfigured operating system.

Manual Conversion

As mentioned earlier, if you have a custom install you may need to manually convert parts of your system to avoid having to switch from the HVM console to the PV console during the boot process. Some files to look at are:

  • /etc/inittab - needs hvc0 changed to ttyS0
  • /etc/default/grub - see Converting when using GRUB 2
  • /etc/init/hvc0.conf - needs to be renamed to /etc/init/ttyS0.conf and have the contents updated from hvc0 to ttyS0

Converting when using Legacy Grub

If there are issues, make sure that your bootloader configuration, /boot/grub/menu.lst, contains no splashimage lines and that hvc0 is replaced with ttyS0 in the boot entries.

Converting when using GRUB 2

If you are using GRUB 2, or you wish to use GRUB 2 in the future, it is a good idea to make sure that your configuration files look correct. The file /etc/default/grub is the one that should be modified. Here is a sample /etc/default/grub file. Take note of the lines starting with GRUB_SERIAL_COMMAND and GRUB_TERMINAL. These insure that GRUB 2 will use the serial console instead of the PV console.

GRUB_TIMEOUT=5
# GRUB_DESTRIBUTOR= # The correct value is OS-dependent
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL="serial console"
GRUB_CMDLINE_LINUX="console=ttyS0 rootflags=barrier=0"
GRUB_DISABLE_LINUX_UUID="true"
export LINUX_ROOT_DEVICE="LABEL=PRGMRDISK1"
GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200"

You should rebuild your GRUB configuration file grub.cfg using either grub2-mkconfig or grub-mkconfig. The name of the tool and the pathname are OS-dependent. On RedHat based systems, use:

grub2-mkconfig -o /boot/grub2/grub.cfg

On Debian derivatives and most of the other distributions, use:

grub-mkconfig -o /boot/grub/grub.cfg

Getting Help

If you have any problems, questions, or feedback, please write to us at support.