Preliminary Note

The XEN host system here is assumed to be a GNU/Linux, to be able to use the dd seek option.

Requirements

Fetching the to-be-shared material,

mkdir -p /data/kernels/netbsd7/
cd /data/kernels/netbsd7/

wget http://ftp.fr.netbsd.org/pub/NetBSD/iso/7.1.2/NetBSD-7.1.2-amd64.iso
wget http://ftp.fr.netbsd.org/pub/NetBSD/iso/7.1.2/SHA512

grep amd64.iso SHA512
sha512sum *amd64.iso

wget http://ftp.fr.netbsd.org/pub/NetBSD/NetBSD-7.1.2/amd64/binary/kernel/netbsd-INSTALL_XEN3_DOMU.gz
wget http://ftp.fr.netbsd.org/pub/NetBSD/NetBSD-7.1.2/amd64/binary/kernel/netbsd-XEN3_DOMU.gz
wget http://ftp.fr.netbsd.org/pub/NetBSD/NetBSD-7.1.2/amd64/binary/kernel/SHA512

grep netbsd-INSTALL_XEN3_DOMU.gz SHA512.1
sha512sum netbsd-INSTALL_XEN3_DOMU.gz

The full disk flavor

guest=GUESTNAME
mkdir -p /data/guests/$guest
cd /data/guests/$guest
dd if=/dev/zero of=$guest.disk bs=1024k count=1 seek=4096
#10GB -- seek=10240
grep ^proc /proc/cpuinfo 
cat > $guest <<-EOF
kernel = "/data/kernels/netbsd7/netbsd-INSTALL_XEN3_DOMU.gz"
#kernel = "/data/kernels/netbsd7/netbsd-XEN3_DOMU.gz"
#root = "xbd0a"
memory = 256
name = "$guest"
vcpus = 2
disk = [ 'tap:aio:/data/guests/$guest/$guest.disk,xvda,w',
         'tap:aio:/data/kernels/netbsd7/NetBSD-7.1.2-amd64.iso,xvdb,r' ]
vif = [ 'vifname=$guest.0, bridge=xenbr0' ]
EOF

Launch the installation,

cd /data/guests/$guest/
xl create $guest -c

then install NetBSD on xbd0 using cdrom at xbd1a.

When finished,

x: Exit Install System

halt -p

Then switch to the ending production kernel,

#kernel = "/data/kernels/netbsd7/netbsd-INSTALL_XEN3_DOMU.gz"
kernel = "/data/kernels/netbsd7/netbsd-XEN3_DOMU.gz"
root = "xbd0a"

Then run the guest normally and tune some shit,

xl create $guest -c

cp -pi /etc/rc.conf /etc/rc.conf.dist
vi /etc/rc.conf

wscons=no
no_swap=yes
savecore=no
sshd=yes

cp -i /etc/ttys /etc/ttys.dist
vi /etc/ttys

console "/usr/libexec/getty Pc"         vt100   on secure
ttyE1   "/usr/libexec/getty Pc"         wsvt25  off secure
ttyE2   "/usr/libexec/getty Pc"         wsvt25  off secure
ttyE3   "/usr/libexec/getty Pc"         wsvt25  off secure

Ref. https://wiki.xenproject.org/wiki/How_to_install_a_NetBSD_PV_domU_on_a_Debian_Squeeze_host_(Xen_4.0.1)

Rescuing a netbsd guest

from another guest, say rescue,

disk = [ 'tap:aio:/data/guests/rescue/rescue.disk,xvda,w',
     'tap:aio:/data/guests/sec/sec.disk,xvdb,w',
         'tap:aio:/data/guests/netbsd71/NetBSD-7.1.2-amd64.iso,xvdc,r' ]

fsck /dev/rxbd1a 
mkdir /lala
mount /dev/xbd1a /lala

NetBSD/XEN on EXT2FS vdisk image (READ-WRITE on the xen host)

Same as for the full disk flavor but,

mv $guest.disk $guest.ext2

mkfs.ext2 $guest.ext2

vi $guest

disk = [ 'tap:aio:/data/guests/$guest/$guest.ext2,xvda,w',

cd /data/guests/$guest/
xl create $guest -c

choose language
x

dmesg | grep ^xbd
disklabel xbd0
mount -t ext2fs /dev/xbd0d /mnt
mkdir /cdrom
mount_cd9660 /dev/xbd1a /cdrom
cd /cdrom/amd64/binary/sets
for set in base comp etc man misc tests text; do
    echo -n $set...
    tar xzphfe $set.tgz -C /mnt && echo done
done; unset set

chroot /mnt
cd dev/
./MAKEDEV all

cd /etc
#ln -sf ../usr/share/zoneinfo/Europe/Paris localtime
ln -sf ../usr/share/zoneinfo/Europe/Moscow localtime
vi rc.conf

rc_configured=yes

#xen
wscons=no
no_swap=yes
savecore=no

cat /etc/ttys #fine already

vi /etc/fstab

/dev/xbd0d      /       ext2fs  rw      1 1

^D
umount /mnt
cd
umount /cdrom
sync
halt -p

change the conf and run the guest in normal operation mode,

vi $guest

kernel = "/data/kernels/netbsd7/netbsd-XEN3_DOMU.gz"
root = "xbd0d"

xl create $guest -c

check after boot,

dmesg | grep ^xbd
mount

NetBSD/XEN on UFS/FFS vdisk image (READ-ONLY by default on the xen host)

Warning: this is READ-ONLY by default on Ubuntu and Slackware as the CONFIG_UFS_FS_WRITE kernel feature is not compiled in.

Same as for the EXT2FS flavor but,

mv $guest.disk $guest.ffs

vi $guest

disk = [ 'tap:aio:/data/guests/$guest/$guest.ffs,xvda,w',

...

dmesg | grep ^xbd
disklabel xbd0
newfs /dev/rxbd0a
mount /dev/xbd0a /mnt

...

vi /etc/fstab

/dev/xbd0a      /       ffs  rw      1 1

change the conf and run the guest in normal operation mode,

root = "xbd0a"

and to mount READ-ONLY that UFS/FFS from a GNU/Linux XEN host system,

xl shu $guest
xl li | grep $guest
mkdir lala
mount -t ufs -o loop,ro,ufstype=44bsd $guest.ffs lala

when trying to mount it rw I get,

mount: /data/guests/ufs/lala: WARNING: device write-protected, mounted read-only.

SPECIAL ROUTING

For some special Failover IP usage (think of Dedibox/Online.net),

vif = [ 'vifname=netbsdsec.0, mac=00:16:3e:XX:XX:XX, bridge=xenbr0' ]

Note. no proxy_arp nor ip_forward are needed, this is xen bridge, not xen routing.

And in the netbsd guest,

XEN_HOST=x.x.x.x
ISP_HOSTGW=x.x.x.x
ISP_GW=x.x.x.x
FAILOVER_IP=x.x.x.x

ifconfig xennet0 inet $FAILOVER_IP/32 up
route add -net $XEN_HOST/32 -link -cloning -iface xennet0
ping -c1 $XEN_HOST

route add -net $ISP_HOSTGW/32 -link -cloning -iface xennet0
ping -c1 $ISP_HOSTGW

route add -net $ISP_GW/32 -link -cloning -iface xennet0
ping -c1 $ISP_GW

route add default $ISP_GW -ifa $FAILOVER_IP
ping -c1 8.8.8.8

netstat -rn -f inet

cat > /etc/ifconfig.xennet0 <<-EOF
inet $FAILOVER_IP/32 up
!/sbin/route add -net $XEN_HOST/32 -link -cloning -iface xennet0
!/sbin/route add -net $ISP_GW/32 -link -cloning -iface xennet0
!/sbin/route add default $ISP_GW -ifa $FAILOVER_IP
EOF

Note. eventually add a route to the whole subnet instead of XEN_HOST + ISP_GW.

And if you need a fake switch for the guests on this only to communicate with each other,

brctl addbr dummybr0
ifconfig dummybr0 ...

or in Debian/Ubuntu terms,

vi /etc/network/interfaces

auto dummybr0
iface dummybr0 inet static
        address x.x.x.x/xx
        bridge_ports none

then into the guest config,

vif = [ 'vifname=$guest.0, bridge=xenbr0',
    'vifname=$guest.1, bridge=dummybr0' ]

Refs.

LVM

An alternative is to use LVM instead of a sparse file, which makes even more sense on a NetBSD dom0 as the dd seek option is not available,

lvm pvcreate /dev/rsd1d
lvm vgcreate guestsvg "/dev/rsd1d"
lvm lvcreate -n netbsdguest1 -L 5G guestsvg

'phy:/dev/mapper/guestsvg-netbsdguest1,0x03,w',
'file:/root/NetBSD-7.0.1-amd64.iso,0x04,r'

References