This is an old revision of the document!
Table of Contents
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
Slackware x86 Host Prerequisites
- Download the Slackwarearm distribution package tree with rsync
- Populate a location with the Slackware ARM QEMU files
- Configure the Network File Server (NFS) on the Slackware x86 Host
- Install QEMU and the device-tree-compiler software on the Slackware x86 host
- Configure QEMU Permissions on the Slackware x86 Host
- 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.
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.
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.
You need to know the QEMU network settings in order to access the NFS share. It is recommended that you use NAT mode networking with QEMU. NAT mode allows direct access to the Slackware x86 host NFS share through a QEMU hosted virtual network. More information about the virtual network and assigned addressing is discussed later on in this guide.
With a text editor, as root, add the following to the Slackware host's /etc/exports:
# QEMU guest virtual IP address /export/slackwarearm 10.0.2.15(insecure,ro,nohide,root_squash,sync,no_subtree_check)
NAT mode does not allow direct access to the physical Local Area Network. You will need to set up a bridged network interface if you decide you need direct network access. NAT mode will be sufficient for most users.
Use something similar to the following if you want a bridged network interface:
/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 and match it with your network configuration.
Activate the NFS share by executing the following as root:
# chmod +x /etc/rc.d/{rc.rpc,rc.nfsd} # /etc/rc.d/rc.nfsd # exportfs -va
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
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. Most users will want to use NAT mode.
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.
ip link set eth0 txqueuelen 10000
Run this command for each network interface actively used by QEMU.
QEMU NAT Mode Networking
NAT mode does not require any additional configuration on the Slackware x86 host machine or in the QEMU guest machine. Here is a shortened example of a QEMU guest being launched with NAT mode networking:
# cd /export/armhost # qemu-system-arm -nographic \ -m 1024 \ -M vexpress-a9 \ -k en-us \ -net nic \ -net user ..snip..
The -net nic and -net user options enable QEMU to start the Slackwarearm guest with NAT mode networking enabled.
With NAT mode enabled, QEMU launches a virtual network of 10.0.2.0/24. The QEMU guest will be assigned the IP address 10.0.2.15. The guest can access the Slackware x86 host at 10.0.2.2 and the QEMU DNS server runs at 10.0.2.3. QEMU does not have direct access to the host's Local Area Network. This means that the QEMU guest isn't assigned a physical IP address by your router DHCP service. You will not be able to ping the QEMU guest from the host machine but the guest should be able to ping the host machine at 10.0.2.2. The QEMU guest should be able to access the internet and communicate with the host machine.
QEMU Bridged Mode Networking
The best way to set up a bridged network interface for QEMU is with the provided helper script, rc.local-additions. If you choose to take this route, you need to disable the NetworkManager service. 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 to disable NetworkManager:
# /etc/rc.d/rc.networkmanager stop # chmod -x /etc/rc.d/rc.networkmanager
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
Below you will see the relevant additions needed in to boot the QEMU guest with bridged networking:
# 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 \ ..snip.. -append "TERM=xterm-256color vmalloc=256MB console=ttyAMA0,115200n8 nofont nic=auto:eth0:dhcp root=/dev/ram rw"
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.
Remove from the append line, nic=auto:eth0:dhcp, if you want to use a static IP address for the QEMU guest.
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.
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:
- Opt to drop in to a 'shell' when you exit from the installer
- 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
- Originally written by Stuart Winter
- Original source: http://ftp.arm.slackware.com/slackwarearm/boardsupport/qemu/
- Modified and Maintained by Brenton Earl (mralk3)