├── README.md └── recipes └── debian9_inside_vmm.md /README.md: -------------------------------------------------------------------------------- 1 | # Recipes 2 | 3 | Miscellaneous notes on how to achieve things. 4 | 5 | # Contents 6 | 7 | * [Running Debian 9 inside OpenBSD vmm(4)](recipes/debian9_inside_vmm.md) 8 | -------------------------------------------------------------------------------- /recipes/debian9_inside_vmm.md: -------------------------------------------------------------------------------- 1 | # Running Debian 9 inside OpenBSD vmm(4) 2 | 3 | At the time of writing, `vmm(4)` does not emulate CDROM after initial boot. 4 | This means you cannot install Debian directly under `vmm(4)`. 5 | 6 | We can work around this by doing the initial install under qemu. 7 | 8 | 9 | ## Process 10 | 11 | ### Make a disk image with vmctl(8). 12 | 13 | ``` 14 | $ vmctl create deb9.img -s 50G 15 | ``` 16 | 17 | (Makes a 50 Gigabyte disk image) 18 | 19 | ### Boot the Debian install CD under qemu with the disk image attached. 20 | 21 | ``` 22 | $ qemu-system-x86_64 -cdrom debian-9.3.0-amd64-xfce-CD-1.iso -hda deb9.img -boot d -m 3G -net nic -net user 23 | ``` 24 | 25 | ### Install Debian as usual. 26 | 27 | This will be slow, as qemu is not accelerated on OpenBSD. 28 | 29 | Once the install is done, shut down the VM. 30 | 31 | ### Boot the new system under qemu, but without the install CDROM inserted. 32 | 33 | ``` 34 | $ qemu-system-x86_64 -hda deb9.img -m 3G -net nic -net user 35 | ``` 36 | 37 | ### Change the console to the serial line. 38 | 39 | At the time of writing, `vmm(4)` doesn't do VGA emulation, so we have to use the 40 | serial line as a console. 41 | 42 | Login and edit `/etc/default/grub`. Add `console=ttyS0` to 43 | `GRUB_CMDLINE_LINUX_DEFAULT`. You should then have a line like: 44 | 45 | ``` 46 | GRUB_CMDLINE_LINUX_DEFAULT="quiet console=ttyS0" 47 | ``` 48 | 49 | Install the new boot-loader config to the disk, then halt the VM. 50 | 51 | ``` 52 | # update-grub 53 | ... 54 | # halt -p 55 | ``` 56 | 57 | ### Boot the VM under vmm(4). 58 | 59 | ``` 60 | $ doas vmctl start deb9 -d deb9.img -i 1 -L -m 3G -c 61 | ``` 62 | 63 | ### Update the networking configuration. 64 | 65 | `vmm(4)` emulates a different kind of network device to qemu, so we have to 66 | change the config. 67 | 68 | Edit `/etc/networks/interfaces` and replace all instances of `ens3` with 69 | `enp0s3`. You should then have a section like this: 70 | 71 | ``` 72 | # The primary network interface 73 | allow-hotplug enp0s3 74 | iface enp0s3 inet dhcp 75 | ``` 76 | 77 | ### Grant the VM network access. 78 | 79 | We can use firewall rules to grant the VM access to the internet. 80 | 81 | On the OpenBSD host, edit `/etc/pf.conf` and add a lines like this: 82 | 83 | ``` 84 | vm_ext=iwm0 85 | vm_dns=8.8.8.8 86 | ... 87 | pass out on $vm_ext from 100.64.0.0/10 to any nat-to ($vm_ext) 88 | pass in proto udp from 100.64.0.0/10 to any port domain \ 89 | rdr-to $vm_dns port domain 90 | ``` 91 | 92 | Change `vm_ext` and `vm_dns` to: an interface through which to grant the VM 93 | internet access, and a valid DNS server respectively. 94 | 95 | The parentheses around `$vm_ext` causes the NAT rule to lazily look up the 96 | address of the interface. This is useful on (e.g.) a laptop, where the IP of 97 | (in this case) `iwm0` may change as you move networks. 98 | 99 | Don't forget that the order of `pf(4)` rules matters! 100 | 101 | Apply the new rules: 102 | 103 | ``` 104 | # pfctl -f /etc/pf.conf 105 | ``` 106 | 107 | Then enable ipv4 (or ipv6, if you need it) forwarding: 108 | 109 | ``` 110 | # sysctl net.inet.ip.forwarding=1 111 | # echo "net.inet.ip.forwarding=1" >> /etc/sysctl.conf 112 | ``` 113 | 114 | ### Reboot the VM. 115 | 116 | And you are done. 117 | 118 | It's probably a good idea to copy the image somewhere safe so you can use as a 119 | template for Linux VMs. 120 | --------------------------------------------------------------------------------