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

dd if=/dev/zero of=$guest.ext4 bs=1G count=0 seek=5
dd if=/dev/zero of=$guest.reiser4 bs=1G count=0 seek=5

RAM should be in GiB not GB

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

a QCOW2 sparse file

...

or a freaking drbd thin provisioned vdisk

File-systems

then format and mount it

mkfs.ext4 $guest.ext4
mount $guest.ext4 lala/

mkfs.reiser4 --yes --force $guest.reiser4
mount $guest.reiser4 lala/

#mkswap $guest.swap

as for LVM thin provisioning

mkfs.reiser4 -y /dev/vdisks/thin1
fsck.reiser4 -y /dev/vdisks/thin1
mkdir lala/
mount /dev/vdisks/thin1 lala/

as for DRBD (possibly over LVM thin provisioning)

mkfs.reiser4 -y /dev/drbd1
fsck.reiser4 -y /dev/drbd1
mkdir lala/
mount /dev/drbd1 lala/

Install from XEN host

wget https://pub.nethence.com/bin/slack/slackinst.bash.txt
mv -i slackinst.bash.txt slackinst.bash
chmod +x slackinst.bash
#this may loose _some_ sparse out of the file...
#rm -rf lala/*
vi slackstart.conf #newfile

#mirror=https://mirror.yandex.ru/slackware/slackware64-current/
mirror=http://nephtys.lip6.fr/pub/linux/distributions/slackware/slackware64-current/
#mirror=http://x.x.x.x/slackware142/

./slackinst.bash lala

Setup from XEN host

this is otherwise automated using the postxen.bash script

wget https://pub.nethence.com/bin/slack/postxen.bash.txt
mv postxen.bash.txt postxen.bash
chmod +x postxen.bash

./postxen.bash $guest

of if you want to proceed manually

ls -ldF lala/dev/pts/ #exists
ls -ldF lala/dev/shm/ #exists
ls -lF lala/etc/fstab #noexist

cat > lala/etc/fstab <<-EOF
#/dev/xvda1 / ext4 defaults 1 1
/dev/xvda1 / reiser4 defaults 1 1
#/dev/xvda2 swap swap defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
proc /proc proc defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
EOF
cat lala/etc/fstab

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

wget https://slackware.uk/slackonly/14.2-x86_64/libraries/libaal/libaal-1.0.6-x86_64-1_slonly.txz
wget https://slackware.uk/slackonly/14.2-x86_64/system/reiser4progs/reiser4progs-1.1.0-x86_64-2_slonly.txz

installpkg --terse --root lala/ libaal-1.0.6-x86_64-1_slonly.txz
installpkg --terse --root lala/ reiser4progs-1.1.0-x86_64-2_slonly.txz

Get rid of a few packages unnecessary packages for XEN/PV

removepkgs="kernel-* floppy lilo reiserfsprogs smartmontools ntp"
for pkg in $removepkgs; do
            chroot lala ls -lF lala/var/log/packages/$pkg
            echo -n removing $pkg...
            chroot lala removepkg $pkg >/dev/null && echo done
    done; unset pkg

only root can log in

echo non-root login has been disabled > lala/etc/nologin

update CA certificates

chroot lala which c_rehash
chroot lala update-ca-certificates

disabling useless shit from rc.d – tag ADD

ls -lF \
lala/etc/rc.d/rc.cpufreq \
lala/etc/rc.d/rc.loop
chmod -x lala/etc/rc.d/rc.cpufreq
chmod -x lala/etc/rc.d/rc.loop

do not disable those

ls -lF \
lala/etc/rc.d/rc.modules \
lala/etc/rc.d/rc.modules.local
#chmod -x lala/etc/rc.d/rc.modules
#chmod -x lala/etc/rc.d/rc.modules.local

disabling useless shit from rc.d – tag REC

ls -lF \
lala/etc/rc.d/rc.bluetooth \
lala/etc/rc.d/rc.cgmanager \
lala/etc/rc.d/rc.cgproxy \
lala/etc/rc.d/rc.inetd
chmod -x lala/etc/rc.d/rc.bluetooth
chmod -x lala/etc/rc.d/rc.cgmanager
chmod -x lala/etc/rc.d/rc.cgproxy
chmod -x lala/etc/rc.d/rc.inetd

ls -lF \
lala/etc/rc.d/rc.consolekit \
lala/etc/rc.d/rc.mcelog
#chmod -x lala/etc/rc.d/rc.consolekit
#chmod -x lala/etc/rc.d/rc.mcelog

checking overall enabled scripts

ls -lF lala/etc/rc.d/
ls -lF lala/etc/rc.d/rc.udev #already executable

fix the xen guest serial console

ls -lF lala/etc/termcap #needed
ls -lF lala/sbin/agetty #needed

cp -pi lala/etc/inittab lala/etc/inittab.dist
vi lala/etc/inittab

# Local serial lines:
s1:12345:respawn:/sbin/agetty --noclear 115200,38400,9600 hvc0 linux

echo hvc0 >> lala/etc/securetty
cat lala/etc/securetty

fix the timezone

ls -lF lala/etc/localtime-copied-from lala/etc/localtime
rm -f lala/etc/localtime-copied-from lala/etc/localtime
ln -s ../usr/share/zoneinfo/Europe/Moscow lala/etc/localtime
#ln -s ../usr/share/zoneinfo/Europe/Paris lala/etc/localtime

enable TMEM

ls -alF lala/lib/modules/
rm -rf lala/lib/modules/*
ls -lF /data/kernels/lib.modules.*
file /data/kernels/vmlinuz

tar xzf /data/kernels/lib.modules.5.2.21.lightUreiser4.tar.gz -C lala/lib/modules/
ls -lF lala/etc/rc.d/rc.modules*

echo /sbin/modprobe tmem >> lala/etc/rc.d/rc.modules.local
cat lala/etc/rc.d/rc.modules.local

avoid a boot time error on powersave

cp -pi lala/etc/rc.d/rc.M lala/etc/rc.d/rc.M.dist
chmod -x lala/etc/rc.d/rc.M.dist
vi lala/etc/rc.d/rc.M

#/bin/setterm -blank 15 -powersave powerdown -powerdown 60

while on current, it became simplier

chmod -x lala/etc/rc.d/rc.setterm

eventually proceed with a brutal network setup

eventually make a guest template out of this and unless you want to proceed with a full post-install

ls -lF lala/etc/ssh/ssh_host_*
rm -vf lala/etc/ssh/ssh_host_*

finish-up

ls -ldF lala/installpkg-*/
#rm -rf lala/installpkg-*/
du -sh lala/
# Jun 06, 2020 -- minimal 494M

#mklost+found ...
umount lala/

eventually re-create lost+found

fsck.ext4 -fy $guest.ext4

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/drbd1,xvda1,w']
vif = [ 'bridge=xenbr0, vifname=$guest.0' ]
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

NETHENCE | PUB | LAB