Nethence Newdoc Olddoc Lab Your IP BBDock  

Setting up a NetBSD XEN Guest

Prepare the Guest (seek on Linux only)

Fetching the to-be-shared material,

mkdir -p /data/guest/netbsd71
cd /data/guest/netbsd71


Creating 4GB disk, 8 cores and 256MB of RAM,


mkdir -p /data/guest/$guest
cd /data/guest/$guest

dd if=/dev/zero of=$guest.disk bs=1024k count=1 seek=4096

grep ^proc /proc/cpuinfo 

cat > $guest.conf <<-EOF
kernel = "/data/guest/netbsd71/netbsd-INSTALL_XEN3_DOMU.gz"
#kernel = "/data/guest/netbsd71/netbsd-XEN3_DOMU.gz"
memory = 256
name = "$guest"
vcpus = 2
disk = [ 'file:/data/guest/$guest/$guest.disk,sda,w',
         'file:/data/guest/netbsd71/NetBSD-7.1-amd64.iso,hdc,r' ]
vif = [ 'vifname=$guest.0, bridge=xenbr0' ]
root = "xbd0a"
vi $guest

(change cpu and memory)

unset guest

For some special Failover IP usage (think of Dedibox/,

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

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

And in the netbsd guest,


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

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

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

netstat -rn -f inet

vi /etc/ifconfig.xennet0

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

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 ...

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


Ready to go

Create a GNU/Screen session as wheeled user,

cd /data/guest/
screen -S xen

to maintain the guests,

sudo su -
cd netbsdsec/
xl create netbsdsec.conf -c

then install NetBSD on xbd0 using cdrom at xbd1a.

Once the system is installed, switch the kernel parameter from the installer to the ending production one.

rescuing a netbsd guest

from another guest, say rescue,

disk = [ 'file:/data/guest/rescue/rescue.disk,sda,w',
         'file:/data/guest/netbsd71/NetBSD-7.1-amd64.iso,hdc,r' ]

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


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



Home | GitHub | Docker Hub | Donate | Contact