Qemu-simple: Difference between revisions

From Alpine Linux
(improve test, add resolv.conf)
(add about other iso images types)
 
(3 intermediate revisions by the same user not shown)
Line 4: Line 4:


=== Objective ===
=== Objective ===
# Install Alpinelinux.
# Install Alpine Linux.
# Install Qemu and its dependencies.
# Install Qemu and its dependencies.
# Download Alpinelinux ISO and required files.
# Download Alpine Linux ISO and required files.
# Start a Qemu instance of Alpinelinux ISO.
# Start a Qemu instance of Alpine Linux ISO.
# Test basic networking.
# Test basic networking.


Line 17: Line 17:
# RAM: 8GB
# RAM: 8GB


==== Install Alpinelinux ====
==== Install Alpine Linux ====
# Diskless installs (Ram based)
# Diskless installs (Ram based)
# SYS installs
# SYS installs


{{tip| - for further setup to work correctly, its assumed that alpinelinux installed in done for version between ''v3.21.x and v3.22.x''}}
{{tip| - For further setup to work correctly, its assumed that Alpine Linux installed in done for version between ''v3.21.x and v3.22.x''}}


{{Pill||v3.21.x-v3.22.x|cadetblue|lightblue}}
{{Pill||v3.21.x-v3.22.x|cadetblue|lightblue}}
Line 29: Line 29:


{{Pill||v3.21.x-v3.22.x|cadetblue|lightblue}}
{{Pill||v3.21.x-v3.22.x|cadetblue|lightblue}}
==== Download Alpinelinux ISO and required files ====
==== Download Alpine Linux ISO and required files ====
{{Cmd2| # cd ~
{{Cmd2| # cd ~
  # wget https://cdn.alpinelinux.org/v3.22/releases/x86_64/alpine-extended-3.22.0-x86_64.iso
  # wget https://cdn.alpinelinux.org/v3.22/releases/x86_64/alpine-extended-3.22.0-x86_64.iso
}}
}}


==== Start a Qemu instance of Alpinelinux ISO ====
{{tip| - '''alpine-extended''' ISO should be used by new users, other images types i.e
'''alpine-virt''' and '''alpine-standard''' can also be used. Learn and use them as you go. See resource links below. }}
 
==== Start a Qemu instance of Alpine Linux ISO ====
# Basic setup (with ssh forwarding)
# Basic setup (with ssh forwarding)
# Basic tap setup
# Basic tap setup
Line 45: Line 48:
## Simple setup (manually)
## Simple setup (manually)
##  no root privileges needed
##  no root privileges needed
## QEMU emulator version 10.0.0 (alpinelinux) ####
## QEMU emulator version 10.0.0 (Alpine Linux) ####
## -------------------------------------------------
## -------------------------------------------------
ISO=alpine-extended-3.22.0-x86_64.iso
ISO=alpine-extended-3.22.0-x86_64.iso
Line 72: Line 75:
## Manual setup with defaults and no preset scripts
## Manual setup with defaults and no preset scripts
## Works in root
## Works in root
## QEMU emulator version 10.0.0+ (alpinelinux) ####
## QEMU emulator version 10.0.0+ (Alpine Linux) ####
## modprobe tun # needed if not loaded already
## modprobe tun # needed if not loaded already
## -------------------------------------------------
## -------------------------------------------------
Line 83: Line 86:


## ----
## ----
## on HOST
## on HOST (after QEMU has booted)
# ifconfig tap0 10.0.2.2
# ifconfig tap0 10.0.2.2
## on GUEST
## on GUEST
Line 103: Line 106:


== Resources ==
== Resources ==
# https://docs.alpinelinux.org/user-handbook/0.1a/Installing/medium.html#_image_type
# https://wiki.alpinelinux.org/wiki/QEMU
# https://wiki.alpinelinux.org/wiki/QEMU
# https://wiki.qemu.org/Documentation/Networking#How_to_get_SSH_access_to_a_guest
# https://wiki.qemu.org/Documentation/Networking#How_to_get_SSH_access_to_a_guest
# https://www.qemu.org/docs/master/system/invocation.html#hxtool-5
# https://www.qemu.org/docs/master/system/invocation.html#hxtool-5
# https://manned.org/pkg/alpine-3.22/qemu-doc
# https://manned.org/pkg/alpine-3.22/qemu-doc

Latest revision as of 10:07, 2 September 2025

Setup walkthrough

Basic setup that gets you going, you would still need to read main Qemu documentations for advanced features.

Objective

  1. Install Alpine Linux.
  2. Install Qemu and its dependencies.
  3. Download Alpine Linux ISO and required files.
  4. Start a Qemu instance of Alpine Linux ISO.
  5. Test basic networking.

Test bed

WIP

  • Describe here the test bed/setup used to run the scripts below.
  1. MODEL: Dell Laptop.
  2. CPU: Intel i5 3rd/4th generation with virtualization enabled.
  3. RAM: 8GB

Install Alpine Linux

  1. Diskless installs (Ram based)
  2. SYS installs
Tip: - For further setup to work correctly, its assumed that Alpine Linux installed in done for version between v3.21.x and v3.22.x

v3.21.x-v3.22.x

Install Qemu and its dependencies

# apk add qemu qemu-img qemu-system-x86_64 qemu-ui-gtk

# modprobe tun

v3.21.x-v3.22.x

Download Alpine Linux ISO and required files

# cd ~ # wget https://cdn.alpinelinux.org/v3.22/releases/x86_64/alpine-extended-3.22.0-x86_64.iso

Tip: - alpine-extended ISO should be used by new users, other images types i.e alpine-virt and alpine-standard can also be used. Learn and use them as you go. See resource links below.

Start a Qemu instance of Alpine Linux ISO

  1. Basic setup (with ssh forwarding)
  2. Basic tap setup

v3.21.x-v3.22.x

Basic setup (with ssh forwarding)
#!/bin/sh
## -------------------------------------------------
## Simple setup (manually)
##  no root privileges needed
## QEMU emulator version 10.0.0 (Alpine Linux) ####
## -------------------------------------------------
ISO=alpine-extended-3.22.0-x86_64.iso
qemu-system-x86_64 -enable-kvm -m 2048M -cdrom ${ISO} \
    -device virtio-net,netdev=net0 \
    -netdev user,id=net0,hostfwd=tcp::5555-:22 \
    -nographic -display curses \
    -boot d

## ----
## on GUEST
# ifconfig eth0 10.0.2.15
# route add default gw 10.0.2.2
# busybox ping 10.0.2.2
## assuming your HOST gateway is 192.168.1.1
# echo 'nameserver 192.168.1.1' > /etc/resolv.conf
# busybox ping alpinelinux.org
## -------------------------------------------------

v3.21.x-v3.22.x

Basic tap setup
#!/bin/sh
## -------------------------------------------------
## Manual setup with defaults and no preset scripts
## Works in root
## QEMU emulator version 10.0.0+ (Alpine Linux) ####
## modprobe tun # needed if not loaded already
## -------------------------------------------------
ISO=alpine-extended-3.22.0-x86_64.iso
qemu-system-x86_64 -enable-kvm -m 2048M -cdrom ${ISO} \
    -device virtio-net,netdev=nd0 \
    -netdev tap,id=nd0,ifname=tap0,script=no,downscript=no \
    -nographic -display curses \
    -boot d

## ----
## on HOST (after QEMU has booted)
# ifconfig tap0 10.0.2.2
## on GUEST
# ifconfig eth0 10.0.2.15
# route add default gw 10.0.2.2
## ----
## TEST (HOST) - IMPORTANT: remove firewall if any
# nc -l 1234 > filename.out
## TEST (GUEST)
# echo -e "aaa\nbbb" > test.txt
# nc 10.0.2.2 1234 < test.txt
## TEST (HOST)
# cat filename.out
## -------------------------------------------------

See also

Resources

  1. https://docs.alpinelinux.org/user-handbook/0.1a/Installing/medium.html#_image_type
  2. https://wiki.alpinelinux.org/wiki/QEMU
  3. https://wiki.qemu.org/Documentation/Networking#How_to_get_SSH_access_to_a_guest
  4. https://www.qemu.org/docs/master/system/invocation.html#hxtool-5
  5. https://manned.org/pkg/alpine-3.22/qemu-doc