Note: This is an old post from when I wrote on medium.com…formatting may be wonky here until I clean it up.
Matterhornā¦if you squint you can see Puffy up there, I swear. (https://commons.wikimedia.org/wiki/File:Matterhorn_from_Domh%C3%BCtte_-_2.jpg)
Virtualization is just plain fun. While I do rely on it specifically to satisfy professional needs while running OpenBSD on my laptop (mostly hacking on some enterprise Java software that doesnāt natively support *BSD), I find myself constantly fascinated by it and tinkering with it.
The OpenBSD man pages are a great resources, as well are the mailing lists and FAQā¦but when it comes to non-OpenBSD specific needs like tuning your Linux VM there isnāt much out there. Hopefully someone finds these useful š
The following are some tips/tricks for making Alpine Linux far more usable under OpenBSD, especially if you need to do real work in a Linux environment and want to do it on your local OpenBSD machine without rebooting.
This post will cover some installation, disk management, and vm networking tips!
Honestly, this should be self-evident if youāve played with Alpine and VMD. If not, it doesnāt hurt to revisit. Trust me Iāve personally lost sanity points on this.
Alpine has many flavors, each with slightly different, pre-baked boot args, kernel configs, etc. Regardless of which you use you need to properly tell Alpineās boot loader to pass along details to the kernel that you need serial console support. (I believe the exception is the virt flavor, but it doesnāt hurt to know this!)
At boot, hit TAB
to see the boot menu label available. Chances are itās something like hardened
or grsec
depending on your Alpine version (3.6 vs. older).
Type the name (e.g. āhardenedā), a space, and then console=ttyS0,115200
like so: hardened console=ttyS0,115200
. It should be all you need to properly get serial console access via the -c
flag during vmctl start
or when using vmctl console
.
There are still some sync issues between OpenBSDās serial terminal emulator (cu(1)) and the virtualized serial console āpluggedā into the Alpine Linux VM. This problem, on my host system, seems non-deterministic in how it randomly locks upā¦so I recommend scrambling to establish SSH access to complete the install.
While itās not readily apparent, most Alpine iso flavors (at least alpine-standard) have the OpenSSH package available, just not installed. This means you donāt even need internet access in the VM.
Once your inside Alpine Linux after initial boot from the iso:
apk add openssh
passwd root
/etc/ssh/sshd_config
, uncommenting and changing the PermitRootLogin line to something like PermitRootLogin yes
. You can use vi
or sed
or whatever floats your š„/etc/init.d/sshd start
setup-alpine
is the easiest way to do thisā¦just work through the steps up until you select a network device and configure either static of a dynamic IP (write this down or copy it).^c
Once you have the IP, itās safe to kill the serial console via the cu(1)
control sequence <return><return><tilde><period>
(RET RET ~.
).
Then just ssh into the Alpine box using the IP you obtained or set during the aborted install and youāll be on far more stable connection, bypassing the serial console. From there you can re-run alpine-setup
and complete the install.
If youāve followed other guidance you may have at least configured the Alpine instance to use the serial console by default. However, unless you intervene youāll either have long boot times or have to manually intervene to navigate the boot menu presented by syslinux. Letās change that so vm.conf
can then be used to start it automatically at OpenBSD boot time quickly and confidently.
BTW: This is easily done during install and before reboot/poweroff of the VM. If youāve just completed alpine-setup
, you just need to mount the boot partition from your new disk: mount /dev/vdb1 /mnt
Note: It most likely will be the
vdb
block device assumingvdb
is the device you chose to initialize assys
Ā . Choose whichever device you chose duringsetup-alpine
.
Update the config file/mnt/boot/syslinux/extlinux.conf
(or /boot/syslinux/extlinux.conf
if youāre already rebooted after install) to make it look more like the following:
You can either comment out existing lines or remove them entirely. The important things to note are:
MENU
related entries, other than any nested under LABEL
.LABEL
block since it has your systemās root partition UUID (mine wonāt work for you) and the proper kernel name, which may be different.DEFAULT
to the LABEL
value you want to boot, e.g. hardened
Save and reboot. Other than maybe a slow ntp daemon, it should boot right up and be ready to go.
This is super handy if you plan on storing lots of stuff within the Alpine VM and want to be able to nuke the root disk. Letās say your root disk image (where youāve installed Alpine) is called alpine-data.img
.
$ vmctl create alpine-data.img -s 20G
$ vmctl start my-alpine-vm -d alpine-root.img -d alpine-data.img
# apk add parted
(parted) mklabel gpt
(parted) unit MiB
(parted) mkpart 1 ext4 1 20479
(parted) align-check opt
(parted) name 1 data
(parted) quit
# mkfs.ext4 /dev/vdb1
mkfs
reports! Copy that./etc/fstab
in Alpine, adding a new line with the UUID like: UUID=2fc3aff6ā5a80ā4ef7ā809b-33de8a3ceb17 /data ext4 rw,relatime,user 0 0
mount /data
(where /data is my mount-point). If things are good, the entry in /etc/fstab
should tell the system all it needs to mount the disk.vm.conf
, update to include the additional disk in the vm settings.Using disk partition UUIDs, we can make sure if we accidentally or purposely change the order we attach the virtual block devices, the system can still find the right partitions for booting, root, and our new data partition. The joy of GPT and UUIDs!
If you use the data disk idea above and plan on using Docker on Alpine, it makes a perfect way to isolate the storage used by the containers and their data so you donāt blow out disk space for your root partition.
First install Docker, then modify the /etc/conf.d/docker
config file, adding a custom DOCKER_OPTS
setting:
# any other random options you want to pass to docker DOCKER_OPTS=”–data-root /data/docker”
Where /data/docker
is a location on my mounted data disk.
Restart Docker with rc-service docker restart
. You should see the hierarchy of the Docker puke š¤¢ in your new directory.
Last step is never tell anyone on the internet you run Docker on virtualized hardware because youāll be told you just killed about 1000 kittens. š¤·ā
Hopefully the above tips help someone someday. If they do, do us all a favor and kick a few bucks to OpenBSD development.
Future tips might include: