Setting up Debian/m68k on qemu-system-m68k

In order to install Debian/m68k inside a fully emulated QEMU virtual machine, one currently needs to use an out-of-tree version by Laurent Vivier called ?https://github.com/vivier/qemu-m68k as the Quadra-800 system emulation has not been upstreamed yet.

Downloading and building qemu-system-m68k

Installing build dependencies for qemu-system-m68k

root@epyc:~> apt build-dep qemu
Reading package lists... Done
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  guile-2.0-libs libkf5auth5 libpthread-stubs0-dev:m68k linux-libc-dev:m68k
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
  libcurl4-openssl-dev
The following NEW packages will be installed:
  binutils-alpha-linux-gnu binutils-s390x-linux-gnu cpp-9-alpha-linux-gnu cpp-9-s390x-linux-gnu cpp-alpha-linux-gnu cpp-s390x-linux-gnu device-tree-compiler
  gcc-9-alpha-linux-gnu gcc-9-alpha-linux-gnu-base gcc-9-s390x-linux-gnu gcc-9-s390x-linux-gnu-base gcc-alpha-linux-gnu gcc-s390x-linux-gnu libaio-dev
  libasan5-s390x-cross libatomic1-alpha-cross libatomic1-s390x-cross libbluetooth-dev libbrlapi-dev libc6-s390x-cross libc6.1-alpha-cross libc6.1-dev-alpha-cross
  libcacard-dev libcapstone-dev libcurl4-gnutls-dev libfdt-dev libgbm-dev libgcc-9-dev-alpha-cross libgcc-9-dev-s390x-cross libgcc1-alpha-cross libgcc1-s390x-cross
  libgfchangelog0 libglusterfs-dev libgomp1-alpha-cross libgomp1-s390x-cross libibumad-dev libibverbs-dev libiscsi-dev libitm1-alpha-cross libitm1-s390x-cross libnfs-dev
  libnl-3-dev libnl-route-3-dev libnuma-dev librados-dev librbd-dev librdmacm-dev libsasl2-dev libspice-protocol-dev libspice-server-dev libssh-dev libstdc++6-s390x-cross
  libubsan1-s390x-cross libusb-1.0-0-dev libusbredirparser-dev libvdeplug-dev libvirglrenderer-dev libvirglrenderer1 libvte-2.91-dev libxen-dev linux-libc-dev-alpha-cross
  xfslibs-dev
(...)
Setting up xfslibs-dev (5.0.0-1+b1) ...
Setting up cpp-9-alpha-linux-gnu (9.2.1-8cross1) ...
Setting up libcapstone-dev:amd64 (4.0.1+really+3.0.5-1+b1) ...
Setting up libgcc1-s390x-cross (1:9.2.1-8cross1) ...
Setting up librbd-dev (12.2.11+dfsg1-2.1+b2) ...
Setting up libspice-server-dev (0.14.2-3) ...
Setting up libc6.1-dev-alpha-cross (2.29-1cross1) ...
Setting up libgcc1-alpha-cross (1:9.2.1-8cross1) ...
Setting up cpp-s390x-linux-gnu (4:9.2.1-3.1) ...
Setting up libstdc++6-s390x-cross (9.2.1-8cross1) ...
Setting up libitm1-alpha-cross (9.2.1-8cross1) ...
Setting up libbrlapi-dev:amd64 (5.6-11+b1) ...
Setting up libasan5-s390x-cross (9.2.1-8cross1) ...
Setting up libnl-route-3-dev:amd64 (3.4.0-1+b1) ...
Setting up libvirglrenderer-dev:amd64 (0.8.0-1) ...
Setting up cpp-alpha-linux-gnu (4:9.2.1-3) ...
Setting up libubsan1-s390x-cross (9.2.1-8cross1) ...
Setting up libgcc-9-dev-alpha-cross (9.2.1-8cross1) ...
Setting up libibverbs-dev:amd64 (24.0-2) ...
Setting up librdmacm-dev:amd64 (24.0-2) ...
Setting up gcc-9-alpha-linux-gnu (9.2.1-8cross1) ...
Setting up libgcc-9-dev-s390x-cross (9.2.1-8cross1) ...
Setting up gcc-alpha-linux-gnu (4:9.2.1-3) ...
Setting up gcc-9-s390x-linux-gnu (9.2.1-8cross1) ...
Setting up gcc-s390x-linux-gnu (4:9.2.1-3.1) ...
Processing triggers for libc-bin (2.29-2) ...
Processing triggers for man-db (2.8.7-3) ...
Processing triggers for doc-base (0.10.9) ...
Processing 2 added doc-base files...
Scanning processes...                                                                                                                                                       
Scanning processor microcode...                                                                                                                                             
Scanning linux images...                                                                                                                                                    

Running kernel seems to be up-to-date.

Failed to check for processor microcode upgrades.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.
root@epyc:~>

Checking out and building qemu-system-m68k

root@epyc:/local_scratch/m68k> git clone https://github.com/vivier/qemu-m68k.git
Cloning into 'qemu-m68k'...
remote: Enumerating objects: 13762, done.
remote: Counting objects: 100% (13762/13762), done.
remote: Compressing objects: 100% (4803/4803), done.
remote: Total 461765 (delta 10044), reused 10914 (delta 8939), pack-reused 448003
Receiving objects: 100% (461765/461765), 195.00 MiB | 16.19 MiB/s, done.
Resolving deltas: 100% (378241/378241), done.
root@epyc:/local_scratch/m68k> cd qemu-m68k/
root@epyc:..m68k/qemu-m68k> git checkout q800-dev
Already on 'q800-dev'
Your branch is up to date with 'origin/q800-dev'.
root@epyc:..m68k/qemu-m68k> ./configure --target-list=m68k-softmmu 
Install prefix    /usr/local
BIOS directory    /usr/local/share/qemu
firmware path     /usr/local/share/qemu-firmware
binary directory  /usr/local/bin
library directory /usr/local/lib
module directory  /usr/local/lib/qemu
libexec directory /usr/local/libexec
include directory /usr/local/include
config directory  /usr/local/etc
local state directory   /usr/local/var
Manual directory  /usr/local/share/man
ELF interp prefix /usr/gnemul/qemu-%M
Source path       /local_scratch/m68k/qemu-m68k
GIT binary        git
GIT submodules    ui/keycodemapdb tests/fp/berkeley-testfloat-3 tests/fp/berkeley-softfloat-3 dtc capstone slirp
C compiler        cc
Host C compiler   cc
C++ compiler      c++
Objective-C compiler cc
ARFLAGS           rv
CFLAGS            -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -g 
QEMU_CFLAGS       -I/usr/include/pixman-1 -I$(SRC_PATH)/dtc/libfdt -Werror  -pthread -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -fPIE -DPIE -m64 -mcx16 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wall -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -std=gnu99  -Wexpansion-to-defined -Wendif-labels -Wno-shift-negative-value -Wno-missing-include-dirs -Wempty-body -Wnested-externs -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wold-style-declaration -Wold-style-definition -Wtype-limits -fstack-protector-strong -I/usr/include/p11-kit-1   -I/usr/include/libpng16 -I$(SRC_PATH)/capstone/include
LDFLAGS           -Wl,--warn-common -Wl,-z,relro -Wl,-z,now -pie -m64 -g 
QEMU_LDFLAGS      -L$(BUILD_DIR)/dtc/libfdt 
make              make
install           install
python            python3 -B (3.7.4)
slirp support     git 
smbd              /usr/sbin/smbd
module support    no
host CPU          x86_64
host big endian   no
target list       m68k-softmmu
gprof enabled     no
sparse enabled    no
strip binaries    yes
profiler          no
static build      no
SDL support       no 
SDL image support no
GTK support       yes (3.24.11)
GTK GL support    no
VTE support       no 
TLS priority      NORMAL
GNUTLS support    yes
libgcrypt         no
nettle            yes (3.4.1)
libtasn1          yes
PAM               yes
iconv support     yes
curses support    yes
virgl support     no 
curl support      yes
mingw32 support   no
Audio drivers     pa oss
Block whitelist (rw) 
Block whitelist (ro) 
VirtFS support    yes
Multipath support no
VNC support       yes
VNC SASL support  no
VNC JPEG support  yes
VNC PNG support   yes
xen support       no
brlapi support    no
bluez  support    no
Documentation     yes
PIE               yes
vde support       no
netmap support    no
Linux AIO support no
ATTR/XATTR support yes
Install blobs     yes
KVM support       yes
HAX support       no
HVF support       no
WHPX support      no
TCG support       yes
TCG debug enabled no
TCG interpreter   no
malloc trim support yes
RDMA support      no
PVRDMA support    no
fdt support       git
membarrier        no
preadv support    yes
fdatasync         yes
madvise           yes
posix_madvise     yes
posix_memalign    yes
libcap-ng support yes
vhost-net support yes
vhost-crypto support yes
vhost-scsi support yes
vhost-vsock support yes
vhost-user support yes
Trace backends    log
spice support     no 
rbd support       no
xfsctl support    no
smartcard support no
libusb            no
usb net redir     no
OpenGL support    no
OpenGL dmabufs    no
libiscsi support  no
libnfs support    no
build guest agent yes
QGA VSS support   no
QGA w32 disk info no
QGA MSI support   no
seccomp support   yes
coroutine backend ucontext
coroutine pool    yes
debug stack usage no
mutex debugging   no
crypto afalg      no
GlusterFS support no
gcov              gcov
gcov enabled      no
TPM support       yes
libssh support    no
QOM debugging     yes
Live block migration yes
lzo support       no
snappy support    no
bzip2 support     yes
lzfse support     no
NUMA host support no
libxml2           yes
tcmalloc support  no
jemalloc support  no
avx2 optimization yes
replication support yes
VxHS block device no
bochs support     yes
cloop support     yes
dmg support       yes
qcow v1 support   yes
vdi support       yes
vvfat support     yes
qed support       yes
parallels support yes
sheepdog support  yes
capstone          git
docker            no
libpmem support   no
libudev           yes
default devices   yes
root@epyc:..m68k/qemu-m68k> make -j64
(...)
root@epyc:..m68k/qemu-m68k> cp -av m68k-softmmu/qemu-system-m68k /usr/local/bin/
'm68k-softmmu/qemu-system-m68k' -> '/usr/local/bin/qemu-system-m68k'
root@epyc:..m68k/qemu-m68k>

Prepare VM directory:

root@epyc:/local_scratch/m68k> cd qemu-m68k/
root@epyc:..m68k/qemu-m68k> cd ..
root@epyc:/local_scratch/m68k> mkdir system
root@epyc:/local_scratch/m68k> cd system
root@epyc:..m68k/system>

Create hard disk images:

root@epyc:..m68k/system> apt install qemu-utils
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  qemu-utils
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 1,012 kB of archives.
After this operation, 5,847 kB of additional disk space will be used.
Get:1 http://ftp.de.debian.org/debian unstable/main amd64 qemu-utils amd64 1:4.1-1+b3 [1,012 kB]
Fetched 1,012 kB in 0s (28.3 MB/s)   
Selecting previously unselected package qemu-utils.
(Reading database ... 403754 files and directories currently installed.)
Preparing to unpack .../qemu-utils_1%3a4.1-1+b3_amd64.deb ...
Unpacking qemu-utils (1:4.1-1+b3) ...
Setting up qemu-utils (1:4.1-1+b3) ...
Processing triggers for man-db (2.9.0-1) ...
Scanning processes...                                                                                                                                                       
Scanning candidates...                                                                                                                                                      
Scanning processor microcode...                                                                                                                                             
Scanning linux images...                                                                                                                                                    

Running kernel seems to be up-to-date.

Failed to check for processor microcode upgrades.

Restarting services...
Service restarts being deferred:
 systemctl restart NetworkManager.service
 systemctl restart atd.service
 systemctl restart autofs.service
 systemctl restart cron.service
 /etc/needrestart/restart.d/dbus.service
 systemctl restart lightdm.service
 systemctl restart nscd.service
 systemctl restart smartmontools.service
 systemctl restart ssh.service
 systemctl restart unattended-upgrades.service
 systemctl restart xfstt.service

No containers need to be restarted.

User sessions running outdated binaries:
 lightdm @ user manager service: at-spi-bus-laun[2424], systemd[2390]
 root @ user manager service: systemd[11366]
root@epyc:..m68k/system>

root@epyc:..m68k/system> qemu-img create -f qcow2 m68k-system.img 20G
Formatting 'm68k-system.img', fmt=qcow2 size=21474836480 cluster_size=65536 lazy_refcounts=off refcount_bits=16
root@epyc:..m68k/system> qemu-img create -f qcow2 m68k-swap.img 4G
Formatting 'm68k-swap.img', fmt=qcow2 size=4294967296 cluster_size=65536 lazy_refcounts=off refcount_bits=16
root@epyc:..m68k/system>

Download Debian NETINST m68k ISO:

root@epyc:..m68k/system> wget https://cdimage.debian.org/cdimage/ports/2019-07-16/debian-10.0-m68k-NETINST-1.iso
--2019-09-22 15:46:37--  https://cdimage.debian.org/cdimage/ports/2019-07-16/debian-10.0-m68k-NETINST-1.iso
Resolving cdimage.debian.org (cdimage.debian.org)... 194.71.11.165, 194.71.11.173, 2001:6b0:19::165, ...
Connecting to cdimage.debian.org (cdimage.debian.org)|194.71.11.165|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://saimei.ftp.acc.umu.se/cdimage/ports/2019-07-16/debian-10.0-m68k-NETINST-1.iso [following]
--2019-09-22 15:46:37--  https://saimei.ftp.acc.umu.se/cdimage/ports/2019-07-16/debian-10.0-m68k-NETINST-1.iso
Resolving saimei.ftp.acc.umu.se (saimei.ftp.acc.umu.se)... 194.71.11.138, 2001:6b0:19::138
Connecting to saimei.ftp.acc.umu.se (saimei.ftp.acc.umu.se)|194.71.11.138|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 180850688 (172M) [application/x-iso9660-image]
Saving to: ‘debian-10.0-m68k-NETINST-1.iso’

debian-10.0-m68k-NETINST-1.iso             100%[========================================================================================>] 172.47M  62.4MB/s    in 2.8s    

2019-09-22 15:46:40 (62.4 MB/s) - ‘debian-10.0-m68k-NETINST-1.iso’ saved [180850688/180850688]

root@epyc:..m68k/system>

Extract kernel and initrd for debian-installer from ISO:

root@epyc:..m68k/system> mount -o loop debian-10.0-m68k-NETINST-1.iso /mnt/
mount: /mnt: WARNING: device write-protected, mounted read-only.
root@epyc:..m68k/system> cp -av /mnt/install/kernels/vmlinux-4.19.0-5-m68k .
'/mnt/install/kernels/vmlinux-4.19.0-5-m68k' -> './vmlinux-4.19.0-5-m68k'
root@epyc:..m68k/system> cp -av /mnt/install/cdrom/initrd.gz .
'/mnt/install/cdrom/initrd.gz' -> './initrd.gz'
root@epyc:..m68k/system> umount /mnt/
root@epyc:..m68k/system>

Start VM with debian-installer CD-ROM:

/usr/local/bin/qemu-system-m68k -M q800 -serial none -serial mon:stdio -m 1000M -drive file=m68k-system.img,format=qcow2 -drive file=m68k-swap.img,format=qcow2 -net nic,model=dp83932,addr=08:00:07:12:34:89 -net user -nographic -append "root=/dev/ram rw console=ttyS0" -cdrom debian-10.0-m68k-NETINST-1.iso -kernel vmlinux-4.19.0-5-m68k -initrd initrd.gz

Installation

Install Debian system as usual, see for example this (outdated) installation manual for Debian Sarge on m68k and the current guide for Debian stable.

When asked for mirror information, enter the following:

Copy new kernel and initrd from qcow2 disk image to host system

Install libguestfs-tools

root@epyc:..m68k/system> apt install libguestfs-tools 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  augeas-lenses cryptsetup-bin db-util db5.3-util extlinux hfsplus icoutils ldmtool libafflib0v5 libaugeas0
  libconfig9 libdate-manip-perl libewf2 libguestfs-hfsplus libguestfs-perl libguestfs-reiserfs libguestfs-xfs
  libguestfs0 libhfsp0 libhivex0 libldm-1.0-0 libsys-virt-perl libtsk13 libvirt0 libwin-hivex-perl
  libxml-xpath-perl libyara3 lsscsi lzop osinfo-db scrub sgabios sleuthkit supermin syslinux syslinux-common
  zerofree
Suggested packages:
  augeas-doc augeas-tools libguestfs-gfs2 libguestfs-jfs libguestfs-nilfs libguestfs-rescue libguestfs-rsync
  libguestfs-zfs autopsy mac-robber
The following NEW packages will be installed:
  augeas-lenses cryptsetup-bin db-util db5.3-util extlinux hfsplus icoutils ldmtool libafflib0v5 libaugeas0
  libconfig9 libdate-manip-perl libewf2 libguestfs-hfsplus libguestfs-perl libguestfs-reiserfs libguestfs-tools
  libguestfs-xfs libguestfs0 libhfsp0 libhivex0 libldm-1.0-0 libsys-virt-perl libtsk13 libvirt0
  libwin-hivex-perl libxml-xpath-perl libyara3 lsscsi lzop osinfo-db scrub sgabios sleuthkit supermin syslinux
  syslinux-common zerofree
0 upgraded, 38 newly installed, 0 to remove and 1 not upgraded.
Need to get 26.0 MB of archives.
After this operation, 104 MB of additional disk space will be used.
Get:1 http://ftp.de.debian.org/debian unstable/main i386 augeas-lenses all 1.12.0-1 [451 kB]
Get:2 http://ftp.de.debian.org/debian unstable/main amd64 cryptsetup-bin amd64 2:2.2.1-1 [372 kB]
Get:3 http://ftp.de.debian.org/debian unstable/main amd64 db5.3-util amd64 5.3.28+dfsg1-0.6 [64.6 kB]
Get:4 http://ftp.de.debian.org/debian unstable/main i386 db-util all 5.3.1+nmu1 [2,932 B]
Get:5 http://ftp.de.debian.org/debian unstable/main amd64 extlinux amd64 3:6.04~git20190206.bf6db5b4+dfsg1-1 [192 kB]
Get:6 http://ftp.de.debian.org/debian unstable/main amd64 libhfsp0 amd64 1.0.4-15+b1 [35.8 kB]
Get:7 http://ftp.de.debian.org/debian unstable/main amd64 hfsplus amd64 1.0.4-15+b1 [44.8 kB]
Get:8 http://ftp.de.debian.org/debian unstable/main amd64 icoutils amd64 0.32.3-3 [67.5 kB]
Get:9 http://ftp.de.debian.org/debian unstable/main amd64 libldm-1.0-0 amd64 0.2.4-2+b1 [22.0 kB]
(...)
Setting up supermin (5.1.20-1+b10) ...
Setting up libdate-manip-perl (6.78-1) ...
Setting up libsys-virt-perl (5.6.0-1+b1) ...
Setting up hfsplus (1.0.4-15+b1) ...
Setting up db-util (5.3.1+nmu1) ...
Setting up libwin-hivex-perl (1.3.18-1+b2) ...
Setting up libtsk13 (4.6.7-1) ...
Setting up sleuthkit (4.6.7-1) ...
Setting up libguestfs0:amd64 (1:1.40.2-2+b10) ...
Setting up libguestfs-xfs:amd64 (1:1.40.2-2+b10) ...
Setting up libguestfs-perl (1:1.40.2-2+b10) ...
Setting up libguestfs-hfsplus:amd64 (1:1.40.2-2+b10) ...
Setting up libguestfs-reiserfs:amd64 (1:1.40.2-2+b10) ...
Setting up libguestfs-tools (1:1.40.2-2+b10) ...
Processing triggers for man-db (2.9.0-1) ...
Processing triggers for libc-bin (2.29-2) ...
Scanning processes...                                                                                             
Scanning candidates...                                                                                            
Scanning processor microcode...                                                                                   
Scanning linux images...                                                                                          

Running kernel seems to be up-to-date.

Failed to check for processor microcode upgrades.

Restarting services...
Service restarts being deferred:
 systemctl restart autofs.service
 systemctl restart lightdm.service
 systemctl restart smartmontools.service
 systemctl restart unattended-upgrades.service
 systemctl restart xfstt.service

No containers need to be restarted.

User sessions running outdated binaries:
 lightdm @ user manager service: systemd[2390]
root@epyc:..m68k/system>

Mount qcow2 harddisk image and copy over kernel and initrd for guest system to host

root@epyc:..m68k/system> guestmount -a m68k-system.img -m /dev/sda2 /mnt/
root@epyc:..m68k/system> cp -av /mnt/boot/* .
'/mnt/boot/config-4.19.0-5-m68k' -> './config-4.19.0-5-m68k'
'/mnt/boot/config-5.3.0-1-m68k' -> './config-5.3.0-1-m68k'
'/mnt/boot/initrd.img-4.19.0-5-m68k' -> './initrd.img-4.19.0-5-m68k'
'/mnt/boot/initrd.img-5.3.0-1-m68k' -> './initrd.img-5.3.0-1-m68k'
'/mnt/boot/System.map-4.19.0-5-m68k' -> './System.map-4.19.0-5-m68k'
'/mnt/boot/System.map-5.3.0-1-m68k' -> './System.map-5.3.0-1-m68k'
'/mnt/boot/vmlinux-4.19.0-5-m68k' -> './vmlinux-4.19.0-5-m68k'
'/mnt/boot/vmlinux-5.3.0-1-m68k' -> './vmlinux-5.3.0-1-m68k'
root@epyc:..m68k/system> umount /mnt/
root@epyc:..m68k/system>

Booting the installed system

Boot the new system with the newly copied kernel and initrd, make sure to pass the correct partition for the root partition (e.g. /dev/sda2):

/usr/local/bin/qemu-system-m68k -M q800 -serial mon:stdio -m 1000M -drive file=m68k-system.img,format=qcow2 -drive file=m68k-swap.img,format=qcow2 -net nic,model=dp83932,addr=08:00:07:12:34:89 -net user -nographic -append "root=/dev/sda2 rw console=ttyS0" -cdrom debian-10.0-m68k-NETINST-1.iso -kernel vmlinux-5.3.0-1-m68k -initrd initrd.img-5.3.0-1-m68k

Notes