Re: Converting PV to HVM - boot methods

Stephen Borrill <[email protected]> Fri, 25 Apr 2025 09:13:51 +0100 (BST)
Newsgroups gmane.os.netbsd.ports.i386
Message-ID <Pine.NEB.4.64.2504250906060.1680@ugly>
On Thu, 24 Apr 2025, Brad Spencer wrote:
> Stephen Borrill <[email protected]> writes:
>
>> I've set this to port-i386 rather than port-xen as it's more about the x86
>> boot process rather than Xen.
>>
>> I have a (large) number of PV Xen VMs. These were created from a disk
>> image built with makefs that the sets were extracted into. This means
>> there is no partitioning except for disklabel and the root partition
>> begins at sector 0:
>>
>> 16 partitions:
>> #        size    offset     fstype [fsize bsize cpg/sgs]
>>   a:  18874368         0     4.2BSD   2048 16384     0  # (Cyl.      0 -  18724*)
>>   b:   2097152  18874368       swap                     # (Cyl.  18724*-  20805*)
>>   c:  20971520         0     unused      0     0        # (Cyl.      0 -  20805*)
>>   d:  20971520         0     unused      0     0        # (Cyl.      0 -  20805*)
>>
>> Now that XenServer and XCP-ng no longer support PV booting (and PV-on-PVH
>> doesn't work either), I now need to convert them to HVM. As there's no
>> free sectors at the start, I cannot create a partition table, etc.
>>
>> My current best fix is to add a 2nd tiny (16MB) virtual disk with
>> GPT partitioning and a single MSDOS EFI partition containing:
>>
>> /efi/boot/bootx64.efi
>> /efi/NetBSD/boot.cfg
>>
>> The boot.cfg is altered so that instead of boot netbsd, the lines say boot hd1a:netbsd.
>>
>> Full set of steps (assuming xbd1 for new disk and no existing wedges):
>>
>
> [snip]
>
> I have done this too, but with a MBR style second disk.  All it contains
> is the boot blocks and a boot.cfg.  If you use the NAME=ROOT.foo stuff
> in /etc/fstab you won't have to do any edits.  If xenbus is available to
> the HVM you get you might be able to get pvhvm going which will let you
> use a fully emulated device for the main boot disk, and then xbd devices
> for other disks and maybe the network.  Done that too...

By using UEFI, you simply need to add the second boot disk for it to boot. 
You don't need to alter boot order as it'll get automatically picked up as 
bootable by UEFI. Once booted, the original disk remains as xbd0 (sorry, 
should have made it clear I was using netbsd-10), so no configuration 
changes are necessary and no need to use NAME= syntax in fstab (unless you 
want to).

It's easy enough to switch a XenServer PV VM to UEFI HVM:
vmuuid=`xe vm-list name-label="My VM" --minimal`
xe vm-param-set uuid=$vmuuid domain-type=hvm
xe vm-param-set uuid=$vmuuid platform:viridian=false
xe vm-param-set uuid=$vmuuid HVM-boot-params:firmware=uefi
xe vm-param-set uuid=$vmuuid platform:device-model=qemu-upstream-uefi
vbduuid=`xe vbd-list vm-uuid=vmuuid type=CD --minimal`
xe vbd-param-set uuid=$vbduuid userdevice=2

-- 
Stephen