Compiling a XEN domU Linux kernel

Get the latest mainline or xen testing kernel and,

cd /usr/src/
wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.18.13.tar.xz
tar xJf linux-4.18.13.tar.xz
ln -s linux-4.18.13 linux

wget https://sourceforge.net/projects/reiser4/files/reiser4-for-linux-4.x/reiser4-for-4.18.0.patch.gz/download# -O reiser4-for-4.18.0.patch.gz

cd /usr/src/linux/
zcat ../reiser4-for-4.18.0.patch.gz | patch -p1

#make -j16 distclean
#https://www.kernel.org/doc/makehelp.txt
#make -j16 mrproper
ls -alhF .config* # does not exist yet

cp -pi Makefile Makefile.dist
vi Makefile

EXTRAVERSION = .domureiser4

make help | grep defconfig
#make ARCH=x86_64 tinyconfig
#make ARCH=x86_64 defconfig
make -j16 x86_64_defconfig

cat >> .config <<-EOF0
CONFIG_HYPERVISOR_GUEST=y
CONFIG_PARAVIRT=y
CONFIG_XEN=y
CONFIG_PARAVIRT_GUEST=y
CONFIG_PARAVIRT_SPINLOCKS=y
CONFIG_HVC_DRIVER=y
CONFIG_HVC_XEN=y
CONFIG_XEN_FBDEV_FRONTEND=y
CONFIG_XEN_BLKDEV_FRONTEND=y
CONFIG_XEN_NETDEV_FRONTEND=y
CONFIG_XEN_PCIDEV_FRONTEND=y
CONFIG_INPUT_XEN_KBDDEV_FRONTEND=y
CONFIG_XEN_FBDEV_FRONTEND=y
CONFIG_XEN_XENBUS_FRONTEND=y
CONFIG_XEN_SAVE_RESTORE=y
CONFIG_XEN_GRANT_DEV_ALLOC=m
CONFIG_XEN_TMEM=y
CONFIG_CLEANCACHE=y
CONFIG_FRONTSWAP=y
CONFIG_XEN_SELFBALLOONING=y
EOF0
make oldconfig

those defaults are fine already when pressing ENTER,

CONFIG_XEN_PV=y
CONFIG_XEN_PVHVM=y
CONFIG_XEN_512GB=y
CONFIG_KVM_GUEST=y
CONFIG_HVC_XEN_FRONTEND=y
CONFIG_PTP_1588_CLOCK_KVM=y
CONFIG_XEN_BALLOON=y
CONFIG_XEN_SCRUB_PAGES=y
CONFIG_XEN_DEV_EVTCHN=y
CONFIG_XENFS=y
CONFIG_XEN_COMPAT_XENFS=y
CONFIG_XEN_SYS_HYPERVISOR=y
CONFIG_XEN_GNTDEV=m

but those need to be changed,

cat >> .config <<-EOF0
CONFIG_XEN_DOM0=n
CONFIG_XEN_PVH=y
EOF0
make oldconfig

and maybe even those?

#MOUSE_PS2_VMMOUSE=n ?
#XEN_WDT=n ?
#XEN_PVCALLS_FRONTEND=n ?

interesting, hyperv,

#HYPERV=n ?
#CONFIG_PCI_HYPERV=y
#CONFIG_HYPERV_NET=y
#CONFIG_HID_HYPERV_MOUSE=y
#CONFIG_HYPERV_KEYBOARD=y
#CONFIG_FB_HYPERV=y
#CONFIG_HYPERV_UTILS=y
#CONFIG_HYPERV_BALLOON=y

some file-systems,

cat >> .config <<-EOF0
CONFIG_BTRFS_FS=y
CONFIG_GFS2_FS=y
CONFIG_JFS_FS=y
CONFIG_REISERFS_FS=y
CONFIG_XFS_FS=y
EOF0
echo CONFIG_REISER4_FS=y >> .config
echo CONFIG_BLK_DEV_RBD=y >> .config
make oldconfig

more stuff,

cat >> .config <<-EOF0
CONFIG_BRIDGE=y
CONFIG_VLAN_8021Q=y
EOF0
make oldconfig

(optional)

cat >> .config <<-EOF9
CONFIG_DEBUG_INFO=y
CONFIG_CRASH_DUMP=y
CONFIG_PROC_VMCORE=y
EOF9
make oldconfig

disable modules,

grep =m$ .config
mv -f .config .config.m
#sed 's/=m$/=n/' .config.m > .config
sed 's/=m$/=y/' .config.m > .config
make oldconfig
grep =m$ .config
#CONFIG_XEN_TMEM=m remains!

j=$((`grep ^processor /proc/cpuinfo  | tail -1 | awk '{print $3}'` + 1))
echo $j
time make -j$j > make.domureiser4.log && echo done

as the freaking XEM_TMEM module keeps being a module,

version=`file arch/x86/boot/bzImage | awk '{print $9}'`

ls -lhF /lib/modules/
rm -rf /lib/modules/old-folder-if-exists/
make -j$j modules_install >/dev/null && echo done

cd /lib/modules/
tar czf lib.modules.$version.tar.gz $version/
mv lib.modules.$version.tar.gz /data/kernels/
rm -rf $version/
tar tvzf /data/kernels/lib.modules.$version.tar.gz 

cd /usr/src/linux/
ls -lF arch/x86_64/boot/bzImage
ls -lF arch/x86/boot/bzImage # 10260160
cp -f arch/x86/boot/bzImage /data/kernels/vmlinuz.$version
cp -f .config /data/kernels/vmlinuz.$version.config
cp -f System.map /data/kernels/vmlinuz.$version.map
mv /data/kernels/vmlinuz /data/kernels/vmlinuz.old
ln -s vmlinuz.$version /data/kernels/vmlinuz
ls -l /data/kernels/

unset version

update the guests' configuration,

kernel = "/data/kernels/vmlinuz"

Troubleshooting

if you get this error while booting the guest,

No filesystem could mount root, tried:  ext3 ext2 ext4 vfat msdos iso9660
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(202,1)

==> it may see the disk, however the filesystem driver is missing (here CONFIG_XFS_FS=y)

References

trash

CONFIG_BRIDGE_NF_EBTABLES=y
CONFIG_BRIDGE_EBT_BROUTE=y
CONFIG_BRIDGE_EBT_T_FILTER=y
CONFIG_BRIDGE_EBT_T_NAT=y
CONFIG_BRIDGE_EBT_802_3=y
CONFIG_BRIDGE_EBT_AMONG=y
CONFIG_BRIDGE_EBT_ARP=y
CONFIG_BRIDGE_EBT_IP=y
CONFIG_BRIDGE_EBT_IP6=y
CONFIG_BRIDGE_EBT_LIMIT=y
CONFIG_BRIDGE_EBT_MARK=y
CONFIG_BRIDGE_EBT_PKTTYPE=y
CONFIG_BRIDGE_EBT_STP=y
CONFIG_BRIDGE_EBT_VLAN=y
CONFIG_BRIDGE_EBT_ARPREPLY=y
CONFIG_BRIDGE_EBT_DNAT=y
CONFIG_BRIDGE_EBT_MARK_T=y
CONFIG_BRIDGE_EBT_REDIRECT=y
CONFIG_BRIDGE_EBT_SNAT=y
CONFIG_BRIDGE_EBT_LOG=y
CONFIG_BRIDGE_EBT_NFLOG=y
CONFIG_INFINIBAND=y
CONFIG_INFINIBAND_ISER=y
CONFIG_SCSI_LOWLEVEL=y
CONFIG_ISCSI_TCP=y

grep ^CONFIG_BRIDGE .config
grep ^CONFIG_VLAN_8021Q .config
grep ^CONFIG_INFINIBAND_ISER .config
grep ^CONFIG_SCSI_LOWLEVEL .config
grep ^CONFIG_ISCSI_TCP .config


#ls -lhF /lib/modules/
#rm -rf /lib/modules/4.4.14.domu/
#make modules_install
#rm -f /data/guests/vmlinuz.4.4.14.domu.modules.tar.gz
#tar czpf /data/guests/vmlinuz.4.4.14.domu.modules.tar.gz /lib/modules/4.4.14.domu/

you also need to update the guests e.g.,

cd /data/guests/
xl shu guest1 && xl console guest1
mkdir lala/
mount -o loop guest1/guest1.img lala/
rm -rf lala/lib/modules/4.4.14.domu/
tar xzf vmlinuz.4.4.14.domu.modules.tar.gz -C lala/
ls -ldhF lala/lib/modules/4.4.14.domu/
umount lala/
rmdir lala/
xl create guest1/guest1 -c
#depmod -a