XEN guest // Bootstrapping Slackware

tested on Slackware 14.2 and current

assuming the domU kernel has already been prepared

Virtual disks

guest=slack

mkdir -p /data/guests/$guest/lala/
cd /data/guests/$guest/

either create a raw sparse file

# disk/partition in GB
dd if=/dev/zero of=$guest.ext4 bs=1GB count=0 seek=25
dd if=/dev/zero of=$guest.reiser4 bs=1GB count=0 seek=25

# memory in GiB
#dd if=/dev/zero of=$guest.swap bs=1024k count=0 seek=2048

–or– a QCOW2 sparse file

...

–or– a freaking thin provisioned LVM volume

–or– even better, a DRBD volume on top of it

File-systems

then format and mount it

mkfs.ext4 $guest.ext4
fsck.ext4 $guest.ext4

mkfs.reiser4 -dfy $guest.reiser4
fsck.reiser4 -y $guest.reiser4

mount $guest.ext4 lala/
mount $guest.reiser4 lala/

#mkswap $guest.swap

as for LVM/THIN provisioning alone (w/o DRBD here) – block device

ls -lF /dev/thin1/slack
mkfs.reiser4 -dy /dev/thin1/slack
fsck.reiser4 -y /dev/thin1/slack
mount /dev/thin1/slack lala/

as DRBD/THIN – block device

drbdadm status slack
mkfs.reiser4 -dy /dev/drbd/by-res/slack/0
fsck.reiser4 -y /dev/drbd/by-res/slack/0
mount /dev/drbd/by-disk/thin1/slack lala/

Deploy and setup

from the XEN host directly

cd /data/guests/
wget https://pub.nethence.com/bin/slack/slackstrap.bash.txt
mv -i slackstrap.bash.txt slackstrap.bash
chmod +x slackstrap.bash

# defines mirror=
cat /root/mirror.conf

cd /data/guests/$guest/
../slackstrap.bash lala/
#../slackstrap.bash lala/ full
#../slackstrap.bash lala/ hardware

# kvm-only
../slackstrap.bash lala/ kernel

move the packages around for later use

mkdir ../slackpkgs/
mv -f *.txz ../slackpkgs/
rm -f FILE_LIST tagfile

du -sh lala/

# 356M ext4@ext4
# 1,4G ext4@ext4 kernel
# 11G  ext4@ext4 full

# 1,1G ext4@zfs
# 1,4G ext4@zfs kernel
# 9,7G ext4@zfs full

# 1.3G reiser4@ext4
# 1.3G reiser4@drbd/thin

Setup manually

this is otherwise automated with the slackpost.bash script

cd /data/guests/
wget https://pub.nethence.com/bin/slack/slackpost.bash.txt
mv slackpost.bash.txt slackpost.bash
chmod +x slackpost.bash

# defines `mirror=` and `zone=`
cat /root/mirror.conf

tune accordingly

vi slackpost.bash

# XEN
vpartition=/dev/xvda1
fs=reiser4
serial=hvc0

# KVM
vpartition=/dev/vda1
fs=ext4
serial=ttyS0

and proceed

cd /data/guests/$guest/
../slackpost.bash $guest lala/

–or– proceed manually

TODO why rc.sshd doesn’t start anymore by itself although the init script has the executable bit??!

    # REC but forcibly installed by slackstrap/minimal
    ls -lF lala/etc/rc.d/rc.sshd # already enabled

if this is a REISER4 file-system, let the guest eventually fsck itself at boot time

installpkg --terse --root lala/ /root/2021-10/libaal-1.0.7-x86_64-2_SBo.tgz
installpkg --terse --root lala/ /root/2021-10/reiser4progs-1.2.2-x86_64-2_SBo.tgz

fix the xen guest serial console

vi lala/boot/syslinux/syslinux.cfg

serial 0 115200
console 0
nohalt 1

default Linux
prompt 1
timeout 30

label Linux
    linux /boot/vmlinuz
    append root=/dev/vda1 ro console=ttyS0,115200n8 mitigations=off

label XEN
    kernel mboot.c32
    append /xen.gz dom0_mem=512M,max:1024M loglvl=info guest_loglvl=info noreboot=true smt=1 ept=exec-sp com1=115200,8n1 console=com1 --- /vmlinuz root=/dev/vda1 ro console=hvc0 earlyprintk=xen nomodeset mitigations=off

in case you’re going for a PVH dom0, also add those as micro-kernel arguments

dom0=pvh dom0_mem=1024M,max:2048M

you can also cumulate consoles as such

    # console=tty0 console=ttyS0,115200n8

note hvc0 although we want serial (XEN handles it) — and don’t forget to also tune agetty.

for Ubuntu / Debian also add

            net.ifnames=0 biosdevname=0

https://wiki.xenproject.org/wiki/Xen_FAQ_Console

https://wiki.xenproject.org/wiki/Xen_Serial_Console

eventually proceed with a brutal network setup – avoid ssh host keys generation for darkstar

beware of escapes in da place

short=SHORT-HOSTNAME

# kvm/libvirt
ip=192.168.122.99/24
gw=192.168.122.1
dns1=192.168.122.1

# orange
dns1=192.168.1.1
dns2=80.10.246.2
dns3=80.10.246.129

# dedibox
dns1=62.210.16.6
dns2=62.210.16.7

# opendns
dns1=208.67.222.222
dns2=208.67.220.220

cat lala/etc/HOSTNAME # darkstar.example.net
echo $short > lala/etc/HOSTNAME

mv lala/etc/hosts lala/etc/hosts.dist
echo -e "127.0.0.1\t\tlocalhost.localdomain localhost" > lala/etc/hosts
echo -e "::1\t\t\tlocalhost.localdomain localhost" >> lala/etc/hosts
echo -e "${ip%/*}\t$short.localdomain $short" >> lala/etc/hosts
[[ -n $gw ]] && echo -e "$gw\t\tgw" >> lala/etc/hosts
for dns in dns1 dns2 dns3; do
    [[ -n ${!dns} ]] && echo -e "${!dns}\t\t$dns" | tee -a lala/etc/hosts
done; unset dns

mv -i lala/etc/rc.d/rc.inet1 lala/etc/rc.d/rc.inet1.dist
chmod -x lala/etc/rc.d/rc.inet1.dist

# WARNING ESCAPES ARE IN THERE
cat > lala/etc/rc.d/rc.inet1 <<EOF
#!/bin/bash

echo rc.inet1 PATH is \$PATH

if [[ \$1 = stop || \$1 = down ]]; then
    route delete default
    ifconfig eth0 down
    ifconfig lo down
else
    echo -n lo ...
    ifconfig lo up && echo done

    echo -n eth0 ...
    ifconfig eth0 $ip up && echo done

    echo -n default route ...
    route add default gw $gw && echo done
fi
EOF
chmod +x lala/etc/rc.d/rc.inet1

mv lala/etc/resolv.conf lala/etc/resolv.conf.dist
echo 'search nethence.com' > lala/etc/resolv.conf
for dns in dns1 dns2 dns3; do
    [[ -n ${!dns} ]] && echo -e "nameserver ${!dns}" | tee -a lala/etc/resolv.conf
done; unset dns

don’t forget to put your pubkeys over there

mkdir lala/root/.ssh/
vi lala/root/.ssh/authorized_keys

PASTE PUBKEYS

chmod 700 lala/root/.ssh/
chmod 600 lala/root/.ssh/authorized_keys

https://www.commentcamarche.net/faq/1496-serveurs-dns-des-principaux-fai

also deploy and enable TMEM

mkdir lala/lib/modules/
tar xzf /data/kernels/5.2.21.domureiser4.modules.tar.gz -C lala/lib/modules/
echo /sbin/modprobe tmem >> lala/etc/rc.d/rc.modules.local
ls -lF lala/etc/rc.d/rc.modules.local # enabled already

finish-up — be it for a template or not (see below)

    ls -ldF lala/installpkg-*/
    #rm -rf lala/installpkg-*/
    du -sh lala/
    # 06 Jun 2020 -- minimal 494M
    # 22 Oct 2021 -- with kernel 1,4G

    # mklost+found ...
    umount lala/
    rmdir lala/

Template-ready

see tpl

Guest configuration

cat > $guest <<EOF
kernel = "/data/kernels/vmlinuz"
root = "/dev/xvda1 ro console=hvc0 mitigations=off"
#extra = "init=/bin/bash"
name = "$guest"
memory = 7168
vcpus = 16
#disk = ['tap:tapdisk:aio:/data/guests/$guest/$guest.ext4,xvda1,w']
disk = ['tap:tapdisk:aio:/data/guests/$guest/$guest.reiser4,xvda1,w']
#disk = ['phy:/dev/vdisks/thin1,xvda1,w']
#disk = ['phy:/dev/drbd/by-res/$guest/0,xvda1,w']
vif = [ 'bridge=xenbr0, vifname=$guest.0' ]
type = "pvh"
EOF

Ready to go

what a pleasure, a clean and minimal bsdish gnu/linux distro

xl create $guest -c

lsmod | grep tmem
watch free -m

eats only 46 MB of RAM after a while and total memory stripped down to 137 MB

root@darkstar:~# free -m
              total        used        free      shared  buff/cache   available
Mem:            137          46          15           0          75          61
Swap:             0           0           0

clean-up and make a new template out of it

rm -f FILE_LIST tagfile *.txz
rmdir lala/
cd ../
newtemplate.bash $guest

Rescue mode

extra = "init=/bin/bash"

mount -o remount,rw /
export TERM=xterm
dmesg | grep hvc

...

sync
mount -n -o remount,ro /
halt -p

Troubleshooting

setterm: cannot (un)set powersave mode: Inappropriate ioctl for device

==> disable that ACPI call from rc.M - see above

mount: mount point /dev/pts does not exist
mount: mount point /dev/shm does not exist

==> re-enable rc.udev

interesting shit happens when you install the l and n sets before a and ap, for the record,

installpkg --root lala slackware64/l/glibc-2.23-x86_64-1.txz...sbin/ldconfig: Warning: ignoring configuration file that cannot be opened: /etc/ld.so.conf: No such file or directory
done

installpkg --root lala slackware64/l/polkit-0.113-x86_64-2.txz...grep: etc/passwd: No such file or directory
grep: etc/group: No such file or directory
done

installpkg --root lala slackware64/n/openssh-7.2p2-x86_64-1.txz...grep: etc/shadow: No such file or directory
done

Resources

How to clone LVM thin provisioning volume? https://serverfault.com/questions/458949/how-to-clone-lvm-thin-provisioning-volume

5.4.17. CONTROLLING LOGICAL VOLUME ACTIVATION https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/logical_volume_manager_administration/lv_activate

CHAPTER 14. LOGICAL VOLUME ACTIVATION https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_logical_volumes/assembly_lvm-activation-configuring-and-managing-logical-volumes


HOME | GUIDES | LECTURES | LAB | SMTP HEALTH | NU | HTML5
PROXYSELLER — the best individual proxy provider
Copyright © 2021 Pierre-Philipp Braun