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.
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
-enable-kvm toggles support for, well, KVM: kernel-based
virtual machine.
-m specifies the amount of memory in megabytes to grant
the virtual system.
-nic stands for network interface controller. QEMU
provides this option as a shortcut to configure both the guest OS
virtual NIC hardware and its communication with the host network.
user indicates the virtual machine may use the host
network for the current user of the host machine, and
model=virtio enables QEMU to use the Linux virtio kernel
module for faster speeds. Although QEMU automatically selects the
associated model of the machine emulated, it's recommended to specify
the option manually because it's subject to change in future releases
according to documentation. Use -nic none to disable
networking devices entirely.
-drive specifies which file to use as the disk for the
virtual machine and virtio, again, enables faster speeds.
-cdrom passes the Alpine Linux ISO as a CD in a virtual
drive. It's needed to boot the installation medium, but it should not
be specified after a successful install. Otherwise, the virtual machine
boots into the installation medium instead of the newly installed
instance of Alpine
Linux.
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.
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.