X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=input%2Fhowto%2Finstall-kvm.creole;h=c72af39489a728a20a34fc2349c22cf7ecf4f434;hb=47ee381fc4a4c3ffb8dd96d506446772e57f109f;hp=d97343da8ec0996dafadc56f4027bf7df09da002;hpb=de9c7bbd863f186b9792801dfb453068f11d6da5;p=mirror%2Fdsa-wiki.git diff --git a/input/howto/install-kvm.creole b/input/howto/install-kvm.creole index d97343d..c72af39 100644 --- a/input/howto/install-kvm.creole +++ b/input/howto/install-kvm.creole @@ -12,7 +12,7 @@ setup_env() { echo -n "New hostname: " && export LC_ALL=C && read guest && - target=/mnt/target && + target="/mnt/target-$guest" && mirror=`cat /etc/apt/sources.list /etc/apt/sources.list.d/debian.list 2>/dev/null | awk '/^deb.*debian/ {print $2; exit}'` && vgdefault=`vgdisplay -c | awk -F: '{print $1;exit}' | sed 's/ *//g'` && echo -n "Volume group? [$vgdefault]: " && @@ -35,10 +35,16 @@ setup_env() { dev_boot="/dev/mapper/$vg-$guest--boot" && echo "Root device will be $dev_root" && echo "Boot device will be $dev_boot" && - fs=ext3 + fs=ext4 fi && - dev_swap="/dev/mapper/$vg-$guest--swap" && - echo -n "Use a /boot filesystem? [Y/n] " && + if [ "$vg" != "" ]; then + dev_swap="/dev/mapper/$vg-$guest--swap" + elif [ -d /SWAPFILES ]; then + dev_swap=/SWAPFILES/$guest-swap + else + echo "No idea how to do swap" && false + fi && + echo -n "Use a /boot filesystem (strongly recommended)? [Y/n] " && read use_boot && echo "Swap device will be $dev_swap" && echo "fs is $fs" @@ -78,7 +84,7 @@ trivial. lvcreate -L 4g -n "$guest"-swap /dev/"$vg" && : && if [ "$use_boot" != "n" ] ; then - ( echo ',,L,*' | sfdisk "$dev_boot" ) && + ( echo ',,L,*' | sfdisk -D "$dev_boot" ) && kpartx -v -a "$dev_boot" && mkfs."$fs" "$dev_boot"1 fi && @@ -93,7 +99,7 @@ trivial. fi && cd "$target" && - debootstrap --variant=minbase --keyring=/usr/share/keyrings/debian-archive-keyring.gpg lenny . "$mirror" + debootstrap --variant=minbase --keyring=/usr/share/keyrings/debian-archive-keyring.gpg squeeze . "$mirror" }}} And finalize the setup: @@ -116,54 +122,39 @@ EOF rm -fv etc/apt/sources.list && ( ! [ -e /etc/apt/sources.list ] || cp /etc/apt/sources.list etc/apt/sources.list) (cp -v /etc/apt/sources.list.d/* etc/apt/sources.list.d/ || true ) && - cp -v /etc/apt/preferences etc/apt/ && + ( ! [ -e /etc/apt/preferences ] || cp -v /etc/apt/preferences etc/apt/ ) && apt-key exportall | chroot . apt-key add - && chroot . apt-get update && echo "Apt::Install-Recommends 0;" > etc/apt/apt.conf.d/local-recommends && - chroot . apt-get install net-tools iproute ifupdown dialog vim netbase xfsprogs && - cp -av $dev_root dev/ && - if [ "$use_boot" != "n" ] ; then - DEBIAN_FRONTEND=noninteractive chroot . apt-get install grub && - cp -av $dev_boot $dev_boot""1 dev/ && - echo "(hd0) /dev/`basename $dev_boot`" > boot/grub/device.map && - if [ -e usr/lib/grub/x86_64-pc ] ; then cp -av usr/lib/grub/x86_64-pc boot/grub ; - else cp -av usr/lib/grub/i386-pc boot/grub ; fi && - grub << EOF && -device (hd0) $dev_boot -root (hd0,0) -setup (hd0) -quit -EOF - # install a kernel image - cat > etc/kernel-img.conf << EOF && -do_symlinks = yes -link_in_boot = yes -do_initrd = yes -EOF - chroot . apt-get install linux-image-2.6-amd64 && - cat >> etc/kernel-img.conf << EOF -postinst_hook = /usr/sbin/update-grub -postrm_hook = /usr/sbin/update-grub -EOF - rm -v dev/"`basename $dev_boot`" dev/"`basename $dev_boot`1" boot/grub/device.map && - else - cat > etc/kernel-img.conf << EOF && + chroot . apt-get install -y net-tools iproute ifupdown dialog vim netbase xfsprogs && + cp -av `readlink -f $dev_root` dev/`basename $dev_root` && + DEBIAN_FRONTEND=noninteractive chroot . apt-get install -y grub2 && + cat > etc/kernel-img.conf << EOF && do_symlinks = no do_initrd = yes EOF - chroot . apt-get install linux-image-2.6-amd64 && - cat >> etc/kernel-img.conf << EOF -postinst_hook = update-grub -postrm_hook = update-grub -EOF - DEBIAN_FRONTEND=noninteractive chroot . apt-get install grub2 && + if [ "$use_boot" != "n" ] ; then + cp -av `readlink -f $dev_boot` dev/`basename $dev_boot` && + cp -av `readlink -f $dev_boot""1` dev/`basename $dev_boot`1 && + chroot . grub-install --modules=part_msdos /dev/`basename $dev_boot` && + # install a kernel image + chroot . apt-get install -y linux-image-2.6-amd64 && + sed -i -e 's/^#GRUB_TERMINAL=console/GRUB_TERMINAL=console/' etc/default/grub && + echo "(hd0) /dev/`basename $dev_boot`" > boot/grub/device.map && + chroot . update-grub && + sed -i -e "s#dev/`basename $dev_boot`1#dev/hda1#g" boot/grub/grub.cfg && + rm -v dev/"`basename $dev_boot`" dev/"`basename $dev_boot`1" + else + echo && echo && echo && echo "Hardly tested, expect this to fail." && echo && echo && echo && echo "(hd0) /dev/`basename $dev_root`" > boot/grub/device.map && chroot . grub-install /dev/"`basename $dev_root`" && + # install a kernel image + chroot . apt-get install -y linux-image-2.6-amd64 && sed -i -e 's/^#GRUB_TERMINAL=console/GRUB_TERMINAL=console/' etc/default/grub && - chroot . update-grub && - sed -i -e "s#dev/`basename $dev_root`#dev/vda#g" boot/grub/grub.cfg - rm -v boot/grub/device.map + chroot . update-grub fi && + sed -i -e "s#dev/`basename $dev_root`#dev/vda#g" boot/grub/grub.cfg && + rm -v boot/grub/device.map && rm -v dev/"`basename $dev_root`" }}} @@ -171,28 +162,9 @@ And a fstab and a boot loader config {{{ # doesn't work: chroot . update-grub - rootuuid=`vol_id "$dev_root" "$target" | awk -F= '$1=="ID_FS_UUID" {print $2}'` && - swapuuid=`vol_id "$dev_swap" "$target" | awk -F= '$1=="ID_FS_UUID" {print $2}'` && - if [ "$use_boot" != "n" ] ; then - bootuuid=`vol_id "$dev_boot"1 | awk -F= '$1=="ID_FS_UUID" {print $2}'` && - cat > boot/grub/menu.lst << EOF -default 0 -timeout 5 -color cyan/blue white/blue - -### BEGIN AUTOMAGIC KERNELS LIST -# kopt=root=UUID=$rootuuid ro - -## ## End Default Options ## -title Debian -root (hd0,0) -kernel /vmlinuz root=UUID=$rootuuid ro -initrd /initrd.img - -### END DEBIAN AUTOMAGIC KERNELS LIST -EOF - fi && - if [ "$fs" = "ext3" ]; then + rootuuid=`blkid -s UUID -o value "$dev_root"` && + swapuuid=`blkid -s UUID -o value "$dev_swap"` && + if [ "$fs" = "ext4" ]; then rootopts="errors=remount-ro" else rootopts="defaults" @@ -202,6 +174,7 @@ UUID=$rootuuid / $fs $rootopts 0 1 UUID=$swapuuid none swap sw 0 0 EOF if [ "$use_boot" != "n" ] ; then + bootuuid=`blkid -s UUID -o value "$dev_boot"1` && echo "UUID=$bootuuid /boot $fs defaults 0 2" >> etc/fstab fi cat > etc/network/interfaces << EOF @@ -221,6 +194,19 @@ Maybe fix/setup networking properly: vi etc/network/interfaces }}} +And set a password: +{{{ +chroot . passwd +}}} + +Set a nameserver config that works once the VM has booted. Later in the process we will install unbound anyway. +{{{ +cat > etc/resolv.conf << EOF +nameserver 8.8.8.8 +search debian.org +EOF +}}} + And unmount: {{{ @@ -235,7 +221,7 @@ And unmount: === virsh setup === -Setup a new kvm domain by creating a new file in /etc/da-virt/`hostname/$guest.xml. +Setup a new kvm domain by creating a new file in /etc/dsa-kvm/`hostname/$guest.xml. * Properly configure hostname * Pick a new uuid ({{{uuidgen}}})