Page History

Alpine Disk Image

Mark George edited this page on 8 May 2022

Clone this wiki locally

Installing in single partition (for use as a VM guest)

Installing Alpine in a single partition is a bit of a PITA since the installer always creates boot and swap partitions if you let it prepare the disk. A single partition is worth doing since it makes it easier to shrink the VDI. I finally managed to do it, so here is what I did:

Start with the VM install image since it is tiny (38MB).

  1. Boot the install ISO.
  2. Run fdisk and create the partition on /dev/sda. Use the entire disk. Make it bootable
  3. Check if /dev/sda1 exists, and if not reboot from the ISO again.
  4. Set up enough to get apk add working:
    1. Disable IPv6 since it will be used by default and things will break (even in 2021...!!).
      sysctl net.ipv6.conf.all.disable_ipv6=1
    2. setup-interfaces
    3. rc-service networking start
    4. setup-apkrepos
  5. Install e2fsprogs.
    apk add e2fsprogs
  6. Format /dev/sda1. Make sure it uses the 32 bit layout since syslinux is a bit crap (you need to do this even with 64 bit guest images):
    mkfs.ext4 -O ^64bit -m 1 -L alpine /dev/sda1
  7. Reboot from the install ISO again.
  8. Mount the partition at /mnt. Explicitly set the FS type using -t ext4:
    mount -t ext4 /dev/sda1 /mnt
  9. Create /boot in the mounted FS:
    mkdir /mnt/boot
  10. Run the installer using setup-alpine. If asked about disks, answer none (it might not ask since the only disk is already mounted). Also answer none for configs and APK cache.
  11. Run setup-disk to install the base image:
    setup-disk -m sys /mnt
  12. Install bootloader in MBR:
    dd bs=440 count=1 conv=notrunc if=/usr/share/syslinux/mbr.bin of=/dev/sda
  13. Reboot in installed partition.
  14. Install e2fsprogs so that fsck can check the disk on start-up:
    apk add --no-cache e2fsprogs

VirtualBox Guest Additions

Install via APK rather than the VirtualBox ISO.

  1. Enable the 'community' repo in /etc/apk/repositories.
  2. Install:
    apk add --no-cache virtualbox-guest-additions virtualbox-guest-modules-virt
  3. Add the modules to /etc/modules so that they load on start-up:
    echo vboxguest >> /etc/modules
    echo vboxsf >> /etc/modules
  4. Add the service to the default run-level so that it will start on boot:
    rc-update add virtualbox-guest-additions

This will allow shared folders to be auto-mounted.



apk add docker
apk add docker-compose

Enable on start-up:

rc-update add docker


Colour prompt

mv /etc/profile.d/color_prompt /etc/profile.d/


Create /etc/profile.d/, with the following contents:

alias ls='ls -ahp --color=auto --group-directories-first'
alias ll='ls -l'

Shrinkifying the VDI

  1. Remove any crap you don't need.
  2. Reboot off the install ISO (have ISO attached, and hit F12 at boot).
  3. Set up enough to get apk add working:
    1. setup-interfaces
    2. rc-service networking start
    3. setup-apkrepos
  4. Enable the edge testing repo in /etc/apk/repositories.
  5. Install zerofree.
  6. Run zerofree to zero the free space:
    zerofree -v /dev/sda1
  7. Shut down VM.
  8. Shrink VDI using:
    VBoxManage modifymedium disk "<path to VDI>" --compact