Skip to content

Commit

Permalink
improve alpine build process
Browse files Browse the repository at this point in the history
fix for podman
add nodejs with hello world as example package
add missing modules=virtio_pci to fix boot process
  • Loading branch information
copy committed Apr 27, 2024
1 parent 077ba9b commit 9286ca8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 28 deletions.
3 changes: 3 additions & 0 deletions docs/archlinux.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
See [Alpine setup](../tools/docker/alpine/Readme.md) for a more reliable and
faster way to automatically build Linux images for v86.

(This document partly also applies to other Linuxes)

Choosing an installer ISO
Expand Down
32 changes: 13 additions & 19 deletions tools/docker/alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
FROM i386/alpine:3.18.6
FROM docker.io/i386/alpine:3.19.1

ENV KERNEL=lts
ENV HOSTNAME=localhost
ENV ROOT_PASSWORD='root'
ENV ADDPKGS=''
ENV ADDPKGS=nodejs

RUN apk add openrc \
alpine-base \
agetty \
alpine-conf \
$ADDPKGS

# Install mkinitfs from edge (todo: remove this when 3.19+ has worked properly with 9pfs)
RUN apk add mkinitfs --no-cache --allow-untrusted --repository https://dl-cdn.alpinelinux.org/alpine/edge/main/
RUN apk add openrc alpine-base agetty alpine-conf $ADDPKGS

RUN if [ "$KERNEL" == "lts" ]; then \
apk add linux-lts \
Expand All @@ -22,21 +13,24 @@ else \
apk add linux-$KERNEL; \
fi

RUN sed -i 's/getty 38400 tty1/agetty --autologin root tty1 linux/' /etc/inittab && \
echo "root:$ROOT_PASSWORD" | chpasswd
RUN sed -i 's/getty 38400 tty1/agetty --autologin root tty1 linux/' /etc/inittab
RUN echo 'ttyS0::respawn:/sbin/agetty --autologin root -s ttyS0 115200 vt100' >> /etc/inittab
RUN echo "root:" | chpasswd

RUN setup-hostname $HOSTNAME
RUN setup-hostname localhost

# Adding networking.sh script (works only on lts kernel yet)
RUN if [ "$KERNEL" == "lts" ]; then \
echo -e "rmmod ne2k-pci && modprobe ne2k-pci\nhwclock -s\nsetup-interfaces -a -r" > /root/networking.sh && \
chmod +x /root/networking.sh; \
RUN if [ "$KERNEL" == "lts" ]; then \
echo -e "rmmod ne2k-pci && modprobe ne2k-pci\nhwclock -s\nsetup-interfaces -a -r" > /root/networking.sh && \
chmod +x /root/networking.sh; \
fi

RUN echo 'console.log("Hello, world!");' > /root/hello.js

# https://wiki.alpinelinux.org/wiki/Alpine_Linux_in_a_chroot#Preparing_init_services
RUN for i in devfs dmesg mdev hwdrivers; do rc-update add $i sysinit; done
RUN for i in hwclock modules sysctl hostname syslog bootmisc; do rc-update add $i boot; done
RUN rc-update add killprocs shutdown

# Generate initramfs with 9p modules
RUN mkinitfs -F "ata base ide scsi virtio ext4 9p" $(cat /usr/share/kernel/$KERNEL/kernel.release)
RUN mkinitfs -F "ata base ide scsi virtio ext4 9p" $(cat /usr/share/kernel/$KERNEL/kernel.release)
10 changes: 4 additions & 6 deletions tools/docker/alpine/Readme.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
You can build a Alpine Linux 9p image using Docker:

1. As needed, kernel flavor (`virt` is smaller than `lts`, but don't have networking) and set of additional packages (community repo is enabled by default) can be edited in `Dockerfile`.
2. Run `./start-container.sh` with started dockerd.
3. Configure V86 options (you can use `examples/arch.html` or `examples/debian.html` as template) or add profile in `src/browser/main.js` (see `tools/docker/debian/Readme.md`) and run local webserver (`make run`).
1. As needed, kernel flavor (`virt` is smaller than `lts`, but don't have networking) and set of additional packages (community repo is enabled by default) can be edited in `Dockerfile`
2. Run `./start-container.sh` with started dockerd (podman works)
3. Configure V86 options (you can use `examples/arch.html` or `examples/debian.html` as template) or add profile in `src/browser/main.js` (see `tools/docker/debian/Readme.md`) and run local webserver (`make run`)

```js
filesystem: {
baseurl: "../images/alpine-rootfs-flat",
basefs: "../images/alpine-fs.json"
},

bzimage_initrd_from_filesystem: true,

cmdline: [
"rw",
"root=host9p rootfstype=9p rootflags=trans=virtio,cache=loose",
"root=host9p rootfstype=9p rootflags=trans=virtio,cache=loose modules=virtio_pci",
"tsc=reliable nowatchdog"
].join(" ")
```
8 changes: 5 additions & 3 deletions tools/docker/alpine/build-container.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
set -veu
set -euo pipefail

IMAGES="$(dirname "$0")"/../../../images
OUT_ROOTFS_TAR="$IMAGES"/alpine-rootfs.tar
Expand All @@ -16,12 +16,14 @@ docker create --platform linux/386 -t -i --name "$CONTAINER_NAME" "$IMAGE_NAME"
docker export "$CONTAINER_NAME" -o "$OUT_ROOTFS_TAR"

# https://github.com/iximiuz/docker-to-linux/issues/19#issuecomment-1242809707
tar -f "$OUT_ROOTFS_TAR" --delete ".dockerenv"
tar -f "$OUT_ROOTFS_TAR" --delete ".dockerenv" || true

"$(dirname "$0")"/../../../tools/fs2json.py --out "$OUT_FSJSON" "$OUT_ROOTFS_TAR"

# Note: Not deleting old files here
mkdir -p "$OUT_ROOTFS_FLAT"
"$(dirname "$0")"/../../../tools/copy-to-sha256.py "$OUT_ROOTFS_TAR" "$OUT_ROOTFS_FLAT"

echo "$OUT_ROOTFS_TAR", "$OUT_ROOTFS_FLAT" and "$OUT_FSJSON" created.
echo "$OUT_ROOTFS_TAR", "$OUT_ROOTFS_FLAT" and "$OUT_FSJSON" created.

# TODO: auto-build state, add examples/alpine.html

0 comments on commit 9286ca8

Please sign in to comment.