vmtemplate . I installed Gentoo for this section (the installation steps are similar to the steps in the standard Gentoo Handbook manual), as well as additional software that I chose based on which services will eventually work inside virtual machines (so that the “difference” between them is minimal). As a result, I got such a list of additional software: #!/bin/sh ROOT=/mnt/gentoo DEV=/dev/xenguests/vm-template-gentoo echo "Mounting filesystems" mount $DEV $ROOT mount -t proc none $ROOT/proc mount --bind /dev $ROOT/dev mount --bind /usr/portage $ROOT/usr/portage cp /etc/resolv.conf $ROOT/etc/resolv.conf chroot $ROOT /bin/bash echo "Unmounting filesystems" umount $ROOT/dev $ROOT/proc $ROOT/usr/portage umount $ROOT CONFIG_PAX_RANDKSTACK function in the kernel (Randomize kernel stack base) related to PAX.vm-site1 . The size of this section in my case is 1 GB (the size of the partition from the reference VM is 8 GB). FS on both sections - ext4.sys-fs/aufs3 on the main system - we will need it soon./etc/genkernel.conf file /etc/genkernel.conf uncomment the line: ALLRAMDISKMODULES="1" - this is necessary for the newly installed aufs module to be copied to ramdisk, which we will create using genkernel. I did not find a more elegant way of doing this, and I did not want to edit the system files in /usr/share/genkernel .overlay folder, inside it a file with the name init , which is made executable: #!/bin/busybox sh mount -t proc -o noexec,nosuid,nodev proc /proc >/dev/null 2>&1 mount -o remount,rw / >/dev/null 2>&1 /bin/busybox --install -s if [ "$0" = '/init' ] then [ -e /linuxrc ] && rm /linuxrc fi modprobe xen-blkfront RO=/dev/xvda1 RW=/dev/xvda2 mknod /dev/xvda1 b 202 1 mknod /dev/xvda2 b 202 2 modprobe aufs mkdir /aufs mkdir /rw mkdir /ro mount $RO /ro mount $RW /rw mount -t aufs -o dirs=/rw:/ro=ro aufs /aufs [ -d /aufs/ro ] || mkdir /aufs/ro [ -d /aufs/rw ] || mkdir /aufs/rw mount --move /ro /aufs/ro mount --move /rw /aufs/rw cat /aufs/ro/etc/fstab | grep -v ' / ' | grep -v swap >> /aufs/etc/fstab ROTYPE=$(cat /proc/mounts | grep $RO | cut -d' ' -f3) ROOPTIONS=$(cat /proc/mounts | grep $RO | cut -d' ' -f4) RWTYPE=$(cat /proc/mounts | grep $RW | cut -d' ' -f3) RWOPTIONS=$(cat /proc/mounts | grep $RW | cut -d' ' -f4) echo $RO /ro $ROTYPE $ROOPTIONS 0 0 > /aufs/etc/fstab echo $RW /rw $RWTYPE $RWOPTIONS 0 0 >> /aufs/etc/fstab echo "cp /proc/mounts /etc/mtab" > /aufs/etc/local.d/mtab.start chmod a+x /aufs/etc/local.d/mtab.start echo "sysctl -w kernel.grsecurity.grsec_lock=1" > /aufs/etc/local.d/grsec.start chmod a+x /aufs/etc/local.d/grsec.start exec /sbin/switch_root -c "/dev/console" /aufs /sbin/init #!/bin/sh VERSION=`uname -r` MODULE=`modprobe -nv aufs | cut -d' ' -f2` if [ ! -f $MODULE ]; then echo "aufs module not found on your system" fi genkernel initramfs --no-install --no-postclear --initramfs-overlay=/home/xen/overlay cp -v /var/tmp/genkernel/initramfs-${VERSION} /boot/initramfs-domU /dev/xvda2 , and /dev/xvda1 is our reference image, the files in which we can update if desired, and the updates will “pick up” all virtual machines (at the time of updating the reference image of the machine should be stopped). The partition with the data of a specific virtual machine (in our case, the LVM partition of vm-site1 , contains only differences from the reference filesystem, it can also be freely mounted on the host system, make changes to files, make backup copies, etc. kernel = "/boot/vmlinuz" ramdisk = "/boot/initramfs-domU" memory = 128 name = "site1" vcpus = 1 disk = [ "phy:/dev/xenguests/vm-template,xvda1,r", "phy:/dev/xenguests/vm-site1,xvda2,w" ] root = "/dev/xvda1 ro" extra = "xencons=tty" on_poweroff = "destroy" on_reboot = "restart" on_crash = "destroy" vif = [ "mac=0a:11:10:24:14:20,bridge=br1" ] dhcp = "dhcp" Source: https://habr.com/ru/post/183686/
All Articles