In order to test modifications to the FreeBSD kernel, I would like to boot a diskless virtual machine. The goal is to be able to quickly test changed I make without needing to recreate the VM each time, or run the installation procedure inside of the VM.
You can elect to put the root anywhere you want. For this example, I will be using /home/vm as the root of the virtual machine.
There are a few aspects to this:
- The filesystem that will be booted.
- VirtualBox setup
- Virtual machine setup
- DHCP server
- Host setup
Filesystem Installation
- Create the distribution:
cd /usr/src make installworld installkernel distribution DESTDIR=/home/vm
-
Create the /conf directory used for diskless boot. See /etc/rc.initdiskless for details.
# cd /home/vm/ # mkdir -p conf/base/etc # cd conf/base/etc # cat diskless_remount /etc # cat fstab md /tmp mfs -s=30m,rw 0 0 md /var mfs -s=30m,rw 0 0 # cat md_size 256m
VirtualBox Setup
Create a "host-only" interface with DHCP disabled. To do this:
Create the Virtual Machine
- Create a new virtual machine. Make sure to select "FreeBSD - 64 bit". Note that you should create this machine without any disk (and ignore the warning at the end).
- Open up the virtual machine's settings
- Select only the "Network" option under boot order (System->Motherboard->Boot Order). Also check "Hardware clock in UTC time."
- Under network select the Host Only Adapter created before. Under advanced options, change the adapter type to "PCNet-PCI II." Also make a note of the mac address of the virtual machine. It will be needed later.
DHCP Server
For simplicity I opted to use a really simple DHCP server dnsmasq:- Install dnsmasq
$ make -C /usr/ports/dns/dnsmasq install clean
- Configure dnsmasq to server as a tftp and DHCP server for the virtual machine interface. Modify /usr/local/etc/dnsmasq.conf (I've bolded the parts that are configuration specific):
interface=vboxnet0 dhcp-range=172.16.100.100,172.16.100.200,48h[1] #Note that this mac address is the mac address of the vm noted earlier. dhcp-host=01:02:03:04:05:06,vm-testing,172.16.100.100,set:diskless dhcp-boot=tag:diskless,/home/vm/boot/pxeboot dhcp-option=tag:diskless,option:root-path,"/home/vm/" enable-tftp
- Add this to /etc/dhclient.conf so that you can reference your virtual machine by name:
precede domain-name-servers 127.0.0.1;
Host Setup
- Add the following to /etc/rc.conf:
# Required for VirtualBox devfs_system_ruleset="system" # Required for diskless boot dnsmasq_enable="YES" # NFS Exports rpcbind_enable="YES" nfs_server_enable="YES" mountd_enable="YES" mountd_flags="-r" nfs_client_enable="YES" weak_mountd_authentication="YES"
- Add the directory to /etc/exports:
/home/vm -ro -alldirs -network 172.16.0.0 -maproot=root
Now you are all set. Just boot the virtual machine from VirtualBox and watch it go!
- Note that the 172.16.0.0/20 network is RFC 1918 private address space.
No comments:
Post a Comment
Have something you want to say? You think I'm wrong? Found something I said useful?
Leave a comment!