XEN guest // CRUX using installer

guest-crux | guest-crux-rootfs | guest-crux-hvm

DRAFT

Introduction

CRUX comes with an installer. I prefer to bootstrap it manually](guest-crux) but since I went through the pain of runing the installer once, to show up properly on a XEN console, here we go.

Their kernel and RAMDISK load fine as PV guest (and displays with console=hvc0). However their installer env rootfs does not show any prompt. This is what we are fixing over here.

Requirements

see guest-crux for grabbing the release and mount to loop/

Fix the install media

Fix the agetty console thing for it to be XEN/PV ready

cd /root/ISO-IMAGES/

mkdir tmp/
tar xJf loop/rootfs.tar.xz -C tmp/

cp -a tmp/etc/inittab ./

vi inittab

c1:2:respawn:/sbin/agetty --autologin root --noclear 115200 hvc0 linux
(and remove c2 to c6)

ls -lhF tmp/usr/bin/serial_console
rm -rf tmp/

and APPEND it to the existing rootfs (otherwise you would face issues with /dev)

#tar: Cannot update compressed archives
xzcat loop/rootfs.tar.xz > rootfs.tar
tar --append -f rootfs.tar etc/inittab
tar tvf rootfs.tar | tail
rm -rf etc/

time xz -z rootfs.tar
# 2m56.727s

now enable your fix into a new install media image

dd if=/dev/zero of=crux-$ver-xen.ext4 bs=1G count=0 seek=2
mkfs.ext4 crux-$ver-xen.ext4
mkdir media/
mount crux-$ver-xen.ext4 media/
cp -a loop/* media/
cp -f rootfs.tar.xz media/
du -sh media/
umount media/
rmdir media/
rm -f rootfs.tar.xz

Ready to go

make the PV compatible kernel and initramfs available

mkdir -p /data/kernels/crux/
ls -lhF /data/kernels/crux/
cp -i loop/boot/vmlinuz loop/boot/initramfs /data/kernels/crux/
umount loop/

setup the guest skeleton

cd /root/guests/crux/
vi crux

kernel = "/data/kernels/crux/vmlinuz"
ramdisk = "/data/kernels/crux/initramfs"

# installer
root = "/dev/xvdb1 ro console=hvc0 net.ifnames=0 biosdevname=0 mitigations=off"

# to-be vdisk
#root = "/dev/xvda1 ro console=hvc0 net.ifnames=0 biosdevname=0 mitigations=off"

name = "crux"
vcpus = 2
memory = 1024
disk = ['file:/root/guests/crux/crux.reiser4,xvda1,w',
    'file:/root/ISO-IMAGES/crux-3.7-xen.ext4,xvdb1,r']
vif = [ 'bridge=guestbr0,vifname=crux0','bridge=br0,vifname=crux1' ]

xl create crux -c

System Installation

mount /dev/xvda /mnt
setup

add xvda and eventually tmpfs

#devpts /dev/pts devpts noexec,nosuid,gid=tty,mode=0620 0 0
#shm /dev/shm tmpfs defaults 0 0
cat >> /mnt/etc/fstab <<EOF
/dev/xvda / ext4 defaults 0 1
tmp /tmp tmpfs defaults 0 0
EOF
cat /mnt/etc/fstab

cp -pi /mnt/etc/rc.conf /mnt/etc/rc.conf.dist
vi /mnt/etc/rc.conf

TIMEZONE=Europe/Moscow
HOSTNAME=crux

do not forget to fix the inittab YET AGAIN

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

#c1:2:respawn:/sbin/agetty --noclear 38400 tty1 linux
c1:2:respawn:/sbin/agetty --noclear 38400 hvc0 linux

cp -pi /mnt/etc/securetty /mnt/etc/securetty.dist
echo hvc0 >> /mnt/etc/securetty
cat /mnt/etc/securetty

ls -lkF /lib/modules/4.14.40/

sync
umount /mnt/
poweroff

Now disable the customized install media and boot normally

vi crux

root = "/dev/xvda ro"

disk = ['file:/data/guests/crux/crux.ext4,xvda,w']
#        'file:/data/guests/crux/media.ext4,xvdb,r']

NOTE THAT WE ARE KEEPING THE RAMDISK (see Troubleshooting to see what happens if not) – that seems to be the CRUX way to boot normally.

xl create crux -c

Additional Notes & Maintenance

In case you need to chroot into it for some reason

#mount --bind /dev lala/dev
#mount --bind /tmp lala/tmp
#mount -t proc proc lala/proc
#mount -t sysfs none lala/sys
#chroot lala/ /bin/bash
#passwd
#localedef -i en_US -f UTF-8 en_US.UTF-8
#sync
#^D
#umount lala/{dev,tmp,proc,sys}

and eventually make a template out of this

cd /data/guests/
time tar cSf /data/templates/crux.`date +%s`.tar crux/
ls -lhF /data/templates/crux.*.tar

Troubleshooting

   * Copying devices from rootfs... cp: can't create '/newroot/dev/btrfs-control': No such file or directory

==> do not copy rootfs’s /dev/, use tar --append instead

blkfront: xvda: flush diskcache: enabled; persistent grants: enabled; indirect descriptors: enabled;
xenbus_probe_frontend: Device with no driver: device/vif/0
hctosys: unable to open rtc device (rtc0)
List of all partitions:
ca00         4194304 xvda 
 driver: vbd
No filesystem could mount root, tried: 

Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(202,0)
CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.14.40 #1
Call Trace:
 dump_stack+0x5c/0x78
 panic+0xd0/0x218
 mount_block_root+0x273/0x290
 ? set_debug_rodata+0xc/0xc
 prepare_namespace+0x12b/0x161
 kernel_init_freeable+0x18e/0x19b
 ? rest_init+0xa0/0xa0
 kernel_init+0x5/0xed
 ret_from_fork+0x35/0x40
Kernel Offset: disabled

==> keep the RAMDISK installer (seems to be the CRUX way to boot normally)

tar: short read

==> maybe one should not append to .tar.xz afterall, busybox doesn’t seem to like it


HOME | GUIDES | LECTURES | LAB | SMTP HEALTH | HTML5 | CONTACT
Copyright © 2024 Pierre-Philipp Braun