Skip to content

Make gok work on Windows #89

Open
Open

Description

@dolmen

Add a gok build command that allows to build an image without writing it to a device.

Rationale

Building an image is already possible withgok overwrite --full <file> --target_storage_bytes <bytes>.

However, the gok overwrite command requires much OS-specific code to write the image, especially as this usually requires admin privileges. That part could be handled by other platform specific tool (ex: rufus) that a user could invoke independently of gok once an image is built.

Currently it is not possible to build gok on Windows because of the overwrite command because it is dependent on Unix-specific bits such as dependency on non-portable module golang.org/x/unix.

If gok was refactored to isolate a build command, a developer (well, myself 😜 ) could more easily make a version of gok available on Windows with the build command but, as a first step, without the overwrite command. And port the overwrite command later.

Activity

  1. changed the title [-]Refactor `overwrite` and extract a `build` command[/-] [+]Make gok work on Windows[/+] on May 29, 2025
  2. stapelberg commented on May 29, 2025

    @stapelberg
    Contributor

    I don’t think introducing a separate command to the CLI is necessary or helpful for making gok work on Windows, which I think is your actual goal :)

    In fact, I’ll do you one better: with the two most recent commits, gok now builds and runs on Windows:

    Microsoft Windows [Version 10.0.22631.4751]
    (c) Microsoft Corporation. All rights reserved.
    
    michael stapelberg@BEAST C:\Users\Michael Stapelberg\gokrazy\hello>"C:\Users\Michael Stapelberg\gok" overwrite --root root.squashfs
    2025/05/29 14:29:54 gokrazy gok g5b15ff+ on GOARCH=amd64 GOOS=windows
    2025/05/29 14:29:54 
    2025/05/29 14:29:54 Build target: CGO_ENABLED=0 GOARCH=arm64 GOARCH=arm64 GOOS=linux GOOS=linux
    2025/05/29 14:29:54 Build timestamp: 2025-05-29T14:29:54+02:00
    2025/05/29 14:29:54 Loading system CA certificates from bundled Mozilla CA list
    2025/05/29 14:29:54 Building 3 Go packages:
    2025/05/29 14:29:54 
    2025/05/29 14:29:54   github.com/gokrazy/fbstatus
    2025/05/29 14:29:54 
    2025/05/29 14:29:54   github.com/gokrazy/hello
    2025/05/29 14:29:54 
    2025/05/29 14:29:54   github.com/gokrazy/serial-busybox
    2025/05/29 14:29:54 
    [building (go compiler)]go: finding module for package github.com/gokrazy/gokrazy/cmd/dhcp
    go: downloading github.com/gokrazy/gokrazy v0.0.0-20250520211131-8916805aa0c7
    go: finding module for package github.com/gokrazy/gokrazy/cmd/dhcp
    go: toolchain upgrade needed to resolve github.com/gokrazy/gokrazy/cmd/dhcp
    go: github.com/gokrazy/gokrazy@v0.0.0-20250520211131-8916805aa0c7 requires go >= 1.24 (running go 1.23.6)
    2025/05/29 14:29:57 getting incomplete packages [github.com/gokrazy/gokrazy/cmd/dhcp]
    […]
    [done] in 58.29s
    2025/05/29 14:30:52
    2025/05/29 14:30:54 Including extra files for Go packages:
    2025/05/29 14:30:54
    2025/05/29 14:30:54   github.com/gokrazy/serial-busybox
    2025/05/29 14:30:54     will include extra files in the root file system
    2025/05/29 14:30:54       from C:\Users\Michael Stapelberg\go\pkg\mod\github.com\gokrazy\serial-busybox@v0.0.0-20250119153030-ac58ba7574e7\_gokrazy\extrafiles_arm64.tar
    2025/05/29 14:30:54       last modified: 2025-01-19T15:59:16+01:00 (3117h31m38s ago)
    2025/05/29 14:30:54
    2025/05/29 14:30:54 Including loadable kernel modules from:
    2025/05/29 14:30:54   C:\Users\Michael Stapelberg\go\pkg\mod\github.com\gokrazy\kernel.rpi@v0.0.0-20250520195459-906287a872d7\lib\modules
    2025/05/29 14:30:55
    2025/05/29 14:30:55 Feature summary:
    2025/05/29 14:30:55   use GPT: true
    2025/05/29 14:30:55   use PARTUUID: true
    2025/05/29 14:30:55   use GPT PARTUUID: true
    2025/05/29 14:30:55
    2025/05/29 14:30:55 Creating root file system
    [done] in 0.78s
    2025/05/29 14:30:56
    2025/05/29 14:30:56 Build complete!
    2025/05/29 14:30:56
    2025/05/29 14:30:56 To interact with the device, gokrazy provides a web interface reachable at:
    2025/05/29 14:30:56
    2025/05/29 14:30:56     http://gokrazy:redacted@hello/
    2025/05/29 14:30:56
    2025/05/29 14:30:56 In addition, the following Linux consoles are set up:
    2025/05/29 14:30:56
    2025/05/29 14:30:56     1. foreground Linux framebuffer console on HDMI
    2025/05/29 14:30:56
    
    

    The resulting squashfs image still has a few issues:

    % unsquashfs -ll root.squashfs 
    dr-xr-xr-x root/root               210 2025-05-29 14:30 squashfs-root
    dr-xr-xr-x root/root                33 2025-05-29 14:30 squashfs-root/\etc
    -r--r--r-- root/root                33 2025-05-29 14:30 squashfs-root/\etc/machine-id
    dr-xr-xr-x root/root                 3 2025-05-29 14:30 squashfs-root/bin
    dr-xr-xr-x root/root                 3 2025-05-29 14:30 squashfs-root/dev
    dr-xr-xr-x root/root               151 2025-05-29 14:30 squashfs-root/etc
    -r-------- root/root                20 2025-05-29 14:30 squashfs-root/etc/gokr-pw.txt
    dr-xr-xr-x root/root                57 2025-05-29 14:30 squashfs-root/etc/gokrazy
    -r--r--r-- root/root                 4 2025-05-29 14:30 squashfs-root/etc/gokrazy/mountdevices.json
    -r--r--r-- root/root              7789 2025-05-29 14:30 squashfs-root/etc/gokrazy/sbom.json
    -r--r--r-- root/root                 5 2025-05-29 14:30 squashfs-root/etc/hostname
    -r--r--r-- root/root                34 2025-05-29 14:30 squashfs-root/etc/hosts
    -r--r--r-- root/root                 2 2025-05-29 14:30 squashfs-root/etc/http-port.txt
    -r--r--r-- root/root                 3 2025-05-29 14:30 squashfs-root/etc/https-port.txt
    lr--r--r-- root/root                16 2025-05-29 14:30 squashfs-root/etc/resolv.conf -> /tmp/resolv.conf
    dr-xr-xr-x root/root                36 2025-05-29 14:30 squashfs-root/etc/ssl
    -r--r--r-- root/root            224469 2025-05-29 14:30 squashfs-root/etc/ssl/ca-bundle.pem
    dr-xr-xr-x root/root                82 2025-05-29 14:30 squashfs-root/gokrazy
    -rw-rw-rw- root/root           5824919 2025-05-29 14:30 squashfs-root/gokrazy/dhcp
    -rw-rw-rw- root/root           9931156 2025-05-29 14:30 squashfs-root/gokrazy/heartbeat
    -rw-rw-rw- root/root          13888716 2025-05-29 14:30 squashfs-root/gokrazy/init
    -rw-rw-rw- root/root           3970741 2025-05-29 14:30 squashfs-root/gokrazy/ntp
    -rw-rw-rw- root/root           2618097 2025-05-29 14:30 squashfs-root/gokrazy/randomd
    dr-xr-xr-x root/root                30 2025-05-29 14:30 squashfs-root/lib
    dr-xr-xr-x root/root                33 2025-05-29 14:30 squashfs-root/lib/modules
    dr-xr-xr-x root/root               348 2025-05-29 14:30 squashfs-root/lib/modules/6.12.25-v8
    […]
    dr-xr-xr-x root/root                 3 2025-05-29 14:30 squashfs-root/mnt
    dr-xr-xr-x root/root                 3 2025-05-29 14:30 squashfs-root/perm
    dr-xr-xr-x root/root                 3 2025-05-29 14:30 squashfs-root/proc
    dr-xr-xr-x root/root                 3 2025-05-29 14:30 squashfs-root/run
    dr-xr-xr-x root/root                 3 2025-05-29 14:30 squashfs-root/sys
    dr-xr-xr-x root/root                 3 2025-05-29 14:30 squashfs-root/tmp
    dr-xr-xr-x root/root                66 2025-05-29 14:30 squashfs-root/user
    -rw-rw-rw- root/root          10612758 2025-05-29 14:30 squashfs-root/user/fbstatus
    -rw-rw-rw- root/root           2155519 2025-05-29 14:30 squashfs-root/user/hello
    -rw-rw-rw- root/root           5231901 2025-05-29 14:30 squashfs-root/user/serial-busybox
    dr-xr-xr-x root/root                30 2025-05-29 14:30 squashfs-root/usr\local\bin
    -rwxr-xr-x root/root           1231136 2025-05-29 14:30 squashfs-root/usr\local\bin/busybox
    lr--r--r-- root/root                 9 2025-05-29 14:30 squashfs-root/var -> /perm/var
    

    The \etc/machine-id is wrong, and similar for usr\local\bin/busybox. In both cases, the OS path separator (\) leaks into the output file system, which should unconditionally use / (forward slashes). Maybe you can send a PR to fix this issue and any other potential Windows-specific issues? I don’t use Windows myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions