Welcome to the Slackware Documentation Project

Qemu Support in Slackware ARM

This document describes the process of installing Slackwarearm inside of QEMU.

  • QEMU is a full system emulator that can emulate a range of real hardware architectures. In this case we will use QEMU to emulate the ARM Ltd. “Versatile Express” development board.
  • QEMU provides a platform to allow an operating system to believe that it is running on real hardware.
  • QEMU runs on your Intel-based Slackware PC/server (in most cases this will be a desktop machine, but it is possible to run QEMU on a headless server and use VNC for graphics).

Who is Slackware ARM in QEMU aimed at?

The aim of installing Slackware ARM inside QEMU is to allow people who do not have ARM hardware to try out Slackware ARM.

While QEMU is an excellent emulator, it is very slow compared to real ARM hardware. QEMU was used for approximately a year to develop most of Slackware ARM version 12.2. Due to the slow speed of QEMU, distcc can be used on several x86 machines to speedup compilations. It's possible to effectively use Slackware ARM in QEMU, however be aware that it will not present the best user experience due to its lack of speed. Ideally Slackware ARM should be run on real ARM hardware.

This document is a work in progress and it targets the development release of Slackware ARM, Slackwarearm-current.

Documentation for Slackware ARM 14.0, 14.1, and 14.2, can be found here:

Installation Environment Assumptions

Several assumptions are made to aid in writing this document.

  • The host machine is running a full installation of Slackware x86 or x86_64
  • You have root access on the host machine and can compile software
  • The Slackware host and QEMU emulator are on a secure Local Area Network
  • The host machine has the address 192.168.1.1 and the network has the CIDR value of 192.168.1.0/24
  • You can export a Network File System file share on the host machine that shares the Slackware ARM tree with the QEMU guest
  • The root directory of the exported NFS share on the host is located at /export
These guidelines can be met with one Slackware x86/x86_64 host machine. This single host machine can serve the NFS content, as well as host the Slackware ARM installation inside QEMU.

Slackware x86 Host Prerequisites

  1. Download the Slackwarearm distribution package tree with rsync
  2. Populate a location with the Slackware ARM QEMU files
  3. Configure the Network File Server (NFS) on the Slackware x86 Host
  4. Install QEMU and the device-tree-compiler software on the Slackware x86 host
  5. Configure QEMU Permissions on the Slackware x86 Host
  6. Create the QEMU disk image using the helper scripts

Download Slackware ARM

Download Slackware ARM to your Slackware x86 Host. In this tutorial rsync is used to mirror Slackware ARM. Before running rsync, make your user has read, write, and execute permissions within the /export directory.

mkdir -p /export/slackwarearm
cd /export/slackwarearm
rsync --exclude '*/source/*' --delete -Pavv ftp.arm.slackware.com::slackwarearm/$SLACKREL .

If you wish to use a web browser, wget, or lftp to download Slackware ARM, the mirror is here.

The $SLACKREL variable refers to the Slackware ARM tree you downloaded. If you chose Slackwarearm-14.2, the rsync URL will be ftp.arm.slackware.com::slackwarearm/slackwarearm-14.2

Populate Slackware ARM Files and Directories

In order to boot the Slackware ARM installer you need to create a directory that stores the Kernel and Initial RAM disk. You also need a few helper scripts to run QEMU. In this totorial, all of these files will be stored in /export/armhost.

Copy the kernel and RAM disk:

mkdir -p /export/armhost
cp -fa /export/slackwarearm/$SLACKREL/kernels/armv7/{zImage*,initrd*,dtb} /export/armhost/
cp -fa /export/slackwarearm/$SLACKREL/isolinux/initrd-armv7.img /export/armhost/

Download and copy the QEMU helper scripts:

# cd /tmp ; mkdir qemu ; cd qemu
# rsync -Prlvv --delete ftp.arm.slackware.com::slackwarearm/boardsupport/qemu/$SLACKREL .
# cd $SLACKREL
# cp -fav helper-scripts/* /export/armhost/

You can find the helper scripts here if you do not wish to use rsync to download them.

The $SLACKREL variable refers to the Slackware ARM tree you downloaded. If you chose Slackwarearm-14.2, the path will be /export/slackwarearm/slackwarearm-14.2. The rsync URL for the QEMU helper scripts will be ftp.arm.slackware.com::slackwarearm/boardsupport/qemu/slackwarearm-14.2

Configure Network File System services

The Slackware x86 host needs to be configured appropriately in order to run the Slackwarearm installation process within QEMU. The easiest and most efficient way to do so is by setting up a Network File System (NFS) share on the host machine. This NFS share will be used by the Slackwarearm client (running inside QEMU) to access the Slackware distribution package tree on the host. NFS services are not the only way to serve the Slackware distribution package tree to the QEMU client. Other methods are quite a bit slower when used with QEMU emulated networking. As a result, the NFS service has been chosen for this tutorial.

With a text editor, as root, add the following to Slackware host's /etc/exports:

/export/slackwarearm xxx.xxx.xxx.x/255.255.255.0(insecure,ro,nohide,root_squash,sync,no_subtree_check)

Replace xxx.xxx.x.x/255.255.255.0 with 192.168.1.0/255.255.255.0 if you are going to use the same network settings described in this guide. If you are using a different netmask, you must configure your NFS share to allow access by adding a different mount point on the network.

QEMU guest network settings are described later in this guide. One such option for QEMU network settings is NAT mode. NAT mode allows direct access to the Slackware x86 host NFS share through the loop back interface. If you plan to use NAT mode, you need to use the following NFS share mount point:

# NAT mode settings
/export/slackwarearm 127.0.0.1(insecure,ro,nohide,root_squash,sync,no_subtree_check)

Finally, enable the new NFS share by executing the following as root:

# chmod +x /etc/rc.d/{rc.rpc,rc.nfsd}
# /etc/rc.d/rc.nfsd
# exportfs -va
It is possible, though not recommended, to use the Apache web server or the vsftpd FTP daemon to serve the Slackware ARM tree to the QEMU client. Testing concluded that NFS services are the better choice.

Install QEMU and device-tree-compiler

Installing SlackBuilds is not apart of the scope of this article. If you need assistance with installing QEMU or device-tree-compiler, please refer to the SlackBuilds.org HOWTO page. With that said, there are a few recommendations:

  • If you are running Slackware-current you can install QEMU and skip installing the device-tree-compiler package. Slackware-current already includes the device-tree-compiler package in a full installation.
  • Please be certain that you did a full Slackware installation on your x86 host prior to installing these SlackBuilds.
  • Slackware 14.0, 14.1, and 14.2 users need to install the device-tree-compiler package from SlackBuilds.org prior to installing QEMU.
  • You can download and install QEMU from SlackBuilds.org.
  • You will not have the ability on 14.0, 14.1, and 14.2 systems to emulate the ARM architecture in QEMU if you do not first install the device-tree-compiler package.

QEMU Permissions

There are a few permissions that need to be set once you have successfully installed QEMU on your system. The QEMU client will be launched by running the /usr/bin/qemu-system-arm binary. This binary needs root permissions in order to be executed. You can run this binary with sudo by editing /etc/sudoers. Using sudo is the most secure option if you have multiple users on your system. If you are the only user on your system then setting the setuid permission as root is sufficient. Adjusting these permissions will allow a normal user to configure and boot the QEMU guest without logging in as root.

Setting the setuid root permission requires that you log in as root. As root execute the following commands:

# chmod +s /usr/bin/qemu-system-arm

If you plan to configure QEMU to use a network bridge, you also need to set the setuid root permission for /sbin/ifconfig and /sbin/brctl.

# chmod +s /sbin/{ifconfig,brctl}

Create QEMU Disk Image

Prior to booting the Slackware ARM installer in QEMU, you must create a disk image that acts as an emulated SD Card. This disk image is used to emulate the MMC controller in Slackware ARM. Earlier you copied the Slackware ARM helper scripts to /export/armhost/. Within this directory there is a script, makeimg. This script creates a 15GB disk image automatically in /export/armhost/ when it is executed. Initially all you need to do is run this script.

Switch to the directory where you copied the helper scripts and execute makeimg:

cd /export/armhost
./makeimg

For reference, this is the makeimg script:

# Create the QEMU disk image - the emulated SD card.

IMG=sdcard.img
SIZE=15G

rm -f $IMG
qemu-img \
   create \
   $IMG $SIZE
Be aware that once you have installed Slackware ARM onto this disk image you must move it to a different directory for storage, or you risk it being destroyed when makeimg is executed at a later time.

QEMU Network Settings

This section covers the process of setting up QEMU guest networking. Two different processes will be described. Network Address Translation mode (NAT) is the first and easiest way to get a functional network in QEMU guests. The second is bridged mode. The difference between the two is that NAT mode does not allow direct access to the Slackware x86 host's physical network and bridged mode does. It is best to use bridged mode if you plan on doing any more advanced network operations that require full access to the host and the host's physical network.

There are many different ways to configure QEMU guest networking. This document will only cover the QEMU functionality required to boot Slackware ARM. Refer to the QEMU man pages or the QEMU documentation if you need further explanation.

Later on when you boot the Slackware ARM installer in QEMU you may need to modify the txqueuelen for your network interfaces. This is because large Slackware packages time out while being downloaded from the NFS share on the host. This happens because QEMU emulation is very slow. The NFS daemon on your host machine simply shuts down the network socket before large packages (rust, kernel-firmware, etc) finish being copied to the SD Card. Setting the txqueuelen to 10000 for all network interfaces should be sufficient to prevent this anomaly. The following commands seem to resolve this issue:
ip link set br0 txqueuelen 10000
ip link set eth0 txqueuelen 10000
ip link set lo txqueuelen 10000
ip link set tap0 txqueuelen 10000

QEMU NAT Mode Networking

NAT mode does not require any additional configuration on the Slackware x86 host machine or in the QEMU guest machine. You can launch the Slackware ARM installer within QEMU using the following command:

# cd /export/armhost
# qemu-system-arm -nographic \
   -m 1024 \
   -M vexpress-a9 \
   -k en-us \
   -net nic \
   -net user \
   -rtc base=localtime \
   -no-reboot \
   -sd sdcard.img \
   -initrd initrd-armv7.img \
   -kernel zImage-armv7 \
   -dtb dtb/vexpress-v2p-ca9.dtb \
   -append "TERM=xterm-256color vmalloc=256MB console=ttyAMA0,115200n8 nofont nic=auto:eth0:dhcp root=/dev/ram rw"

The -net nic and -net user options enable QEMU to start the Slackwarearm guest with NAT mode networking enabled.

By default QEMU launches guests with the IP address 10.0.2.15 in NAT mode. The Slackware x86 host is the gateway, at IP address 10.0.2.2. The host machine and the guest machine will have full network access between the two. The downside of NAT mode is that the QEMU guest will not have internet access.

You will need to edit the NFS share on the Slackware x86 host so that it mounts the share at 127.0.0.1. The QEMU guest will then have access to the Slackwarearm package tree.

QEMU Bridged Mode Networking

There are two ways to set up bridged mode networking. The method you choose depends on your existing network configuration. The first method uses the existing Slackware init scripts. The Slackware init scripts will create the network bridge and enable the QEMU guest's NIC in the form of a tap device. The Slackware init scripts are configured by editing /etc/rc.d/rc.inet1.conf.

The second method uses the provided rc.local-additions script. A brief explanation can be found later in this document, here.

The Slackware beginner's guide briefly explains networking on a Slackware system. Additionally, Eric Hameleers wrote a very in-depth guide explaining advanced networking on Slackware. I suggest you read through both documents to familiarize yourself with the process.

First I will discuss how to use the Slackware init scripts. This is by far the easiest way to configure the bridge. Let's take a look at the relevant changes in rc.inet1.conf:

IFNAME[0]="br0"
BRNICS[0]="eth0"
IPADDR[0]=""
NETMASK[0]=""
IPALIASES[0]=""
USE_DHCP[0]="yes"
DHCP_HOSTNAME[0]=""

VIRTIFNAME[0]="tap0"
VIRTIFTYPE[0]="tap"
VIRTIFUSER[0]="root"
VIRTIFGROUP[0]="root"

You will need to restart your network for the changes to take effect. It is also important to disable NetworkManager if are going to use rc.inet1.conf to configure your network. NetworkManager comes with Slackware, but it is not developed by Slackware. As a result, the process of configuring a bridge with NetworkManager is not supported in this guide. The following commands must be executed as root:

# /etc/rc.d/rc.networkmanager stop
# chmod -x /etc/rc.d/rc.networkmanager
# /etc/rc.d/rc.inet1 restart

Next you need to create a few files that QEMU requires to bring up the guest's network interface. These scripts must be executable because QEMU runs each of them automatically upon booting the Slackware ARM guest. If they do not already exist in /export/armhost, create them.

File: qemu-network-tun.sh

#!/bin/sh

# This is the IP of 'tap0' on the Slackware/x86 host:
BRIDGEIP=192.168.1.4

modprobe tun
/sbin/ifconfig $1 $BRIDGEIP netmask 255.255.255.0
/sbin/brctl addif br0 $1

File: qemu-network-tun-down.sh

#!/bin/sh

/sbin/ifconfig $1 down
/sbin/brctl delif br0 $1

Mark both qemu-network-tun.sh and qemu-network-tun-down.sh as executable

# chmod +x /export/armhost/qemu-network-tun.sh
# chmod +x /export/armhost/qemu-network-tun-down.sh

You are now ready to boot the Slackware ARM guest. Launch QEMU with the following command:

# cd /export/armhost
# qemu-system-arm -nographic \
   -net nic${MACADDR} -net tap,ifname=tap0,script=qemu-network-tun.sh,downscript=qemu-network-tun-down.sh \
   -m 1024 \
   -M vexpress-a9 \
   -k en-us \
   -rtc base=localtime \
   -no-reboot \
   -sd sdcard.img \
   -append "TERM=xterm-256color vmalloc=256MB console=ttyAMA0,115200n8 nofont nic=auto:eth0:dhcp root=/dev/ram rw" \
   -kernel zImage-armv7 \
   -dtb dtb/vexpress-v2p-ca9.dtb \
   -initrd initrd-armv7.img

Notice the line: -net nic${MACADDR} -net tap,ifname=tap0,script=qemu-network-tun.sh,downscript=qemu-network-tun-down.sh

This line tells QEMU to attach to the tap device, tap0, which you configured earlier in /etc/rc.d/rc.inet1.conf. This option will assign (qemu-network-tun.sh) tap0 an IP address when the QEMU guest is started. It will also destroy (qemu-network-tun-down.sh) tap0 network settings upon QEMU guest shut down.

QEMU Bridged Mode Networking with rc.local-additions

This section describes the process of configuring QEMU networking with a more fine grained control. It uses the rc.local-additions init script provided within the Slackware ARM helper scripts. This script requires a bit more of an in-depth knowledge to network bridges, tap devices, and networking in general. It is meant as an example for the user to edit and add to /etc/rc.d/rc.local on the Slackware x86 host. It is very likely that this script will not be useful until you customize it to fit the network settings on your Local Area Network.

You can find the script with comments here: rc.local-additions

Here is the relevant portion of the script that requires modification. Changes depend on your network settings for the host machine:

.. snip ..

# Turn on the bridge.  Note that this is a different IP from
# the one specified in your qemu-network-bridge.sh script
# in your 'armhost' directory on your Slackware x86 box.
# You need a bridge IP, a tunnel (tap0) IP, and then another
# IP which is assigned to the Slackware ARM host (by Linux inside QEMU)
# to its own eth0.
# I tried bringing this up after eth0 but the bridge didn't work.
# I don't know why that is!
ifconfig br0 192.168.1.3 up

# Put back the original IP for eth0:
ifconfig eth0 192.168.1.2 up

# 
route del default
route add default gw 192.168.1.1

These network settings assume static IP addressing. The br0 interface is the bridged network interface. The eth0 interface is the host machine network interface that allows the host machine to retain network connectivity. The default gateway, 192.168.1.1, typically points to the network gateway on the physical network. In order for the QEMU guest to access the network you must configure the tap0 device with the qemu-network-tun.sh script. This static IP address should reflect your network settings as well.

#!/bin/sh

# This is the IP of 'tap0' on the Slackware/x86 host:
BRIDGEIP=192.168.1.4

modprobe tun
/sbin/ifconfig $1 $BRIDGEIP netmask 255.255.255.0
/sbin/brctl addif br0 $1

As described earlier in this document, you can launch the Slackware ARM installer within the QEMU guest, with the same network options:

# qemu-system-arm -nographic \
   -net nic${MACADDR} -net tap,ifname=tap0,script=qemu-network-tun.sh,downscript=qemu-network-tun-down.sh \
   .. snip ..
   -initrd initrd-armv7.img

Install Slackware ARM

I will assume that you are now in X Windows, running as your normal user account, and that you followed the steps outlined earlier in this document. As stated earlier, QEMU runs extremely slow when emulating the ARM architecture. Depending on your hardware set up it may take several hours or more for the Slackware installer to copy all packages to the emulated disk. If the Slackware installer appears to be unresponsive, check your system process monitor (top or htop) to see if the QEMU process is still active. A good sign that QEMU is still active is that a single CPU core is operating at 100 percent.

The Slackware ARM installer is mostly identical to the Slackware x86 installer. There is no learning curve to install Slackware ARM if you have installed Slackware before.

Booting the Installer

In order to boot the installer you will need to configure and execute the installer_launch script within a terminal window.

cd /export/armhost
./installer_launch

The installer_launch script can be found here.

You will see some warnings from QEMU about being unable to open audio and video devices. Those warnings can safely be ignored. Next you will see the Linux kernel boot messages and eventually the installer asking about what key map you want to use. Once you select your key map and log in to the system you will notice that the installer obtains an IP address via DHCP. The DHCP assigned IP address and resulting network configuration relies heavily on how you set up your networking on the host machine. If QEMU does not assign an IP address to the guest, then you need to go back and verify your network settings are configured appropriately.

Partitioning

The emulated SD Card created with the makeimg command is a blank image. You will have to partition this SD Card with the installer. It is best to keep the partition scheme simple in our case. It is recommended that you create a 200MB swap partition and to allocate the rest of the disk to the root partition. You can use the fdisk or cfdisk tools to create the partitions.

Example partitioning scheme:

/dev/mmcblk0p1 - 200MB swap
/dev/mmcblk0p2 - the rest of the disc, "Linux" - type 83.

Setup and Configuration

Run the setup command at the shell prompt after you exit the partitioning tool. Make the installer aware of your swap parition and root partition. It is recommended that you select the ext4 file system when you format the root partition. Next you will be prompted to select the source media. Choose option 4, Install from NFS (Network Filesystem). Enter the IP address of your Slackware x86 host. Enter the path to the NFS mounted share.

The full path of the NFS share is required:

Enter the IP address: 192.168.1.1 # br0 or eth0 IP address
Enter the directory: /export/slackwarearm/$SLACKREL/slackware

Following that, you will be prompted for package selection. Slackware ARM has all of the standard Slackware packages apart from those which are x86 only. It is highly recommended that you do a full installation to satisfy all system dependencies. Please be patient, this is the most time consuming part of the installation process.

After installation has finished, running 'MKFONTDIR AND MKFONTSCALE UPDATE' takes a long time.

At the Network Setup screen it is best to select the DHCP option. The DHCP option best compliments QEMU's NAT mode and both bridged mode networking options. The only reason not to select DHCP is if your physical network uses static IP addressing.

Next you will reach the Window Manager selection for the X Windows server. It is recommended that you select a light weight window manager, such as Fluxbox or WindowMaker. KDE and Xfce are not very useful within the QEMU guest due to speed constraints.

Post-Installation

Once you complete the installation process you should drop to a shell prompt to configure the SSH Daemon. By default, OpenSSH does not allow root to log in with a password. This is a security concern. You may want to think about this carefully if your device is connected directly to an untrusted network. It is best to make a user account for remote connections to the SSH service and escalate privileges locally with “su” or “sudo”. If you wish to use root to log in remotely, follow these steps:

  1. Opt to drop in to a 'shell' when you exit from the installer
  2. At the shell, enter:
# sed -i 's?^#PermitRootLogin.*?PermitRootLogin yes?g' /mnt/etc/ssh/sshd_config
# poweroff                  

This completes the installation process of Slackware ARM within QEMU.

Boot Slackware ARM with QEMU

Work in Progress

For making it this far, congratulations! The next step is booting into your fresh installation of Slackwarearm-current. Locate the disk_launch helper script in /export/armhost and modify it to fit your needs.

# cd /export/armhost
# vi disk_launch

This script has a few variables you may want to change.

  • ROOTFSTYPE - root file system type, ext4 is the default
  • ROOTFSDEV - location of the root partition within the SD Card image
  • KEYBOARD - keyboard locale you wish to use, typically the same as what you chose during installation
  • NETTYPE - network configuration, NAT mode or bridged mode

The disk_launch script can be found online, here.

The first boot will take quite a while. This is due to the fact that Slackware will generate the font cache for the first time. Start up QEMU by executing the disk_launch script.

# ./disk_launch

Slackware ARM Graphical User Interface

Work in Progress

This section will discuss the positives and negatives around running X Windows, which window manager or desktop environment to use, and the ways you can start it up.

Sources


In Other Languages
Translations of this page?:
QR Code
QR Code howtos:hardware:arm:qemu_support_in_slackware_arm (generated for current page)