Skip to content

Instantly share code, notes, and snippets.

@sogaiu
Last active March 11, 2026 10:28
Show Gist options
  • Select an option

  • Save sogaiu/0f320485d010d0e4250f119c17610241 to your computer and use it in GitHub Desktop.

Select an option

Save sogaiu/0f320485d010d0e4250f119c17610241 to your computer and use it in GitHub Desktop.
build static janet via qemu + alpine

steps

  • choose a release https://alpinelinux.org/releases/ -> 3.23.3

  • download iso and checksum from https://alpinelinux.org/downloads/

    wget https://dl-cdn.alpinelinux.org/alpine/v3.23/releases/x86_64/alpine-standard-3.23.3-x86_64.iso
    wget https://dl-cdn.alpinelinux.org/alpine/v3.23/releases/x86_64/alpine-standard-3.23.3-x86_64.iso.sha256
    
  • verify checksum (or do the gpg thing)

    sha256sum alpine-standard-3.23.3-x86_64.iso
    # 966d6bf4d4c79958d43abde84a3e5bbeb4f8c757c164a49d3ec8432be6d36f16  alpine-standard-3.23.3-x86_64.iso
    cat alpine-standard-3.23.3-x86_64.iso.sha256 
    # 966d6bf4d4c79958d43abde84a3e5bbeb4f8c757c164a49d3ec8432be6d36f16  alpine-standard-3.23.3-x86_64.iso
    
  • make file to store installation (here only 1GB chosen, adjust if needed)

    qemu-img create -f qcow2 alpine-standard-3.23.3-x86_64.qcow2 1G
    
  • create shell script for starting alpine (there is likely some unneeded stuff, prune):

#! /bin/sh

# create file by:
#
#   qemu-img create -f qcow2 alpine-standard-3.23.3-x86_64.qcow2 1G

qemu-system-x86_64 \
-enable-kvm                                                    \
-m 2048                                                        \
-drive file=alpine-standard-3.23.3-x86_64.qcow2,if=virtio      \
-boot d                                                        \
-cdrom alpine-standard-3.23.3-x86_64.iso                       \
-netdev user,id=net0,net=192.168.0.0/24,dhcpstart=192.168.0.9  \
-device virtio-net-pci,netdev=net0                             \
-vga std
  • start system via script above

  • log in as root (no password)

  • partition disk

    fdisk /dev/vda
    

    use n to add a new primary partition and choose default values, then chose w to write the table and exit.

  • prepare filesystem, mount, and start setup:

    mkdosfs /dev/vda1
    mkdir -p /media/vda1
    echo "/dev/vda1 /media/vda1 vfat rw 0 0" >> /etc/fstab
    mount -a
    setup-alpine  # (select vda1 for saving configs)
    
  • continue through setup, answered (mostly defaults):

    * Keymap [none]
    * Hostname [localhost]
    * Interface [eth0]
    * Ip address for eth0? [dhcp]
    * Do you want to do any manual network configuration? (y/n) [n]
    * Root Password <something-appropriate>
    * Timezone [UTC]
    * Proxy [none]
    * APK Mirror
      * Enter mirror number or URL: [1]
    * User [no]
    * Which ssh server? [none]
    * Disk & Install
      * Which disk(s) would you like to use? [none]
      * Enter where to store configs [vda1]
      * Enter apk cache directory [/media/vda1/cache]
    
  • update apk repository indexes

    apk update
    
  • install some packages

    apk add gcc make git musl-dev
    
  • tweak PATH things:

    mkdir -p $HOME/.local/bin
    export PATH=$HOME/.local/bin:$PATH
    
  • fetch janet source:

    mkdir src
    cd src
    git clone https://github.com/janet-lang/janet
    cd janet
    
  • edit Makefile for static build, find CFLAGS lines and append -static appropriately

  • build janet:

    make clean && PREFIX=$HOME/.local make
    
  • copy build/janet to /media/vda1/cache

    cp buid/janet /media/vda1/
    
  • might be able to keep packages and such via lbu commit -- not sure

  • shut down

    sync
    halt
    
  • use nbd to get at static janet from qcow2

    sudo modprobe nbd max_part=8
    sudo qemu-nbd --connect=/dev/nbd0 alpine-standard-3.23.3-x86_64.qcow2
    sudo mount /dev/nbd0p1 /mnt
    cp /mnt/janet /tmp/
    sudo umount /mnt
    sudo qemu-nbd --disconnect /dev/nbd0
    

references

future

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