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
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
Login with the default credentials i.e. (root,<no_passwd>).
Start the setup script via
setup-alpine
.When prompted to select a disk, choose sda (the attached virtual disk).
Follow the setup instructions and confirm writing changes to disk.
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.
Subscribe to my newsletter
Read articles from Nosferatu directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Nosferatu
Nosferatu
Hey there, I am लक्ष्य (lakshay) which means "target" or "aim" in Hindi. A Manga and Music Enthusiast, and most importantly a Recreational Programmer. Have interest in almost anything and everything; android, open source, systems programming, manga, anime, linguistics, music, philosophy, mathematics, physics, science in general, chess, volleyball, history, books, archaeology, arts, and loves to read & write about the stuff I love…