CRUX as a XEN/PV Guest

tested with release 3.4

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

Requirements

Get the latest CRUX release

cd /data/ISO-IMAGES/

wget http://mirror.neolabs.kz/crux/crux-3.4/iso/crux-3.4.iso
wget http://ftp.morpheus.net/pub/linux/crux/crux-3.4/iso/crux-3.4.md5
md5sum crux-3.4.iso
cat crux-3.4.md5

#wget https://crux.ninja/updated-iso/crux-3.4-updated.iso
#wget https://crux.ninja/updated-iso/crux-3.4-updated.md5
#md5sum crux-3.4-updated.iso
#cat crux-3.4-updated.md5

Create a XEN/PV skeleton for it

cd /data/guests/crux/
dd if=/dev/zero of=crux.ext4 bs=1G count=0 seek=4
mkfs.ext4 crux.ext4

Fixing the rootfs

Mount the install media,

mkdir cdrom/
mount -o loop,ro /data/ISO-IMAGES/crux-3.4.iso cdrom/

Make the PV compatible kernel and initramfs available

cp cdrom/boot/vmlinuz cdrom/boot/initramfs ./

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

mkdir lala/ etc/
tar xJf cdrom/rootfs.tar.xz -C lala/
#less lala/usr/bin/serial_console
cp lala/etc/inittab etc/
rm -rf lala/
vi etc/inittab

#c1:2:respawn:/sbin/agetty --autologin root --noclear 38400 tty1 linux
c1:2:respawn:/sbin/agetty --autologin root --noclear 38400 hvc0 linux
#c1:2:respawn:/sbin/agetty --autologin root --noclear 115200,38400,9600 hvc0 linux

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

xzcat cdrom/rootfs.tar.xz > rootfs.tar
tar --append -f rootfs.tar etc/inittab
tar tvf rootfs.tar | tail
xz -z rootfs.tar 

Now enable your fix into a new install media image,

rm -f media.ext4
ls -lkF /data/ISO-IMAGES/crux-3.4.iso 
dd if=/dev/zero of=media.ext4 bs=1G count=0 seek=1
mkfs.ext4 media.ext4
mkdir media/
mount -o loop,rw media.ext4 media/
cp -a cdrom/* media/
cp -f rootfs.tar.xz media/
du -sk media/
umount media/
rmdir media/

Further clean-up

rm -f rootfs.tar.xz
rm -rf etc/
umount cdrom/
rmdir cdrom/

Ready to run the XEN/PV guest

vi crux

kernel = "/data/guests/crux/vmlinuz"
ramdisk = "/data/guests/crux/initramfs"
extra = "console=hvc0"
#root = "/dev/xvda ro"
name = "crux"
memory = 4096
vcups = 4
disk = ['file:/data/guests/crux/crux.ext4,xvda,w',
        'file:/data/guests/crux/media.ext4,xvdb,r']
vif = [ 'vifname=crux.0' ]

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)

HVM Mode

cd /data/guests/cruxhvm/
dd if=/dev/zero of=cruxhvm.ext4 bs=1G count=0 seek=4
mkfs.ext4 cruxhvm.ext4

vi cruxhvm

#type = "hvm"
builder = "hvm"
sdl = 1

name = "cruxhvm"
memory = 1024
vcups = 4
disk = ['file:/data/guests/cruxhvm/cruxhvm.ext4,xvda,w',
    'file:/data/ISO-IMAGES/crux-3.4.iso,hdc:cdrom,r']
vif = [ 'vifname=cruxhvm.0' ]

on_reboot = "preserve"
on_crash = "preserve"

xl create cruxhvm -c

fb1280

Resources


Nethence | Doc | Pub | Lab | Pbraun | SNE Russia | xhtml