PV and HVM Virtualization

From PrgmrWiki
Revision as of 18:19, 11 May 2018 by Cmb (talk | contribs)

The Poor Man Method of PV to HVM Conversion

A number of customers have expressed interest in converting Xen instances from PV to HVM. That process requires both changes to the Xen configuration for the VPS on our server and changes to the operating system that is running inside the instance. We do have some scripts for making the required changes to the OS, but they won't work with all distributions. In fact, the only distributions that they are guaranteed to support are CentOS 6 and CentOS 7. Even for those, the scripts do not work in many situations. For example, having more than one partition will cause the scripts to fail. Writing a capable and universal script for making bootloader changes turns out to be a difficult problem. However, we recently came up with a new strategy for PV to HVM conversions which requires minimal changes to the operating system. For many distributions, it requires no change at all. For lack of a better term, we have been referring to this as the "poor man conversion" method in internal discussion. If we did a PV to HVM conversion for you, and we told you that we used the poor man method, this wiki page is for you. Here is how it works.

After performing the necessary changes and migration for Xen on our end, we set your new HVM VPS to boot using a CD image. If you used pv-grub for your PV instance, that CD image contains the Grub Legacy bootloader, I.E., version 0.97. If you used grub2, it contains GRUB 2. The bootloader chain-loads the configuration file on your disk, booting what used to be a PV instance in HVM mode. This takes advantage of the fact that for a PV instance, the bootloader configuration is always stored in partition 1. We always know where to find it, so we can chainload it from the bootloader on the CD.

One problem with this approach is that the device used for a PV console differs from the device used for the HVM console. The PV console device is hvc0, but an HVM VPS uses a serial console: ttyS0. While we are converting a VPS, one of our scripts edits the bootloader configuration in-place, replacing occurrences of hvc0 with ttyS0. This should always work, but there are likely a few outliers where it might not. There is an extremely high probability that after this edit, the kernel boot messages will appear on the correct console, ttyS0. However, the login prompt might still go to the PV console, hvc0. We've decided that for people using this conversion strategy, we will expose both the HVM and the PV console. This only works if your kernel provides the hvc0 device when it is booted under HVM, but some kernels do not provide it. See the distribution-specific notes for more details. When you use option 1 from the main menu of the management console to connect to the out-of-band console of the VPS, you'll get a new menu that will allow you to choose between the PV and HVM consoles.

Extended Boot Options

In order to support this conversion method, we have added a menu to the "Set Bootloader or Rescue Mode" menu of the management console. It is named "External Bootloaders", and it contains two options: one to set the instance to boot from a GRUB Legacy ISO, and one to set the instance to boot from a GRUB 2 ISO. If your instance was converted with the poor man method, you should use these instead of "boot from disk", until you are sure that your bootloader has been properly installed and configured. These options are available to all guests with HVM virtualization, not just those that received a PV to HVM conversion.

Special Configuration Changes

For most distributions, this solution works out of the box, requiring no configuration changes by the customer. However, in some cases, changes are required. Through testing and experimentation, we have determined the necessary action for each of our supported distributions. If your distribution is not mentioned in the notes below, and it is one of the distributions for which we provide images, you can safely assume that it works out of the box. However, if you are using GRUB 2, please see #Notes Concerning GRUB 2 below. As always, if you have any issues, please let us know by writing to support@prgmr.com.

CentOS 6 should work out of the box with no changes. If it does not, 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.

Debian 7.0 does not provide a PV console device. Also, the console is listed in /etc/inittab. Edit your /etc/inittab, replacing references to hvc0 with ttyS0.

For Debian 8.0 Jessie with sysvinit and Debian 9.0 Stretch with sysvinit, edit inittab and replace occurrences of hvc0 with ttyS0.

Ubuntu 14.04 will print kernel messages to the HVM console, but the login prompt will be displayed on the PV console. Copy the file /etc/init/hvc0.conf to /etc/init/ttyS0.conf, and replace occurrences of hvc0 with ttyS0 in /etc/init/hvc0.conf. Then execute:

sudo service start ttyS0

Notes Concerning 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

Afterword

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