This procedure was tested on FreeBSD-CURRENT build from d8819d88af52.
-
Enable linuxulator and install linux userland:
# sysrc linux_enable="YES" # service linux start # pkg install linux_base-c7
Test it:
$ /compat/linux/usr/bin/uname -a Linux monster-1 4.4.0 FreeBSD 14.0-CURRENT #1 main-n254392-d8819d88af52: Wed Apr 6 22 x86_64 x86_64 x86_64 GNU/Linux
For more details on linuxulator setup please refer to handbook.
-
remote-ssh seem to ignore bash config files so we need to change
$PATH
in/etc/login.conf
or send custom env withSetEnv
directive inssh_config
. Choose which fits you better.By default it's class
default
, we need to give priority to linux binaries::path=/compat/linux/usr/sbin /compat/linux/usr/bin /sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin ~/bin:\
rebuild CAP database:cap_mkdb /etc/login.conf
Host your-freebsd.box SetEnv PATH="/compat/linux/usr/sbin:/compat/linux/usr/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
-
Set you normal PATH for your every day use in your shell's config file (.bashrc od .zshrc, etc)
-
Connect to your FreeBSD box with VScode's remote SSH extension!
Maybe some additional context on the setup I'm using helps: I do mostly FreeBSD kernel development/research and use very few extensions in the remote VS Code (server) instance. For this I use a Linux host and a FreeBSD guest in a QEMU VM and I connect to it through the VS Code Remote SSH extension on the host. Once connected, I exclusively use the FreeBSD system and toolchains, not the emulated Debian toolchains! I presume this is especially important when using the built-in terminal, which should default to the Debian bash executable in this setup, which will probably reveal further broken symlinks etc sooner or later. My FreeBSD VM does also not have any users, I just do everything as root. I get that this is not practicable in most other setups. For writing this guide I used a fresh VM, with no previous code-server installations, so this should not be a factor.
Just now I tried following my own guide but using a non-root user account (in yet another freshly installed VM). For me this failed due to some permission errors when trying to accessing the user's home dir. I was able to fix this following the FS mount instructions in this chapter of the FreeBSD manual. Specifically, I appended this:
... to
/etc/fstab
(as root of course) in FreeBSD and mounted everything with:# mount -al
With this, I am able to connect to VM again and everything seems to be working. I guess I should have kept this step in the guide, but while writing it I figured out that it was not necessary for my particular setup. It just didn't occur to me that this might cause issues when using non-root user accounts.