KVM guest // Bootstrap Slackware Linux

tested on focal and hirsute

boostrapping slackware on a vdisk (not a v-partition for once)

Requirements

We will need pkgtools so we’re brutally installing it on Ubuntu, however it overrides the /sbin symlink so be careful

mirror=...

    lftp -c "open $mirror/slackware64/a/; mget pkgtools-*.txz"

mkdir /var/tmp/pkgtools/
    tar xaf pkgtools-*.txz -C /var/tmp/pkgtools/
mv -f /var/tmp/pkgtools/sbin/* /usr/local/sbin/

grep 21 /etc/group
groupdel fax
groupadd -g 21 slocate
grep ^slocate /etc/group

We use SYSLINUX / EXTLINUX against the guest virtual disk from the host

apt install syslinux

Assuming you got the virbr0 bridge up and running

virsh net-start default
virsh net-list
brctl show

Bootstrap

KVM requires a boot-loader hence a full virtual disk

as root

guest=slack
guest=powerslack

    mkdir -p /data/guests/$guest/lala/
    cd /data/guests/$guest/
    dd if=/dev/zero of=$guest.img bs=1GB count=0 seek=26
    #dd if=/dev/zero of=$guest.img bs=1GB count=0 seek=100
fdisk $guest.img

n
p
ENTER
ENTER
ENTER
a
w

loop=`losetup --find --partscan --show $guest.img`
echo loop is $loop
mkfs.ext4 ${loop}p1
#mkfs.xfs ${loop}p1
mount ${loop}p1 lala/

Deploy and setup

from the KVM host directly

[an error occurred while processing the directive]

Setup manually

[an error occurred while processing the directive] [an error occurred while processing the directive]

Boot-blocks

setup the kvm guest boot-loader and kernel-time serial console

dd if=/usr/lib/syslinux/mbr/mbr.bin of=$loop
mkdir lala/boot/syslinux/
extlinux --install lala/boot/syslinux/ --device ${loop}p1
cp -f /usr/lib/syslinux/modules/bios/mboot.c32 lala/boot/syslinux/
cp -f /usr/lib/syslinux/modules/bios/libcom32.c32 lala/boot/syslinux/

and see syslinux

Ready to go

umount lala/
#umount -R lala/
rmdir lala/

#dumpe2fs -i /dev/loop3p1
#dumpe2fs -h /dev/loop3p1
#fsck.ext4 -f /dev/loop3p1

# requires more recent syslinux than v3 on ubuntu
#xfs_info /dev/loop3p1

losetup --detach ${loop}

choose a decent machine type

qemu-system-x86_64 -machine help | grep PC

pc-i440fx-hirsute    Ubuntu 21.04 PC (i440FX + PIIX, 1996) (default)
pc                   Standard PC (i440FX + PIIX, 1996) (alias of pc-i440fx-5.2)
q35                  Standard PC (Q35 + ICH9, 2009) (alias of pc-q35-5.2)

new UUID and MAC address will be generated on the fly

cat > $guest.xml <<EOF
<domain type='kvm'>
  <name>$guest</name>
  <memory unit='GiB'>1</memory>
  <vcpu placement='static'>16</vcpu>
  <os>
    <type arch='x86_64' machine='q35'>hvm</type>
    <boot dev='hd'/>
  </os>
  <devices>
    <emulator>/usr/bin/qemu-system-x86_64</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/data/guests/$guest/$guest.img'/>
      <target dev='vda' bus='virtio'/>
    </disk>
    <interface type='bridge'>
      <source bridge='virbr0'/>
      <model type='virtio'/>
    </interface>
    <serial type='pty'>
      <target type='isa-serial' port='0'>
    <model name='isa-serial'/>
      </target>
    </serial>
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>
  </devices>
</domain>
EOF

Note you might need more than 1 GiB for a power/building system.

virsh create /data/guests/$guest/$guest.xml
virsh console $guest

TAB --> to get the chance to see the syslinux prompt

(login)
ping -c1 opendns.com

^]

Cloning

clone the machine already

poweroff

cd ../
cp -R --sparse=always slack/ slack-clone/
vi slack-clone/slack.xml

      <name>slack-clone</name>

          <source file='/data/guests/slack-clone/slack.img'/>

du -sh slack*/

and proceed

virsh create slack-clone/slack.xml
virsh console slack-clone

vi /etc/HOSTNAME
vi /etc/hosts
vi /etc/rc.d/rc.inet1

(change static ip)

reboot

ping -c1 opendns.com
^]

Maintenance

virsh list # should NOT run
losetup -a # already mapped?
    losetup --find --partscan --show $guest.img
fsck /dev/loop3p1
mount /dev/loop3p1 lala/
...

umount -R lala/
losetup --detach /dev/loop3

Troubles

"Error: AppArmor parser not found"

ERROR: Can't find apparmor_parser at /sbin/apparmor_parser

–> /sbin is a symlink since focal, did you mess it up by installing pkgtools?…

TODO

Resources

QemuKVMMigration https://wiki.ubuntu.com/QemuKVMMigration

QEMU Unsupported Machine Type ‘pc-q35-3.1’ https://forum.level1techs.com/t/qemu-unsupported-machine-type-pc-q35-3-1/140084

How can I change Qemu KVM machine architecture from 440fx to q35 with virsh edit or virt-manager https://serverfault.com/questions/637917/how-can-i-change-qemu-kvm-machine-architecture-from-440fx-to-q35-with-virsh-edit


HOME | GUIDES | LECTURES | LAB | SMTP HEALTH | NU | HTML5
Copyright © 2022 Pierre-Philipp Braun