install-kvm
authorPeter Palfrader <peter@palfrader.org>
Thu, 2 Apr 2009 10:33:05 +0000 (12:33 +0200)
committerPeter Palfrader <peter@palfrader.org>
Thu, 2 Apr 2009 10:33:05 +0000 (12:33 +0200)
input/howto/install-kvm.creole [new file with mode: 0644]
input/index.mdwn

diff --git a/input/howto/install-kvm.creole b/input/howto/install-kvm.creole
new file mode 100644 (file)
index 0000000..e648ec7
--- /dev/null
@@ -0,0 +1,158 @@
+== Setup a new kvm domain fast ==
+
+Define a shell function
+
+{{{
+# set up environment
+setup_env() {
+ echo -n "New hostname: " &&
+ export LC_ALL=C &&
+ read host &&
+ target=/mnt/target &&
+ mirror=`cat /etc/apt/sources.list /etc/apt/sources.list.d/debian.list 2>/dev/null | awk '/^deb.*debian/ {print $2; exit}'` &&
+ vg=`vgdisplay -c | awk -F: '{print $1;exit}' | sed 's/ *//g'` &&
+ echo "Chosen vg is $vg" &&
+ echo "Chosen mirror is $mirror"
+}
+}}}
+
+And run it
+
+{{{
+setup_env
+}}}
+
+Then install base:
+
+{{{
+#######
+# install base
+
+ apt-get install debootstrap kpartx &&
+ lvcreate -L 128m -n "$host"-boot /dev/"$vg" &&
+ lvcreate -L 4g -n "$host"-root /dev/"$vg" &&
+ lvcreate -L 4g -n "$host"-swap /dev/"$vg" &&
+ : &&
+ ( echo ',,L,*' | sfdisk /dev/"$vg"/"$host"-boot ) &&
+ kpartx -v -a /dev/"$vg"/"$host"-boot &&
+ mkfs.ext3 /dev/mapper/"$vg"-"$host"--boot1 &&
+ mkfs.ext3 /dev/"$vg"/"$host"-root &&
+ mkswap /dev/"$vg"/"$host"-swap &&
+ : &&
+ mkdir -p "$target" &&
+ mount /dev/"$vg"/"$host"-root "$target" &&
+ mkdir -p "$target/boot" &&
+ mount /dev/mapper/"$vg"-"$host"--boot1 "$target/boot" &&
+
+ cd "$target" &&
+ debootstrap --variant=minbase lenny . "$mirror"
+}}}
+
+And finalize the setup:
+
+{{{
+#######
+# finish setup
+ echo "$host" > etc/hostname &&
+ cat > etc/hosts << EOF &&
+127.0.0.1       localhost
+
+# The following lines are desirable for IPv6 capable hosts
+::1     localhost ip6-localhost ip6-loopback
+fe00::0 ip6-localnet
+ff00::0 ip6-mcastprefix
+ff02::1 ip6-allnodes
+ff02::2 ip6-allrouters
+ff02::3 ip6-allhosts
+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/ &&
+ 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 &&
+ #chroot . apt-get remove --purge cpp dpkg-dev g++ gcc gcc-4.2-base libatm1 libdevmapper1.02.1 libgpm2 libc6-dev linux-libc-dev libstdc++6-4.3-dev binutils cpp-4.3 gcc-4.3 gettext-base libgmp3c2 libgomp1 libmpfr1ldbl libtimedate-perl
+ # don't - it may start daemons
+ #chroot . apt-get dist-upgrade
+ chroot . apt-get install grub &&
+ cp -av usr/lib/grub/x86_64-pc boot/grub &&
+ grub << EOF &&
+device (hd0) /dev/mapper/$vg-$host--boot
+root (hd0,0)
+setup (hd0)
+quit
+EOF
+ # install a kernel image
+ echo -e "do_symlinks = yes\nlink_in_boot = yes\ndo_initrd = yes" > etc/kernel-img.conf &&
+ chroot . apt-get install linux-image-2.6-amd64
+
+}}}
+
+And a fstab and a boot loader config
+
+{{{
+ # doesn't work: chroot . update-grub
+ rootuuid=`vol_id /dev/"$vg"/"$host"-root "$target" | awk -F= '$1=="ID_FS_UUID" {print $2}'` &&
+ swapuuid=`vol_id /dev/"$vg"/"$host"-swap "$target" | awk -F= '$1=="ID_FS_UUID" {print $2}'` &&
+ bootuuid=`vol_id /dev/mapper/"$vg"-"$host"--boot1  | 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
+ cat > etc/fstab << EOF &&
+UUID=$rootuuid    /               ext3    errors=remount-ro 0       1
+UUID=$bootuuid    /boot           ext3    defaults        0       2
+UUID=$swapuuid    none            swap    sw              0       0
+EOF
+ cat > etc/network/interfaces << EOF
+auto lo
+iface lo inet loopback
+
+auto eth0
+iface eth0 inet manual
+  pre-up ip link set up dev \$IFACE
+  post-down ip link set down dev \$IFACE
+EOF
+}}}
+
+Maybe fix/setup networking properly:
+
+{{{
+vi etc/network/interfaces
+}}}
+
+And unmount:
+
+{{{
+  cd / &&
+ umount "$target"/boot &&
+ umount "$target" &&
+ kpartx -v -d /dev/"$vg"/"$host"-boot &&
+ rmdir "$target"
+}}}
+
+Setup a new kvm domain by creating a new file in /etc/dm-virt/`hostname/$host.xml.
+
+* Properly configure hostname
+* Pick a new uuid ({{{uuidgen}}})
+* Setup block devices properly
+* pick a new and unique mac address (on d.o every kvm host has their own mac address space and the last block is changed for the guests, as in {{{..:..:..:..:<host byte>:<guest byte>}}}. )
+* virsh commands:
+** {{{virsh define foo.xml}}}
+** {{{virsh start foo}}}
+** {{{virsh destroy foo}}}
+** {{{virsh vncdisplay foo}}} (and ssh -L 5900:localhost:<5900+x> $host  and  vnc localhost)
index 91d2598..4c75fdb 100644 (file)
@@ -25,6 +25,7 @@ VCS repositories for ud-ldap and all our other stuff can be found at
 * [[howto/upgrade-to-lenny]]
 * [[howto/ilo-https]]
 * [[howto/backup]]
+* [[howto/install-kvm]]: How to setup a new kvm domain without going through d-i etc.
 
 ## misc