├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── _gokrazy ├── extrafiles_amd64.tar ├── extrafiles_arm.tar └── extrafiles_arm64.tar ├── go.mod ├── go.sum ├── mkfs.go └── third_party └── e2fsprogs-1.47.1 ├── e2fsck.amd64 ├── e2fsck.arm ├── e2fsck.arm64 ├── mke2fs.amd64 ├── mke2fs.arm └── mke2fs.arm64 /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:bullseye 2 | 3 | RUN apt-get update && apt-get install -y crossbuild-essential-armel crossbuild-essential-arm64 build-essential curl 4 | 5 | RUN mkdir /src /bins && curl -s https://mirrors.edge.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/v1.47.1/e2fsprogs-1.47.1.tar.gz | tar --strip-components=1 -C /src -xzf - 6 | 7 | ENV SOURCE_DATE_EPOCH 1600000000 8 | 9 | RUN cd /src && \ 10 | ./configure CFLAGS='-O2 -static' LDFLAGS=-static CC=arm-linux-gnueabi-gcc --host=arm-linux-gnueabi && \ 11 | make -j$(nproc) && \ 12 | cp ./misc/mke2fs /bins/mke2fs.arm && \ 13 | cp ./e2fsck/e2fsck /bins/e2fsck.arm && \ 14 | make distclean 15 | 16 | RUN cd /src && \ 17 | ./configure CFLAGS='-O2 -static' LDFLAGS=-static CC=aarch64-linux-gnu-gcc --host=aarch64-linux-gnu && \ 18 | make -j$(nproc) && \ 19 | cp ./misc/mke2fs /bins/mke2fs.arm64 && \ 20 | cp ./e2fsck/e2fsck /bins/e2fsck.arm64 && \ 21 | make distclean 22 | 23 | RUN cd /src && \ 24 | ./configure CFLAGS='-O2 -static' LDFLAGS=-static && make -j$(nproc) && \ 25 | cp ./misc/mke2fs /bins/mke2fs.amd64 && \ 26 | cp ./e2fsck/e2fsck /bins/e2fsck.amd64 && \ 27 | make distclean 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 the gokrazy authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of gokrazy nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: _gokrazy/extrafiles_amd64.tar _gokrazy/extrafiles_arm64.tar _gokrazy/extrafiles_arm.tar 2 | 3 | third_party/e2fsprogs-1.47.1/mke2fs.amd64: Dockerfile 4 | docker build --rm -t e2fsprogs . 5 | docker run --rm -v $$(pwd)/third_party/e2fsprogs-1.47.1:/tmp/bins e2fsprogs cp -r /bins/ /tmp/ 6 | 7 | _gokrazy/extrafiles_amd64.tar: third_party/e2fsprogs-1.47.1/mke2fs.amd64 third_party/e2fsprogs-1.47.1/e2fsck.amd64 8 | mkdir -p _gokrazy 9 | tar cf $@ $^ "--transform=s,third_party/e2fsprogs-1.47.1/\([^.]*\)\..*,usr/local/bin/\1,g" 10 | 11 | _gokrazy/extrafiles_arm64.tar: third_party/e2fsprogs-1.47.1/mke2fs.arm64 third_party/e2fsprogs-1.47.1/e2fsck.arm64 12 | mkdir -p _gokrazy 13 | tar cf $@ $^ "--transform=s,third_party/e2fsprogs-1.47.1/\([^.]*\)\..*,usr/local/bin/\1,g" 14 | 15 | _gokrazy/extrafiles_arm.tar: third_party/e2fsprogs-1.47.1/mke2fs.arm third_party/e2fsprogs-1.47.1/e2fsck.arm 16 | mkdir -p _gokrazy 17 | tar cf $@ $^ "--transform=s,third_party/e2fsprogs-1.47.1/\([^.]*\)\..*,usr/local/bin/\1,g" 18 | 19 | clean: 20 | rm -f third_party/e2fsprogs-1.47.1/* 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gokrazy mkfs 2 | 3 | This program is intended to be run on gokrazy only, where it will create an ext4 4 | file system on the perm partition and then reboot your system. If `/perm` is 5 | already mounted, the program will exit without changing anything. 6 | 7 | The gokrazy mkfs program includes a static build of the `mke2fs` and `e2fsck` 8 | programs from the `e2fsprogs` package. 9 | 10 | ## Usage 11 | 12 | You can either add this program to your gokrazy instance: 13 | 14 | ``` 15 | gok add github.com/gokrazy/mkfs 16 | ``` 17 | 18 | …or, if you want to run it only once without otherwise including it in your 19 | installation, you can use `gok run`: 20 | 21 | ``` 22 | git clone https://github.com/gokrazy/mkfs 23 | cd mkfs 24 | gok -i bakery run 25 | ``` 26 | 27 | 28 | -------------------------------------------------------------------------------- /_gokrazy/extrafiles_amd64.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokrazy/mkfs/fbb07f9ec5fd85dbed6db8a3f64ef9c55315cc1d/_gokrazy/extrafiles_amd64.tar -------------------------------------------------------------------------------- /_gokrazy/extrafiles_arm.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokrazy/mkfs/fbb07f9ec5fd85dbed6db8a3f64ef9c55315cc1d/_gokrazy/extrafiles_arm.tar -------------------------------------------------------------------------------- /_gokrazy/extrafiles_arm64.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokrazy/mkfs/fbb07f9ec5fd85dbed6db8a3f64ef9c55315cc1d/_gokrazy/extrafiles_arm64.tar -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/gokrazy/mkfs 2 | 3 | go 1.24 4 | 5 | require ( 6 | github.com/gokrazy/gokapi v0.0.0-20250530162407-ee2d0d668321 7 | github.com/gokrazy/internal v0.0.0-20250526201501-559979153369 8 | ) 9 | 10 | require ( 11 | github.com/antihax/optional v1.0.0 // indirect 12 | github.com/spf13/pflag v1.0.5 // indirect 13 | golang.org/x/oauth2 v0.23.0 // indirect 14 | ) 15 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwcg= 2 | github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= 3 | github.com/gokrazy/gokapi v0.0.0-20250530162407-ee2d0d668321 h1:WIkgE9uiyZw1/YzywulZQP2o2YfrFWV/BBbshhcWY4Y= 4 | github.com/gokrazy/gokapi v0.0.0-20250530162407-ee2d0d668321/go.mod h1:rVItujrJo0NpYZhFR5dYdzLDqMoMCtjEZkdxoCRDo+o= 5 | github.com/gokrazy/internal v0.0.0-20250526201501-559979153369 h1:aNni2iPwJbowfHW1SFapKLfY+ZPUIcBfFrJvYPAh3p4= 6 | github.com/gokrazy/internal v0.0.0-20250526201501-559979153369/go.mod h1:dQY4EMkD4L5ZjYJ0SPtpgYbV7MIUMCxNIXiOfnZ6jP4= 7 | github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= 8 | github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 9 | github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= 10 | github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 11 | golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= 12 | golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= 13 | -------------------------------------------------------------------------------- /mkfs.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | "os" 8 | "os/exec" 9 | "strings" 10 | 11 | "github.com/gokrazy/gokapi" 12 | "github.com/gokrazy/gokapi/ondeviceapi" 13 | "github.com/gokrazy/internal/rootdev" 14 | ) 15 | 16 | func makeFilesystemNotWar() error { 17 | b, err := os.ReadFile("/proc/self/mountinfo") 18 | if err != nil { 19 | return err 20 | } 21 | for _, line := range strings.Split(strings.TrimSpace(string(b)), "\n") { 22 | parts := strings.Fields(line) 23 | if len(parts) < 5 { 24 | continue 25 | } 26 | mountpoint := parts[4] 27 | log.Printf("Found mountpoint %q", parts[4]) 28 | if mountpoint == "/perm" { 29 | log.Printf("/perm file system already mounted, nothing to do") 30 | return nil 31 | } 32 | } 33 | 34 | // /perm is not a mounted file system. Try to create a file system. 35 | dev := rootdev.Partition(rootdev.Perm) 36 | log.Printf("No /perm mountpoint found. Creating file system on %s", dev) 37 | 38 | mkfs := exec.Command("/usr/local/bin/mke2fs", "-t", "ext4", dev) 39 | mkfs.Stdout = os.Stdout 40 | mkfs.Stderr = os.Stderr 41 | log.Printf("%v", mkfs.Args) 42 | if err := mkfs.Run(); err != nil { 43 | return fmt.Errorf("%v: %v", mkfs.Args, err) 44 | } 45 | 46 | // It is pointless to try and mount the file system here from within this 47 | // process, as gokrazy services are run in a separate mount namespace. 48 | // Instead, we trigger a reboot so that /perm is mounted early and 49 | // the whole system picks it up correctly. 50 | log.Printf("triggering reboot to mount /perm") 51 | cfg, err := gokapi.ConnectOnDevice() 52 | if err != nil { 53 | return err 54 | } 55 | cl := ondeviceapi.NewAPIClient(cfg) 56 | _, err = cl.UpdateApi.Reboot(context.Background(), &ondeviceapi.UpdateApiRebootOpts{}) 57 | if err != nil { 58 | return err 59 | } 60 | 61 | return nil 62 | } 63 | 64 | func main() { 65 | if err := makeFilesystemNotWar(); err != nil { 66 | fmt.Fprintf(os.Stderr, "%v\n", err) 67 | } 68 | // tell gokrazy to not supervise this service, it’s a one-off: 69 | os.Exit(125) 70 | } 71 | -------------------------------------------------------------------------------- /third_party/e2fsprogs-1.47.1/e2fsck.amd64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokrazy/mkfs/fbb07f9ec5fd85dbed6db8a3f64ef9c55315cc1d/third_party/e2fsprogs-1.47.1/e2fsck.amd64 -------------------------------------------------------------------------------- /third_party/e2fsprogs-1.47.1/e2fsck.arm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokrazy/mkfs/fbb07f9ec5fd85dbed6db8a3f64ef9c55315cc1d/third_party/e2fsprogs-1.47.1/e2fsck.arm -------------------------------------------------------------------------------- /third_party/e2fsprogs-1.47.1/e2fsck.arm64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokrazy/mkfs/fbb07f9ec5fd85dbed6db8a3f64ef9c55315cc1d/third_party/e2fsprogs-1.47.1/e2fsck.arm64 -------------------------------------------------------------------------------- /third_party/e2fsprogs-1.47.1/mke2fs.amd64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokrazy/mkfs/fbb07f9ec5fd85dbed6db8a3f64ef9c55315cc1d/third_party/e2fsprogs-1.47.1/mke2fs.amd64 -------------------------------------------------------------------------------- /third_party/e2fsprogs-1.47.1/mke2fs.arm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokrazy/mkfs/fbb07f9ec5fd85dbed6db8a3f64ef9c55315cc1d/third_party/e2fsprogs-1.47.1/mke2fs.arm -------------------------------------------------------------------------------- /third_party/e2fsprogs-1.47.1/mke2fs.arm64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gokrazy/mkfs/fbb07f9ec5fd85dbed6db8a3f64ef9c55315cc1d/third_party/e2fsprogs-1.47.1/mke2fs.arm64 --------------------------------------------------------------------------------