Difference between revisions of "NetBSD"

From PrgmrWiki
m (Fix errors)
 
(45 intermediate revisions by 9 users not shown)
Line 1: Line 1:
== c33ris2's gentle guide to installing NetBSD in a prgmr DomU (January 2009) ==
+
=PV and HVM Virtualization =
Note: By June 2010 (or earlier) <b><i>some</i></b> of the dom0 hosts have packed the installer files into the /distros collection available to many recovery images. In these cases, the fetching activity is no longer required.
 
  
'''Note:''' for mantle/chessboard users: Mantle is currently running Xen 4.0.1. There is a [http://mail-index.netbsd.org/port-xen/2010/06/15/msg006105.html bug] in NetBSD that [http://lists.xensource.com/archives/html/xen-users/2010-08/msg00076.html breaks networking] when running in a Xen4 domU.
+
For the rest of this document, we assume that you have a VPS in PV (paravirtualized) mode. We have a page [[PV and HVM Virtualization]] describing the two virtualization types supported by Xen: PV and HVM. While it is possible to install NetBSD on an HVM VPS, at the present time we strongly recommend installing NetBSD on a PV VPS for performance reasons. Installing under HVM with a netboot installer is not yet documented.
  
'''Note:''' what Xen version is marshallIt also has the issue.
+
= Legacy Grub (pv-grub) or Grub2? =
 +
Legacy GRUB, also referred to as pv-grub, requires a separate boot partition formatted as ext2 that contains the grub config file and the kernel to be booted. While seeming more awkward, pv-grub is currently the mainstream approach.
  
'''Note:''' A -current NetBSD kernel is required to run under Xen 4.xWhen NetBSD 6 is released, these notes will go away-current is for EXPERTS ONLY.
+
Using GRUB 2 requires a separate step at the end to download the Xen kernel and configure a grub config file; this is more about the defaults in the install process scripting than what is or isn't simplerWith GRUB 2, the grub process started from the dom0 reads the NetBSD root filesystem to find the grub config file and then the kernelThe advantage is that no separate boot ext2 partition is needed.
  
===Getting Started===
+
== Issues with pv-grub ==
Installing NetBSD as DomU is easy, but not trivial.
 
  
Boot your preconfigured system, in order to discover, and note for later use, YOUR_IP, NETMASK, GATEWAY, and NAMESERVER as follows:
+
After installing via pv-grub, the system boots fine.  Running fsck_ext2fs under NetBSD shows some minor issues.  It is not clear how serious these are, and if they should be left or fixed.  One has to modify the boot partition to update to a new NetBSD kernel, typically writing it from NetBSD to do so, and the pv-grub started by Xen has to read the partition to read the kernel.  Advice for now is not to change anything with fsck.
<pre>
+
Run 'ifconfig eth0' and note your "inet addr" and "Mask" values.
+
\todo Resolve the fsck issues in terms of an ext2 specification and whether there are bugs in the mkfs used in the install vs. NetBSD's in-kernel implementation and/or NetBSD's fsck_ext2fs.
Run 'route' or 'ip route' and note the IP of the default gateway.
 
Run 'cat /etc/resolv.conf' and note the IP of the nameserver
 
</pre>
 
  
From [[Prgmr_menu|the control menu on your dom0 host]], destroy/shutdown the instance, and restart ("create/start") it, selecting the "rescue" option from the bootloader. Login as 'root'.
+
== Issues with grub2 ==
  
Your fixed disk, as known to the linux rescue image, is /dev/xvda. Later, when booted to the NetBSD installer, it is identified as /dev/xbd0.
+
This approach does not seem to work. grub2 complains about not being able to find the Xen ELF note.
  
For NetBSD, this disk must be partitioned, and the NetBSD installer files placed therein.
+
\todo Verify this, or add reports of this working.  With grub2, I got an error about a failure to find a xen ELF note.
<pre>fdisk /dev/xvda</pre>
 
  
From within fdisk,
+
= Installing =
<ul>
+
== Booting NetBSD installer (PV) ==
  <li>delete the existing partition, <b>*which will destroy your current OS image and data*</b></li>
 
  <li>create a new primary partition #1, with first cylinder at default=1 and last cylinder at +32M</li>
 
  <li>create a new primary partition #2, directly after partition 1 and last cylinder at end of disk</li>
 
  <li>change the ID of the new partition #2 to 'a9' (NetBSD)
 
  <li>write the new parition table to the disk.
 
  <li>exit fdisk
 
</ul>
 
  
Success to this point is evidenced by the prseence of /dev/xvda1 which must now be formatted, mounted, and a /boot directory created:
+
From the [[Management Console]], select the option labeled "install new OS image".  Select the version of NetBSD you wish to install from the list of operating systems.  Note that this doesn't install the OS; it installs a kernel that will boot into the NetBSD installer.  This also partitions your drive for use with pvgrub and adds a menu.lst.  Once the install is finished, go back to the main menu, and use the option "create/start" to boot. Once the system is booted to a pvgrub menu, select the entry containing the word "install".
<pre>mkfs.ext2 /dev/xvda1
 
mount -n /dev/xvda1 /mnt
 
mkdir /mnt/boot
 
mkdir /mnt/boot/grub
 
</pre>
 
  
If the file 'netbsd64.tar.gz' exists in /distros, skip over to [[#Unpacking the Installer]]
+
== Overall instructions ==
 +
Before you perform the installation, you should disable privacy extensions for autoconfigured IPv6 addresses.  Such temporary addresses are not usable for a Prgmr.com VPS. From the utility menu, select <code>Run /bin/sh</code>.  At the shell prompt, execute the following command: <code>sed -i 's/^slaac private/slaac hwaddr/' /etc/dhcpcd.conf</code>
  
'''Note:''' if you will be using a -current install, then don't bother with /distros
+
A tutorial for the netbsd installer is at http://netbsd.org/docs/guide/en/chap-exinst.html
  
Otherwise you'll have to proceed here with
+
When prompted, install to xbd0.
  
===Fetching the Installer===
+
=== Partitioning for pv-grub (for NetBSD &lt; 9.0) ===
 +
When prompted, select 'Use existing partition sizes'. Your root device should be on partition 'a'. Please refer to http://netbsd.org/docs/guide/en/chap-inst.html#chap-inst-install-partition for more information on partitioning
  
Substituting actual values observed (above) for  
+
When editing partition 'a', the following is known to work:
YOUR_IP, NETMASK, GATEWAY, and NAMESERVER ...
+
* Use 'FFSv2' for FStype
 +
* Set 'start' to e (for end of partition e)
 +
* Set 'end' to -1 (for full disk)
 +
* Set 'mount' to 'yes'
 +
* Set 'mount point' to '/'
 +
This partition scheme should work and was made for a 4GiB disk:
 
<pre>
 
<pre>
ifconfig eth0 up YOUR_IP/NETMASK
+
We now have your BSD disklabel partitions as:                               
route add default gw GATEWAY eth0
+
This is your last chance to change them.                                    
echo "nameserver NAMESERVER" >/etc/resolv.conf
+
                                                                             
</pre>
+
    Start  MB  End  MB  Size  MB FS type    Newfs Mount Mount point         
 
+
    --------- --------- --------- ---------- ----- ----- -----------          
wget and extract to /mnt/boot/ :
+
a:       34      4095      4061 FFSv2      Yes  Yes  /
 
+
  b:        0        0        0 unused
<pre>
+
c:         0      4095      4096 NetBSD partition
cd /mnt/boot
+
d:         0     4095      4096 Whole disk
wget ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-5.1/amd64/binary/kernel/netbsd-INSTALL_XEN3_DOMU.gz
+
e:         3        33        30 Linux Ext2
wget ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-5.1/amd64/binary/kernel/netbsd-XEN3_DOMU.gz
+
f:        0        0        0 unused
gunzip netbsd-INSTALL_XEN3_DOMU.gz
+
g: Show all unused partitions
gunzip netbsd-XEN3_DOMU.gz
+
h: Change input units (sectors/cylinders/MB)
</pre>
+
>x: Partition sizes ok
 
 
'''Note:''' if you will be using -current, you must get a current build from NetBSD's releng. (http://releng.netbsd.org). Check for a successful amd64 build in the log data, then determine the corresponding location in the binary snapshots.
 
 
 
===Configuring Boot Menu===
 
 
 
Create a file boot/grub/menu.lst with this content:
 
 
 
<pre>
 
timeout 5
 
 
 
title NetBSD run
 
         root (hd0,0)
 
         kernel --type=netbsd /boot/netbsd-XEN3_DOMU
 
 
 
title NetBSD install
 
        root (hd0,0)
 
        kernel --type=netbsd /boot/netbsd-INSTALL_XEN3_DOMU
 
 
</pre>
 
</pre>
  
<b>Skip to [[#Booting the Installer]]</b>
+
You may choose whatever options you want as long as the Linux Ext2 partition is preserved as-is. If the boot partition is formatted or removed, however, you will be unable to boot.
  
===Unpacking the Installer===
+
Note that in the above example, the boot partition (e) is actually in lower-numbered sectors, with the NetBSD root partition (a) later in the disk.  This does not bother NetBSD, and \todo perhaps is necessary for grub.   Also note that in addition to disklabel, there is an MBR partition table, with two "Linux" (sysid 131) partitions. The first is the boot partition, aliased by e above, and the second aliases the NetBSD a partition.
This section presumes the presence, in the rescue instance, of /distros/netbsd64.tar.gz
 
<br>Unpack this into the new boot menu, and shutdown.
 
  
<pre>tar zxf /distros/netbsd64.tar.gz -C /mnt/boot/
+
\todo Explain why the second, large, Linux partition isn't of type NetBSD.
shutdown -h now
 
</pre>
 
  
 +
=== Partitioning for pv-grub (for NetBSD 9.0 and above) ===
 +
NetBSD 9.0 adds a screen that lets you set just the partition sizes.  Ignore it, by selecting "x" to abort.  The subsequent screen will let you edit your partitions in a manner similar to what is done for NetBSD 8.1 and below.
  
===Booting the Installer===
+
NetBSD now shows partition sizes in sectors.  If you're more comfortable with megabytes, you can select that with the "change input units" option on the partitioning screens.  Note that the unit is called [https://en.wikipedia.org/wiki/Megabyte megabyte] in the NetBSD menus, though it is actually the [https://en.wikipedia.org/wiki/Mebibyte mebibyte].
  
Returning to [[Prgmr_menu|the control menu on your dom0 host]], change your bootloader selection to 'amd64' instead of 'i386'.  Destroy/shutdown your instance if it is running, and create/start it again, this time selecting first the "user bootloader configuration" from the options presented by the dom0, and after that select the installer from your new user bootloader. This should take you to the NetBSD  Installer, for which [http://netbsd.org/docs/guide/en/chap-exinst.html#exinst-starting  a tutorial exists at netbsd.org]
+
In NetBSD 9 and greater, the first EXT2 partition is partition c, and the second EXT2 partition is partition d.
 +
* Select partition d, and delete it.
 +
* Then select partition a. Values such as the filesystem type and mountpoint are already set.
 +
* Change the start to "c", I.E., the end of partition c.
 +
* Change the size to -1.
  
Install onto xbd0
+
=== Partitioning for grub2 ===
 +
Your root device should be on partition 'a'. To our best knowledge, you may install with whatever options you choose as long as the first partition has room for the netbsd kernel (approximately 8MiB) and the
 +
[[grub2#Compatible_file_systems|file system]] is compatible with grub2.<br> Please refer to http://netbsd.org/docs/guide/en/chap-inst.html#chap-inst-install-partition for more information on partitioning
  
When presented with the option, choose
+
Example of working partition scheme:
<br><b>b: Use existing partition sizes</b>
 
<br>The next screen should show the existing BSD-disklabel partitions, as follows for a 3G allocation.
 
 
<pre>
 
<pre>
 +
We now have your BSD-disklabel partitions as:
 +
This is your last chance to change them.
 +
 
     Start  MB  End  MB  Size  MB FS type    Newfs Mount Mount point
 
     Start  MB  End  MB  Size  MB FS type    Newfs Mount Mount point
 
     --------- --------- --------- ---------- ----- ----- -----------
 
     --------- --------- --------- ---------- ----- ----- -----------
  a:        0         0        0 unused
+
  a:        0     2815      2816 FFSv2      Yes  Yes  /
  b:         0        0        0 unused
+
  b:     2816      3071      256 swap
 
  c:        0      3071      3072 NetBSD partition
 
  c:        0      3071      3072 NetBSD partition
 
  d:        0      3071      3072 Whole disk
 
  d:        0      3071      3072 Whole disk
  e:        0        29        30 Linux Ext2
+
  e:        0        0        0 unused
f:        30    3071      3041 4.2BSD    Yes  Yes  /
 
g:        0        0        0 unused
 
 
</pre>
 
</pre>
  
<i>If you're new to NetBSD partitioning, which I am, which is why I'm writing this, refer to [http://netbsd.org/docs/guide/en/chap-inst.html#chap-inst-install-partition this NetBSD Guide section]</i>
+
== Continuing Install ==
 +
Only choices that need to be a particular value are called out here.
 +
=== NetBSD 6 ===
 +
* For "Bootblocks selection" , select "Use existing bootblocks"
 +
* "Install from" FTP or HTTP
 +
* Press enter to use the xennet0 device
 +
* Press enter for the "Network media type"
 +
* Select "yes" for DHCP configuration
 +
* Select "no" for IPv6 autoconfiguration
  
In order to install NetBSD properly, lets move the root partition to label:a and create swap.  Select a:, set the partition type to "FFSv2" instead of "unused", and use 'e' as the start of your partition.  Leave space at the end for swap.  I used 128 MB, but you may want more depending on your application and VM allocation.  Make sure to set Newfs, Mount, and Mount point correctly.  Select b: and create swap until the end of the disk (-1).
+
=== NetBSD 7 and NetBSD 8 ===
 +
* For "Bootblocks selection" , select "Use existing bootblocks"
 +
* "Install from" FTP
 +
* Select "Configure network"
 +
* Press enter to use the xennet0 device
 +
* Press enter for the "Network media type"
 +
* Select "yes" for auto configuration
 +
* Select "Get distribution"
  
You can also set the mount point for e:.
+
Be sure to add at least one user account. On NetBSD 7, root login is disabled by default even if you set the root password. If you wish to log in as root you must specifically enable root login after you've logged in with the new user.
  
Finally, remove (the now obsolete) label:f by setting it to unused.
 
  
Here is an example disklabel setup for a 3072M disk
+
== Fixing IPv6 ==
with a 30M boot partition:
+
You also need to disable SLAAC privacy addresses for the target system.  From the utility menu, select "Run /bin/sh", and run the following sequence of commands at the shell prompt:
 
<pre>
 
<pre>
    Start  MB  End  MB  Size  MB FS type    Newfs Mount Mount point
+
mount /dev/xbd0a /mnt
    --------- --------- --------- ---------- ----- ----- -----------
+
sed -i 's/^slaac private/slaac hwaddr/' /mnt/etc/dhcpcd.conf
a:        30      2942      2912 FFSv2      Yes  Yes  /
+
umount /mnt
b:      2943      3071      128 swap
 
c:        0      3071      3072 NetBSD partition
 
d:        0      3071      3072 Whole disk
 
e:        0        29        30 Linux Ext2      Yes  /boot
 
f:        0        0        0 unused
 
 
</pre>
 
</pre>
  
 +
== Finishing install for grub2 bootloader only ==
 +
After finishing the install, you will need to manually add the Xen kernel. Go to the "Utility Menu" and Enter a shell. Perform the following:
 +
<pre>
 +
mount /dev/xbd0a /mnt
 +
chroot /mnt
 +
</pre>
  
Select "accept these sizes" and continue with the installation.
+
<pre>
 
+
#NetBSD 7 (amd64)
When prompted by the installer, select "use existing bootblocks".
+
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-7.0/amd64/binary/kernel/netbsd-XEN3_DOMU.gz
 
+
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-7.0/amd64/binary/kernel/MD5
Install by FTP
+
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-7.0/amd64/binary/kernel/SHA512
 
+
</pre>
When prompted by the installer, use the xennet0 device and when it asks for "Network media type" just press enter.
+
<pre>
 
+
#NetBSD 7 (i386)
Try to use DHCP. If it doesn't work,
+
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-7.0/i386/binary/kernel/netbsd-XEN3PAE_DOMU.gz
Use the actual values observed (above) for
+
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-7.0/i386/binary/kernel/MD5
<br>YOUR_IP, NETMASK, GATEWAY, and NAMESERVER
+
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-7.0/i386/binary/kernel/SHA512
<br>when prompted by the installer
+
</pre>
 
+
<pre>
 +
#NetBSD 8 (amd64)
 +
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-8.0/amd64/binary/kernel/netbsd-XEN3_DOMU.gz
 +
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-8.0/amd64/binary/kernel/MD5
 +
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-8.0/amd64/binary/kernel/SHA512
 +
</pre>
 +
<pre>
 +
#NetBSD 8 (i386)
 +
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-8.0/i386/binary/kernel/netbsd-XEN3PAE_DOMU.gz
 +
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-8.0/i386/binary/kernel/MD5
 +
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-8.0/i386/binary/kernel/SHA512
 +
</pre>
 +
<pre>
 +
#Do not use if this fails
 +
# Replace XEN3_DOMU.gz with XEN3PAE_DOMU.gz if on i386
 +
grep "$(/usr/bin/cksum -a md5 netbsd-XEN3_DOMU.gz)" MD5
 +
#Do not use if this fails
 +
# Replace XEN3_DOMU.gz with XEN3PAE_DOMU.gz if on i386.
 +
grep "$(/usr/bin/cksum -a sha512 netbsd-XEN3_DOMU.gz)" SHA512
 +
mkdir /grub
 +
echo "set default=0
 +
set timeout=5
 +
menuentry 'NetBSD, with kernel netbsd-XEN3_DOMU.gz ' {
 +
        linux /netbsd-XEN3_DOMU.gz
 +
}" > /grub/grub.cfg
 +
rm MD5
 +
rm SHA512
 +
exit
 +
umount /mnt
 +
exit
 +
</pre>
  
 +
Select "Back to main menu" and then "Halt the system". Wait for the VM to reboot.<br> Type 'ctrl-]' to exit back to the management console. From the management console, select
 
<pre>
 
<pre>
The installation of NetBSD is now complete. The system should boot
+
    4. force power off (destroy/hard shutdown)
from hard disk.  Follow the instructions in the INSTALL document about final
 
configuration of your system.  The afterboot(8) manpage is another
 
recommended reading; it contains a list of things to be checked after the
 
first complete boot.
 
 
 
At a minimum, you should edit /etc/rc.conf to match your needs.  See
 
/etc/defaults/rc.conf for the default values.
 
 
</pre>
 
</pre>
 
+
Select
Reboot.
 
 
 
===Mount boot partition in NetBSD domU===
 
Log in as root.
 
 
<pre>
 
<pre>
# mkdir /extboot
+
set bootloader, rescue mode, or netboot installer
# vi /etc/fstab
 
 
</pre>
 
</pre>
find the line in fstab that contains /dev/xbd0e and make it look like this:
+
and select "GRUB2" as the bootloader. Go back to the main menu and select
 
<pre>
 
<pre>
/dev/xbd0e              /extboot        ext2fs    rw              0 0
+
    2. create/start, opens OOB console (try this if the machine is not running)
 
</pre>
 
</pre>
 +
to start your VM.
  
Now it will be readable:
+
= Rescuing NetBSD install =
  
<pre>
+
For the legacy management console, the shell available from the NetBSD installer from the initial pv-grub boot menu may be used as a minimal rescue image, if the boot partition is intact and the grub config file is able to point to that install kernel.
# mount /extboot
+
 
# cd /extboot/boot/
+
If you are on the new management console, there's an additional option for rescuing that will work even if you're using GRUB2, and should work even if you have broken your boot partition.  Select "set bootloader, rescue mode, or netboot installer".  From the "BSD installers" menu, select the option corresponding to your version of NetBSD. You can then boot into that installer and use the shell for rescue purposes.
# ls
 
grub                      netbsd-INSTALL_XEN3_DOMU netbsd-XEN3_DOMU
 
</pre>
 
  
 +
= Loadable kernel modules prior to NetBSD 8.0 =
 +
For NetBSD 7.x and older, loadable kernel modules for xen needed to be built with -DXEN, and the default build did not do this. See https://mail-index.netbsd.org/port-xen/2013/01/20/msg007876.html. Among other things, this renders pf firewalling unusable under the default NetBSD kernel, as loading the pf module (modload /usr/lkm/pf.o) does not work. Building a new kernel with pf built-in should work, see https://www.netbsd.org/docs/network/pf.html  (Alternatively, one can build modules with -DXEN, but almost certainly one should update to 8.1 instead.)
  
{{u}} {{distros}}
+
However, for NetBSD 8.0 and later, loadable kernel modules no longer have a notion of being for Xen or not for Xen, and do work under Xen, so the above note no longer applies.

Latest revision as of 22:27, 19 February 2020

PV and HVM Virtualization

For the rest of this document, we assume that you have a VPS in PV (paravirtualized) mode. We have a page PV and HVM Virtualization describing the two virtualization types supported by Xen: PV and HVM. While it is possible to install NetBSD on an HVM VPS, at the present time we strongly recommend installing NetBSD on a PV VPS for performance reasons. Installing under HVM with a netboot installer is not yet documented.

Legacy Grub (pv-grub) or Grub2?

Legacy GRUB, also referred to as pv-grub, requires a separate boot partition formatted as ext2 that contains the grub config file and the kernel to be booted. While seeming more awkward, pv-grub is currently the mainstream approach.

Using GRUB 2 requires a separate step at the end to download the Xen kernel and configure a grub config file; this is more about the defaults in the install process scripting than what is or isn't simpler. With GRUB 2, the grub process started from the dom0 reads the NetBSD root filesystem to find the grub config file and then the kernel. The advantage is that no separate boot ext2 partition is needed.

Issues with pv-grub

After installing via pv-grub, the system boots fine. Running fsck_ext2fs under NetBSD shows some minor issues. It is not clear how serious these are, and if they should be left or fixed. One has to modify the boot partition to update to a new NetBSD kernel, typically writing it from NetBSD to do so, and the pv-grub started by Xen has to read the partition to read the kernel. Advice for now is not to change anything with fsck.

\todo Resolve the fsck issues in terms of an ext2 specification and whether there are bugs in the mkfs used in the install vs. NetBSD's in-kernel implementation and/or NetBSD's fsck_ext2fs.

Issues with grub2

This approach does not seem to work. grub2 complains about not being able to find the Xen ELF note.

\todo Verify this, or add reports of this working. With grub2, I got an error about a failure to find a xen ELF note.

Installing

Booting NetBSD installer (PV)

From the Management Console, select the option labeled "install new OS image". Select the version of NetBSD you wish to install from the list of operating systems. Note that this doesn't install the OS; it installs a kernel that will boot into the NetBSD installer. This also partitions your drive for use with pvgrub and adds a menu.lst. Once the install is finished, go back to the main menu, and use the option "create/start" to boot. Once the system is booted to a pvgrub menu, select the entry containing the word "install".

Overall instructions

Before you perform the installation, you should disable privacy extensions for autoconfigured IPv6 addresses. Such temporary addresses are not usable for a Prgmr.com VPS. From the utility menu, select Run /bin/sh. At the shell prompt, execute the following command: sed -i 's/^slaac private/slaac hwaddr/' /etc/dhcpcd.conf

A tutorial for the netbsd installer is at http://netbsd.org/docs/guide/en/chap-exinst.html

When prompted, install to xbd0.

Partitioning for pv-grub (for NetBSD < 9.0)

When prompted, select 'Use existing partition sizes'. Your root device should be on partition 'a'. Please refer to http://netbsd.org/docs/guide/en/chap-inst.html#chap-inst-install-partition for more information on partitioning

When editing partition 'a', the following is known to work:

  • Use 'FFSv2' for FStype
  • Set 'start' to e (for end of partition e)
  • Set 'end' to -1 (for full disk)
  • Set 'mount' to 'yes'
  • Set 'mount point' to '/'

This partition scheme should work and was made for a 4GiB disk:

 We now have your BSD disklabel partitions as:                                 
 This is your last chance to change them.                                      
                                                                               
    Start  MB   End  MB  Size  MB FS type    Newfs Mount Mount point           
    --------- --------- --------- ---------- ----- ----- -----------           
 a:        34      4095      4061 FFSv2      Yes   Yes   /
 b:         0         0         0 unused
 c:         0      4095      4096 NetBSD partition
 d:         0      4095      4096 Whole disk
 e:         3        33        30 Linux Ext2
 f:         0         0         0 unused
 g: Show all unused partitions
 h: Change input units (sectors/cylinders/MB)
>x: Partition sizes ok

You may choose whatever options you want as long as the Linux Ext2 partition is preserved as-is. If the boot partition is formatted or removed, however, you will be unable to boot.

Note that in the above example, the boot partition (e) is actually in lower-numbered sectors, with the NetBSD root partition (a) later in the disk. This does not bother NetBSD, and \todo perhaps is necessary for grub. Also note that in addition to disklabel, there is an MBR partition table, with two "Linux" (sysid 131) partitions. The first is the boot partition, aliased by e above, and the second aliases the NetBSD a partition.

\todo Explain why the second, large, Linux partition isn't of type NetBSD.

Partitioning for pv-grub (for NetBSD 9.0 and above)

NetBSD 9.0 adds a screen that lets you set just the partition sizes. Ignore it, by selecting "x" to abort. The subsequent screen will let you edit your partitions in a manner similar to what is done for NetBSD 8.1 and below.

NetBSD now shows partition sizes in sectors. If you're more comfortable with megabytes, you can select that with the "change input units" option on the partitioning screens. Note that the unit is called megabyte in the NetBSD menus, though it is actually the mebibyte.

In NetBSD 9 and greater, the first EXT2 partition is partition c, and the second EXT2 partition is partition d.

  • Select partition d, and delete it.
  • Then select partition a. Values such as the filesystem type and mountpoint are already set.
  • Change the start to "c", I.E., the end of partition c.
  • Change the size to -1.

Partitioning for grub2

Your root device should be on partition 'a'. To our best knowledge, you may install with whatever options you choose as long as the first partition has room for the netbsd kernel (approximately 8MiB) and the file system is compatible with grub2.
Please refer to http://netbsd.org/docs/guide/en/chap-inst.html#chap-inst-install-partition for more information on partitioning

Example of working partition scheme:

 We now have your BSD-disklabel partitions as:
 This is your last chance to change them.
 
    Start  MB   End  MB  Size  MB FS type    Newfs Mount Mount point
    --------- --------- --------- ---------- ----- ----- -----------
 a:         0      2815      2816 FFSv2      Yes   Yes   /
 b:      2816      3071       256 swap
 c:         0      3071      3072 NetBSD partition
 d:         0      3071      3072 Whole disk
 e:         0         0         0 unused

Continuing Install

Only choices that need to be a particular value are called out here.

NetBSD 6

  • For "Bootblocks selection" , select "Use existing bootblocks"
  • "Install from" FTP or HTTP
  • Press enter to use the xennet0 device
  • Press enter for the "Network media type"
  • Select "yes" for DHCP configuration
  • Select "no" for IPv6 autoconfiguration

NetBSD 7 and NetBSD 8

  • For "Bootblocks selection" , select "Use existing bootblocks"
  • "Install from" FTP
  • Select "Configure network"
  • Press enter to use the xennet0 device
  • Press enter for the "Network media type"
  • Select "yes" for auto configuration
  • Select "Get distribution"

Be sure to add at least one user account. On NetBSD 7, root login is disabled by default even if you set the root password. If you wish to log in as root you must specifically enable root login after you've logged in with the new user.


Fixing IPv6

You also need to disable SLAAC privacy addresses for the target system. From the utility menu, select "Run /bin/sh", and run the following sequence of commands at the shell prompt:

mount /dev/xbd0a /mnt
sed -i 's/^slaac private/slaac hwaddr/' /mnt/etc/dhcpcd.conf
umount /mnt

Finishing install for grub2 bootloader only

After finishing the install, you will need to manually add the Xen kernel. Go to the "Utility Menu" and Enter a shell. Perform the following:

mount /dev/xbd0a /mnt
chroot /mnt
#NetBSD 7 (amd64)
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-7.0/amd64/binary/kernel/netbsd-XEN3_DOMU.gz
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-7.0/amd64/binary/kernel/MD5
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-7.0/amd64/binary/kernel/SHA512
#NetBSD 7 (i386)
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-7.0/i386/binary/kernel/netbsd-XEN3PAE_DOMU.gz
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-7.0/i386/binary/kernel/MD5
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-7.0/i386/binary/kernel/SHA512
#NetBSD 8 (amd64)
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-8.0/amd64/binary/kernel/netbsd-XEN3_DOMU.gz
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-8.0/amd64/binary/kernel/MD5
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-8.0/amd64/binary/kernel/SHA512
#NetBSD 8 (i386)
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-8.0/i386/binary/kernel/netbsd-XEN3PAE_DOMU.gz
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-8.0/i386/binary/kernel/MD5
ftp ftp://ftp.netbsd.org/pub/NetBSD/NetBSD-8.0/i386/binary/kernel/SHA512
#Do not use if this fails
# Replace XEN3_DOMU.gz with XEN3PAE_DOMU.gz if on i386
grep "$(/usr/bin/cksum -a md5 netbsd-XEN3_DOMU.gz)" MD5
#Do not use if this fails
# Replace XEN3_DOMU.gz with XEN3PAE_DOMU.gz if on i386.
grep "$(/usr/bin/cksum -a sha512 netbsd-XEN3_DOMU.gz)" SHA512
mkdir /grub
echo "set default=0
set timeout=5
menuentry 'NetBSD, with kernel netbsd-XEN3_DOMU.gz ' {
        linux /netbsd-XEN3_DOMU.gz
}" > /grub/grub.cfg
rm MD5
rm SHA512
exit
umount /mnt
exit

Select "Back to main menu" and then "Halt the system". Wait for the VM to reboot.
Type 'ctrl-]' to exit back to the management console. From the management console, select

    4. force power off (destroy/hard shutdown)

Select

set bootloader, rescue mode, or netboot installer

and select "GRUB2" as the bootloader. Go back to the main menu and select

    2. create/start, opens OOB console (try this if the machine is not running)

to start your VM.

Rescuing NetBSD install

For the legacy management console, the shell available from the NetBSD installer from the initial pv-grub boot menu may be used as a minimal rescue image, if the boot partition is intact and the grub config file is able to point to that install kernel.

If you are on the new management console, there's an additional option for rescuing that will work even if you're using GRUB2, and should work even if you have broken your boot partition. Select "set bootloader, rescue mode, or netboot installer". From the "BSD installers" menu, select the option corresponding to your version of NetBSD. You can then boot into that installer and use the shell for rescue purposes.

Loadable kernel modules prior to NetBSD 8.0

For NetBSD 7.x and older, loadable kernel modules for xen needed to be built with -DXEN, and the default build did not do this. See https://mail-index.netbsd.org/port-xen/2013/01/20/msg007876.html. Among other things, this renders pf firewalling unusable under the default NetBSD kernel, as loading the pf module (modload /usr/lkm/pf.o) does not work. Building a new kernel with pf built-in should work, see https://www.netbsd.org/docs/network/pf.html (Alternatively, one can build modules with -DXEN, but almost certainly one should update to 8.1 instead.)

However, for NetBSD 8.0 and later, loadable kernel modules no longer have a notion of being for Xen or not for Xen, and do work under Xen, so the above note no longer applies.