Skip to content

Instantly share code, notes, and snippets.

@dudeitssm
Forked from oofnikj/answerfile
Created September 24, 2022 15:44
Show Gist options
  • Save dudeitssm/534506cf521e6f61b0a7a01e561bf524 to your computer and use it in GitHub Desktop.
Save dudeitssm/534506cf521e6f61b0a7a01e561bf524 to your computer and use it in GitHub Desktop.

Revisions

  1. @oofnikj oofnikj revised this gist Dec 19, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions docker-termux.md
    Original file line number Diff line number Diff line change
    @@ -79,6 +79,7 @@ qemu-system-aarch64 -machine virt -m 1024 -smp cpus=2 \
    * Install docker and enable on boot:
    ```
    alpine:~# apk update && apk add docker
    alpine:~# service docker start
    alpine:~# rc-update add docker
    ```

  2. @oofnikj oofnikj revised this gist Dec 19, 2020. 1 changed file with 63 additions and 57 deletions.
    120 changes: 63 additions & 57 deletions docker-termux.md
    Original file line number Diff line number Diff line change
    @@ -1,32 +1,35 @@
    # Docker on Termux [in a VM]

    Just kidding, we're cheating by creating a Linux VM and installing Docker in it. It actually runs at okay-ish speed.
    Create a Linux VM and install Docker in it so you can (slowly) run x86 Docker containers on your Android device.

    Recommended to use SSH or external keyboard to execute the following commands unless you want sore thumbs. See https://wiki.termux.com/wiki/Remote_Access#SSH

    * Install QEMU
    ```
    pkg install qemu-utils qemu-common qemu-system-x86_64-headless
    ```
    ```
    pkg install qemu-utils qemu-common qemu-system-x86_64-headless
    ```

    * Download Alpine Linux 3.12 (virt optimized) ISO
    ```
    mkdir alpine && cd $_
    wget http://dl-cdn.alpinelinux.org/alpine/v3.12/releases/x86_64/alpine-virt-3.12.0-x86_64.iso
    ```
    ```
    mkdir alpine && cd $_
    wget http://dl-cdn.alpinelinux.org/alpine/v3.12/releases/x86_64/alpine-virt-3.12.3-x86_64.iso
    ```

    * Create disk (note it won't actually take 4GB of space, more like 500MB)
    ```
    qemu-img create -f qcow2 alpine.img 4G
    ```
    ```
    qemu-img create -f qcow2 alpine.img 4G
    ```

    * Boot it up
    ```
    qemu-system-x86_64 -machine q35 -m 1024 -smp cpus=2 -cpu qemu64 \
    -drive if=pflash,format=raw,read-only,file=$PREFIX/share/qemu/edk2-x86_64-code.fd \
    -netdev user,id=n1,hostfwd=tcp::2222-:22 -device virtio-net,netdev=n1 \
    -cdrom alpine-virt-3.12.0-x86_64.iso \
    -nographic alpine.img
    ```
    ```
    qemu-system-x86_64 -machine q35 -m 1024 -smp cpus=2 -cpu qemu64 \
    -drive if=pflash,format=raw,read-only,file=$PREFIX/share/qemu/edk2-x86_64-code.fd \
    -netdev user,id=n1,hostfwd=tcp::2222-:22 -device virtio-net,netdev=n1 \
    -cdrom alpine-virt-3.12.3-x86_64.iso \
    -nographic alpine.img
    ```

    * Login with user `root` (no password)

    <!-- aarch64 is too slow ```
    qemu-system-aarch64 -machine virt -m 1024 -smp cpus=2 \
    @@ -36,45 +39,48 @@ qemu-system-aarch64 -machine virt -m 1024 -smp cpus=2 \
    -nographic alpine.img
    ``` -->

    * Run setup to install interactively:
    * Use `dhcp` for networking
    * Choose `sys` for drive partition type
    * Install `dropbear` SSH

    ```
    setup-alpine
    ```

    * Shut down and boot again without `cdrom`:

    ```
    qemu-system-x86_64 -machine q35 -m 1024 -smp cpus=2 -cpu qemu64 \
    -drive if=pflash,format=raw,read-only,file=$PREFIX/share/qemu/edk2-x86_64-code.fd \
    -netdev user,id=n1,hostfwd=tcp::2222-:22 -device virtio-net,netdev=n1 \
    -nographic alpine.img
    ```

    * Install pkgs with `apk add ...`

    * enable community repo:
    ```
    sed -i -E 's@^#(.*alpine/v[0-9.]+/community)$@\1@g' /etc/apk/repositories
    apk update
    ```

    * Install and enable docker on boot:
    ```
    apk add docker
    rc-update add docker
    ```

    * Console output
    * add `console=tty0 console=ttyS0,115200` to default options in `/etc/default/grub` and rebuild grub config:
    ```
    sed -i 's/quiet //g' /etc/default/grub
    sed -i -E 's/(GRUB_CMDLINE_LINUX_DEFAULT=".*)"/\1 console=tty0 console=ttyS0,115200"/g' /etc/default/grub
    grub-mkconfig -o /boot/grub/grub.cfg
    ```
    * Setup network (press Enter to use defaults):
    ```
    localhost:~# setup-interfaces
    Available interfaces are: eth0.
    Enter '?' for help on bridges, bonding and vlans.
    Which one do you want to initialize? (or '?' or 'done') [eth0]
    Ip address for eth0? (or 'dhcp', 'none', '?') [dhcp]
    Do you want to do any manual network configuration? [no]
    localhost:~# ifup eth0
    ```

    * Create an answerfile to speed up installation:

    ```
    localhost:~# wget https://gist.github.com/oofnikj/e79aef095cd08756f7f26ed244355d62/raw/answerfile
    ```

    * Patch `setup-disk` to enable serial console output on boot

    ```
    localhost:~# sed -i -E 's/(local kernel_opts)=.*/\1="console=ttyS0"/' /sbin/setup-disk
    ```

    * Run setup to install to disk
    ```
    localhost:~# setup-alpine -f answerfile
    ```

    * Once installation is complete, power off the VM (command `poweroff`) and boot again without cdrom:

    ```
    qemu-system-x86_64 -machine q35 -m 1024 -smp cpus=2 -cpu qemu64 \
    -drive if=pflash,format=raw,read-only,file=$PREFIX/share/qemu/edk2-x86_64-code.fd \
    -netdev user,id=n1,hostfwd=tcp::2222-:22 -device virtio-net,netdev=n1 \
    -nographic alpine.img
    ```

    * Install docker and enable on boot:
    ```
    alpine:~# apk update && apk add docker
    alpine:~# rc-update add docker
    ```

    * Useful keys:
    * Ctrl+a x: quit emulation
  3. @oofnikj oofnikj revised this gist Dec 19, 2020. 1 changed file with 15 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions answerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    KEYMAPOPTS="us us"
    HOSTNAMEOPTS="-n alpine"
    INTERFACESOPTS="auto lo
    iface lo inet loopback

    auto eth0
    iface eth0 inet dhcp
    hostname alpine
    "
    TIMEZONEOPTS="-z UTC"
    PROXYOPTS="none"
    APKREPOSOPTS="http://dl-cdn.alpinelinux.org/alpine/v3.12/main http://dl-cdn.alpinelinux.org/alpine/v3.12/community"
    SSHDOPTS="-c openssh"
    NTPOPTS="-c busybox"
    DISKOPTS="-v -m sys -s 0 /dev/sda"
  4. @oofnikj oofnikj revised this gist Dec 10, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion docker-termux.md
    Original file line number Diff line number Diff line change
    @@ -45,7 +45,7 @@ qemu-system-aarch64 -machine virt -m 1024 -smp cpus=2 \
    setup-alpine
    ```

    * Shut down and boot again without `cdrom`, now with port forwarding:
    * Shut down and boot again without `cdrom`:

    ```
    qemu-system-x86_64 -machine q35 -m 1024 -smp cpus=2 -cpu qemu64 \
  5. @oofnikj oofnikj revised this gist Dec 10, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions docker-termux.md
    Original file line number Diff line number Diff line change
    @@ -22,6 +22,7 @@ qemu-img create -f qcow2 alpine.img 4G
    ```
    qemu-system-x86_64 -machine q35 -m 1024 -smp cpus=2 -cpu qemu64 \
    -drive if=pflash,format=raw,read-only,file=$PREFIX/share/qemu/edk2-x86_64-code.fd \
    -netdev user,id=n1,hostfwd=tcp::2222-:22 -device virtio-net,netdev=n1 \
    -cdrom alpine-virt-3.12.0-x86_64.iso \
    -nographic alpine.img
    ```
  6. @oofnikj oofnikj created this gist Aug 23, 2020.
    80 changes: 80 additions & 0 deletions docker-termux.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,80 @@
    # Docker on Termux [in a VM]

    Just kidding, we're cheating by creating a Linux VM and installing Docker in it. It actually runs at okay-ish speed.

    * Install QEMU
    ```
    pkg install qemu-utils qemu-common qemu-system-x86_64-headless
    ```

    * Download Alpine Linux 3.12 (virt optimized) ISO
    ```
    mkdir alpine && cd $_
    wget http://dl-cdn.alpinelinux.org/alpine/v3.12/releases/x86_64/alpine-virt-3.12.0-x86_64.iso
    ```

    * Create disk (note it won't actually take 4GB of space, more like 500MB)
    ```
    qemu-img create -f qcow2 alpine.img 4G
    ```

    * Boot it up
    ```
    qemu-system-x86_64 -machine q35 -m 1024 -smp cpus=2 -cpu qemu64 \
    -drive if=pflash,format=raw,read-only,file=$PREFIX/share/qemu/edk2-x86_64-code.fd \
    -cdrom alpine-virt-3.12.0-x86_64.iso \
    -nographic alpine.img
    ```


    <!-- aarch64 is too slow ```
    qemu-system-aarch64 -machine virt -m 1024 -smp cpus=2 \
    -cpu cortex-a57 -bios QEMU_EFI.fd \
    -netdev user,id=n1 -device virtio-net,netdev=n1 \
    -cdrom alpine-virt-3.12.0-aarch64.iso \
    -nographic alpine.img
    ``` -->

    * Run setup to install interactively:
    * Use `dhcp` for networking
    * Choose `sys` for drive partition type
    * Install `dropbear` SSH

    ```
    setup-alpine
    ```

    * Shut down and boot again without `cdrom`, now with port forwarding:

    ```
    qemu-system-x86_64 -machine q35 -m 1024 -smp cpus=2 -cpu qemu64 \
    -drive if=pflash,format=raw,read-only,file=$PREFIX/share/qemu/edk2-x86_64-code.fd \
    -netdev user,id=n1,hostfwd=tcp::2222-:22 -device virtio-net,netdev=n1 \
    -nographic alpine.img
    ```

    * Install pkgs with `apk add ...`

    * enable community repo:
    ```
    sed -i -E 's@^#(.*alpine/v[0-9.]+/community)$@\1@g' /etc/apk/repositories
    apk update
    ```

    * Install and enable docker on boot:
    ```
    apk add docker
    rc-update add docker
    ```

    * Console output
    * add `console=tty0 console=ttyS0,115200` to default options in `/etc/default/grub` and rebuild grub config:
    ```
    sed -i 's/quiet //g' /etc/default/grub
    sed -i -E 's/(GRUB_CMDLINE_LINUX_DEFAULT=".*)"/\1 console=tty0 console=ttyS0,115200"/g' /etc/default/grub
    grub-mkconfig -o /boot/grub/grub.cfg
    ```

    * Useful keys:
    * Ctrl+a x: quit emulation
    * Ctrl+a h: toggle QEMU console