Alpine Linux on QEMU with Persistent Storage

This blog provides a comprehensive guide to setting up Alpine Linux on QEMU with persistent storage and SSH access.

Dependencies

  1. Alpine Linux ISO
  2. QEMU

Getting Started

1. Create a Virtual Disk

To enable persistent storage, create a virtual hard disk:

qemu-img create -f qcow2 alpine-persistent.qcow2 10G

2. Run QEMU with ISO and Virtual Disk

Boot Alpine Linux with the installation ISO and attach the virtual disk:

qemu-system-x86_64 \
  -m 1024 \
  -smp 2 \
  -boot d \
  -cdrom alpine-standard-3.21.2-x86_64.iso \
  -drive file=alpine-persistent.qcow2,format=qcow2 \
  -net nic -net user,hostfwd=tcp::2222-:22 \
  -display gtk

3. Install Alpine Linux

  1. Login with the default credentials i.e. (root,<no_passwd>).
  2. Start the setup script via setup-alpine.
  3. When prompted to select a disk, choose sda (the attached virtual disk).
  4. Follow the setup instructions and confirm writing changes to disk.
  5. Once installation is complete, reboot the system.

4. Enable SSH (Optional)

SSH allows remote access to your VM from the host machine. Start the ssh service and enable for future connections.

rc-service sshd start
rc-update add sshd

You can now connect via SSH using:

ssh -p 2222 root@localhost

5. Boot Installed Alpine Linux

After installation, run QEMU without the ISO:

qemu-system-x86_64 \
  -m 1024 \
  -smp 2 \
  -drive file=alpine-persistent.qcow2,format=qcow2 \
  -net nic -net user,hostfwd=tcp::2222-:22 \
  -display gtk

Now, your Alpine Linux VM is fully set up with persistent storage and SSH access.


Go to top File an issue