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

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

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

guest=rescue

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"
EOF
vi $guest

(change cpu and memory)

unset guest

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

And in the netbsd guest,

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

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 8.8.8.8

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' ]

Refs.

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/sec/sec.disk,sdb,w',
         'file:/data/guest/netbsd71/NetBSD-7.1-amd64.iso,hdc,r' ]

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

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


Home | GitHub | Docker Hub | Donate | Contact