Skip to content

Instantly share code, notes, and snippets.

@pojntfx
Last active June 29, 2022 20:04
Show Gist options
  • Save pojntfx/9ed00ff118fc1894abc83061491c252f to your computer and use it in GitHub Desktop.
Save pojntfx/9ed00ff118fc1894abc83061491c252f to your computer and use it in GitHub Desktop.
Cattle Alpine Linux in QEMU (based on custom image)

Also see https://gist.github.com/pojntfx/6d81b9ebe8b801e024d81fa9f3f3a4b2 for a pet Alpine Linux in QEMU

Build image

# If you like to use Docker
docker run --privileged -it alpine:edge sh
apk add alpine-make-vm-image
cd /tmp
# Now add the files from below
alpine-make-vm-image --image-format qcow2 --image-size 250M --repositories-file ./repositories --packages "$(cat ./packages)" --script-chroot ./alpine.qcow2 ./configure.sh

Copy to host and resize

# Copy to host
scp -P 10022 root@localhost:/tmp/alpine.qcow2 ~/Downloads/felix-pojtingers-alpine-linux-distribution.qcow2 # or `docker cp`
# Resize
qemu-img resize ~/Downloads/felix-pojtingers-alpine-linux-distribution.qcow2 +20G

Launch on host and resize filesystem

# Launch on host (exit with CTRL - A - X)
qemu-system-x86_64 -accel hvf -m 2048 -nographic -nic user,hostfwd=tcp::20022-:22 -boot d -drive format=qcow2,file=$HOME/Downloads/felix-pojtingers-alpine-linux-distribution.qcow2

# Connect and resize filesystem
ssh -p 20022 root@localhost "resize2fs /dev/sda"

Access services in the VM from host

# Example: Run Theia in Docker
apk add docker
rc-update add docker
rc-service docker start
docker run -d -it -p 3000:3000 theiaide/theia:next

# Forward VM localhost:3000 to host 0.0.0.0:23000
ssh -p 20022 -L 0.0.0.0:23000:localhost:3000 root@localhost
#!/bin/sh
setup-timezone -z UTC
cat <<-EOF >/etc/network/interfaces
iface lo inet loopback
iface eth0 inet dhcp
EOF
cat <<EOF >/etc/motd
Welcome to Felix Pojtinger's Alpine Linux Distribution!
EOF
mkdir -m 700 -p /root/.ssh
wget -O - https://github.com/pojntfx.keys | tee /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
ln -s networking /etc/init.d/net.lo
ln -s networking /etc/init.d/net.eth0
rc-update add sshd default
rc-update add net.eth0 default
rc-update add net.lo boot
echo 'AllowTcpForwarding yes' >> /etc/ssh/sshd_config
openssh
sudo
curl
e2fsprogs-extra
http://dl-cdn.alpinelinux.org/alpine/edge/main
http://dl-cdn.alpinelinux.org/alpine/edge/community
http://dl-cdn.alpinelinux.org/alpine/edge/testing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment