Skip to content

Windows compatibility #81

@donno

Description

@donno

This issue intends to document and track compatibility on Microsoft Windows.

tl:dr: Running smolBSD on a Windows host is not too far away.

Identification

OS=$(uname -s|tr 'A-Z' 'a-z')

  • For Git Bash, OS is set to mingw64_nt.<version>
  • For Busybox for Windows, OS is set to windows_nt

For smoler/img.sh

OS=$(uname -s|tr 'A-Z' 'a-z')

case $OS in
linux|darwin) ;;
windows_nt|mingw64_nt*) OS=windows ;;
*)
	echo "unsupported platform"
	exit 1
	;;
esac

Orcas Installation

For Windows, the release of, Oras is provided via a ZIP file rater than a GZipped tar and the executable is named oras.exe rather than oras as common there.

install_oras()
{
	command -v oras >/dev/null && return
	version=$(curl -s https://api.github.com/repos/oras-project/oras/releases/latest | jq -r '.tag_name')
	[ "$OS" = "windows" ] && \
		( curl -fsSL --output bin/oras.zip "https://github.com/oras-project/oras/releases/download/${version}/oras_${version#v}_${OS}_${ARCH}.zip" && \
			unzip bin/oras.zip -d bin oras.exe && rm bin/oras.zip ) \
	||	curl -fsSL "https://github.com/oras-project/oras/releases/download/${version}/oras_${version#v}_${OS}_${ARCH}.tar.gz" | \
			tar xf - -C bin oras
}

This mostly works with both:

  • Git Bash from Git for Windows as it ships with unzip and curl
  • BusyBox for Windows, as it has an unzip applet and Microsoft have been shipping a copy of curl with Windows 10 for some time now.

What doesn't work is jq is not available so that is a prerequisite. I just happened to already have it available.

  • This can be easily addressed by downloading it: curl -L --output bin/jq.exe https://github.com/jqlang/jq/releases/download/jq-1.8.1/jq-windows-amd64.exe

Image Pull

This is problematic because bsdshell-amd64:latest.img is not allowed via NTFS for the Win32 namespace/API, and when you try to pull the image down with oras you end up with images/bsdshell-amd64 that is zero bytes.

I haven't figured out a solution for this, it seems odd that the oras doesn't error or attempt to automatically sanitise the name when pulling an image on Windows nor does it seem to have any way to control this behaviour. For testing the rest of smolBSD, I pulled down the image in a container then renamed it.

Example

$ ./smoler.sh images
IMAGE                                    SIZE          CREATED        SIG
bsdshell-amd64_latest                    96.8M      01/01/1970        NOK

The _ before latest is due to changing the : in the filename to _

Fetching Kernel

No compatible make for performing kernfetch.
The simply work around I did to move on was manually fetch it with:

curl -L --output kernels/netbsd-SMOL https://smolbsd.org/assets/netbsd-SMOL

I haven't revisited this. Maybe the logic could be factored out to a separate script instead of being inlined in the Makefile.

Running image

This requires qemu-system-x86_64 be available via PATH.

  • Configure the accelerator
    • -accel whpx
    • The change in startnb.sh would look like this:
Windows-NT|MINGW64_NT-*)
	accel="-accel whpx"
        cputype="kvm64-v1" # host not supported and max results in a trap.
	;;
  • The use of cputype of max rather than host is because to use of -cpu host it requiring KVM or HVF - it doesn't seem to work with the Windows Hypervisor Platform accelerator (except on maybe aarch64/arm64 as the documentation shows it being used there.
  • Tried cputype of max which but that resulted in fatal privileged instruction fault in supervisor mode and then a trap.

Due to the tweak above to the name, where its _ instead of :

/smoler.sh run bsdshell-amd64_latest

Output

➡️ using QEMU version 10.2.0 (v10.2.0-12105-g0f12d445bd)
➡️ using kernel kernels/netbsd-SMOL
➡️ using console: com
➡️ using disk image images/bsdshell-amd64_latest.img
🔚 ^D to stop the vm, ^A-X to kill it
WHPX: setting APIC emulation mode in the hypervisor
Windows Hypervisor Platform accelerator is operational
[   1.0000000] WARNING: system needs entropy for security; see entropy(7)
[   1.0000000] entropy: ready
[   1.0000000] [ Kernel symbol table missing! ]
[   1.0000000] smolBSD 11.0_BETA (SMOL)        Notice: this software is protected by copyright
[   1.0000000] Detecting hardware... (QBOOT    000000000000)
[   1.0000030]  done.
[   1.0646486] kernel boot time: 130ms
Created tmpfs /dev (1835008 byte, 3552 inodes)
[   1.6743150] /dev/dk0: file system not clean (fs_clean=0); please fsck(8)
Setting tty flags.
no viocon(4) support
add net default: gateway 10.0.2.2
net.inet.tcp.sendbuf_max: 262144 -> 16777216
net.inet.tcp.recvbuf_max: 262144 -> 16777216
kern.sbmax: 262144 -> 16777216
Starting local daemons:.
bsd@shell$ ping -c 3 google.com
PING google.com (142.250.124.100): 56 data bytes
64 bytes from 142.250.124.100: icmp_seq=0 ttl=255 time=11.124874 ms
64 bytes from 142.250.124.100: icmp_seq=1 ttl=255 time=11.030169 ms
64 bytes from 142.250.124.100: icmp_seq=2 ttl=255 time=12.020798 ms

----google.com PING Statistics----
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 11.030169/11.391947/12.020798/0.546656 ms
bsd@shell$

Summary

With some minor tweaks to the shell scripts, Windows can be supported through smoller.sh, with the two remaining known issues:

  • Oras can't properly fetch/store the image on Windows as it contains a :
  • Kernel can't be fetched through the normal methods.

I'm happy to put together a pull request with these changes even if it will remain a draft until a decision about what to do about Oras as that is the biggest show stopper. Would the maintainers of this project like to see one commit for "windows supports" or commit per section (for example, "support installing Oras on Windows" and "configure QEMU acceleration on Windows.")?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions