Alpine Linux on QEMU

With Drew DeVault's directions as motivator and guide, I installed Alpine Linux through QEMU. At first, I experienced some trouble: I read the documentation poorly.

I ran setup-alpine with flag -q, for a quick install, and it is quick, especially under KVM on Linux. However, the system failed to boot upon restart.

QEMU

I presumed it was an issue with QEMU. No, I'm not sure of my rationale myself, but I suppose it pertained to my rather large knowledge gap here. Although I've used QEMU in the past to write a small OS -- well, more a bootleg bootloader with a tiny kernel rather than an OS -- I only scraped the surface of the capability, power, and options of this software. I also used it to hack on SerenityOS last summer, but its configuration was entirely automated with scripts.

To initialize storage for the virtual machine, I used the command below. It creates a qcow2 file 8 gigabytes in size.

      $ qemu-img create -f qcow2 alpine.qcow2 8G 
    

qcow2 (QEMU Copy on Write) is native to QEMU. It also only uses as much storage as it currently requires, bounded by the file size set with qemu-img. To expand this size if necessary, in this case an additional 8G, run:

      $ qemu-img resize alpine.qcow2 +8G
    

It's necessary to resize the partition and update the file system in the VM afterward to use this newly allocated space. QEMU allows the shrinking of an image as well, though it may cause loss of data, and whether shrinking or expanding the image, the virtual machine must remain off. It's also possible to run QEMU in snapshot mode, where changes must be explicitly committed to this file to save them across sessions. Specify -snapshot as a flag to do so, and commit changes with commit all in QEMU monitor.

Next, I booted the virtual machine for the first time with the following command:

      
        $ qemu-system-x86_64 \
        > -enable-kvm \
        > -m 2048 \
        > -nic user,model=virtio \
        > -drive file=alpine.qcow2,media=disk,if=virtio \
        > -cdrom alpine-standard-3.8.0-x86_64.iso
      
    

When I attempted to reboot, the machine failed to start the system I thought I installed. I tried this several times to no avail -- both reboot and reinstallation. I realized, eventually, that setup-alpine -q does not automatically configure drives for the system, and that's very reasonable: If I were installing on physical hardware, I'd be skeptical of any automatic formatting and partitioning of my drives without confirmation as well.

To configure disks and install a bootloader, use setup-disk. It's a convenient script similar to setup-alpine provided by the developers. In fact, when a user runs setup-alpine without flag -q, setup-alpine calls setup-disk at some point anyway. It prompts the selection of a disk and automatically creates the standard partitions: boot, root, and swap. For more control, the Alpine documentation recommends partitioning with parted.

Alpine Linux

I remember fiddling with Alpine Linux some time ago, but I struggled even more because I felt the documentation lacked both breadth and depth. Today, the documentation proves better because it not only includes more topics, but its entries contain more clear explanations and straightforward examples. I appreciate these improvements a lot, and it's the first thing I noticed this time around -- decent documentation goes a long way.

As a minimalist system, Alpine ships without the standard Linux environment I expect on a workstation, but it installable without any hassle. The following two commands install a slew of utilities and their respective documentation:

      
        # apk add sed dialog bash bash-completion grep util-linux \
        > pciutils usbutils binutils findutils readline lsof less curl file \
        > man-pages mandoc mandoc-apropos
        # apk add docs
      
    

According to documentation, docs serves as a catch-all for any separate existing documentation subpackages for any packages already installed on the system. For example, given thispkg and thatpkg were previously installed without their corresponding documentation subpackages, then apk add docs installs thispkg-doc and thatpkg-doc.

Lastly, credit again to Drew DeVault and the documentation for Alpine Linux and QEMU.