#!/bin/bash # # $Header$ # # Build and copy pristine root filesystem to host roots for Xen # # Copyright (C) 2005 Christopher G. Stach II # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # Here's the diff to set up a single xenU guest -cgs # diff -ur /etc/xen/xmexample1 /etc/xen/auto/db1.foo.domain.tld # --- /etc/xen/xmexample1 2005-05-31 16:42:31.000000000 -0500 # +++ /etc/xen/auto/db1.foo.domain.tld 2005-06-02 16:53:56.000000000 -0500 # @@ -8,7 +8,7 @@ # # #---------------------------------------------------------------------------- # # Kernel image file. # -kernel = "/boot/vmlinuz-2.6.10-xenU" # +kernel = "/boot/vmlinuz-2.6.11.10-xenU" # # # Optional ramdisk. # #ramdisk = "/boot/initrd.gz" # @@ -20,7 +20,7 @@ # memory = 64 # # # A name for your domain. All domains must have different names. # -name = "ExampleDomain" # +name = "db1.foo.domain.tld" # # # Which CPU to start domain on? # #cpu = -1 # leave to Xen to pick # @@ -34,6 +34,7 @@ # # Optionally define mac and/or bridge for the network interfaces. # # Random MACs are assigned if not given. # #vif = [ 'mac=aa:00:00:00:00:11, bridge=xen-br0' ] # +vif = [ 'mac=de:ad:c0:ff:ee:01' ] # # #---------------------------------------------------------------------------- # # Define the disk devices you want the domain to have access to, and # @@ -42,7 +43,7 @@ # # where UNAME is the device, DEV is the device name the domain will see, # # and MODE is r for read-only, w for read-write. # # -disk = [ 'phy:hda1,hda1,w' ] # +disk = [ 'phy:vg0/db1-root,sda1,w', 'phy:vg0/db1-swap,sda2,w', 'phy:vg0/db1-share,sda3,w' ] # # #---------------------------------------------------------------------------- # # Set the kernel command line for the new domain. # @@ -61,7 +62,7 @@ # #hostname= "vm%d" % vmid # # # Set root device. # -root = "/dev/hda1 ro" # +root = "/dev/sda1 ro" # # # Root device for nfs. # #root = "/dev/nfs" # @@ -71,7 +72,7 @@ # #nfs_root = '/full/path/to/root/directory' # # # Sets runlevel 4. # -extra = "4" # +#extra = "4" # # #---------------------------------------------------------------------------- # # Set according to whether you want the domain restarted when it exits. # All of the hosts we'll configure -cgs readonly HOSTS="db1 ldap1 nms1 ns1 rsync1 www1" # Hosts that need some dedicated partitions -cgs readonly SHARE_HOSTS="db1 srv1" # These hosts belong to this domain -cgs readonly DOMAIN="foo.domain.tld" # This can be an entire disk, also. If it is, don't use grub on it! -cgs readonly LVM_DEV="/dev/hdb1" readonly VOLGROUP="vg0" readonly NEW_ROOT="/mnt/new" readonly PRISTINE_ROOT="/mnt/pristine" readonly PRISTINE_NAME="pristine-`/bin/date +'%Y%m%d'`-root" # # Pick a mirror. This is the one I used. -cgs # # NO TRAILING SLASH! -cgs # readonly STAGE1PATH="http://gentoo.chem.wisc.edu/gentoo/releases/x86/2005.0/stages/x86" readonly STAGE1FILE="stage1-x86-2005.0.tar.bz2" function build_lv() { echo "Building LV ${2} / '${1}'..." /sbin/lvcreate -L${2} -n ${1} ${VOLGROUP} /sbin/mke2fs -v -M / -L / -j /dev/${VOLGROUP}/${1} } function build_lv_swap() { echo "Building LV ${2} swap '${1}'..." /sbin/lvcreate -L${2} -n ${1} ${VOLGROUP} /sbin/mkswap -c /dev/${VOLGROUP}/${1} } function build_lv_share() { echo "Building LV ${2} /mnt/share '${1}'..." /sbin/lvcreate -L${2} -n ${1} ${VOLGROUP} /sbin/mke2fs -v -M /mnt/share -L /mnt/share -j /dev/${VOLGROUP}/${1} } /sbin/pvcreate -M2 ${LVM_DEV} /sbin/vgcreate ${VOLGROUP} ${LVM_DEV} build_lv ${PRISTINE_NAME} 4G /bin/mkdir -p ${PRISTINE_ROOT} /bin/mount -t ext3 /dev/${VOLGROUP}/${PRISTINE_NAME} ${PRISTINE_ROOT} /usr/bin/wget "${STAGE1PATH}/${STAGE1FILE}" /usr/bin/wget "${STAGE1PATH}/${STAGE1FILE}.md5" /usr/bin/md5sum -c "${STAGE1FILE}.md5" > /dev/null 2>&1 if [ $? -ne 0 ]; then echo "error: Stage 1 checksum failed" exit 1 fi /bin/cat ${STAGE1FILE} | ( cd ${PRISTINE_ROOT} ; tar jxvpf - ) # Unpack stage1 into ${PRISTINE_ROOT} (done above), chroot, bootstrap, # emerge -e system, etc. Perform the usual steps, but keep the installation # trimmed down. Configure fstab for the root and swap partitions. Then: # # rc-update del consolefont boot # rc-update del hdparm boot # rc-update del hotplug default # rc-update del keymaps default # # Also, make sure that ntp-client and ntpd aren't in any runlevels. # -cgs # /bin/rm -f ${PRISTINE_ROOT}/etc/localtime /bin/ln -s ../usr/share/zoneinfo/US/Central ${PRISTINE_ROOT}/etc/localtime echo "${DOMAIN}" > ${PRISTINE_ROOT}/etc/dnsdomainname # Maybe do this in the host loop if you want mail to look like it comes from # the specific host # -cgs /bin/sed "s/rewriteDomain=/rewriteDomain=${DOMAIN}/" \ < ${PRISTINE_ROOT}/etc/ssmtp/ssmtp.conf \ > /tmp/ssmtp.$$ /bin/mv -f /tmp/ssmtp.$$ ${PRISTINE_ROOT}/etc/ssmtp/ssmtp.conf echo "SYNC=\"rsync://rsync.${DOMAIN}/gentoo-portage\"" >> ${PRISTINE_ROOT}/etc/make.conf /bin/mkdir -p ${NEW_ROOT} for host in ${HOSTS}; do /bin/echo -n "Configuring root for '${host}'... " build_lv ${host}-root 4G build_lv_swap ${host}-swap 256M /bin/mount -t ext3 /dev/${VOLGROUP}/${host}-root ${NEW_ROOT} ( \ cd ${PRISTINE_ROOT} ; \ /usr/bin/find . \! -path ./lost+found -depth \ | cpio -pdmv ${NEW_ROOT} \ ) echo "${host}" > ${NEW_ROOT}/etc/hostname /bin/umount ${NEW_ROOT} echo "Done!" done for host in ${SHARE_HOSTS}; do build_lv_share ${host}-share 4G /bin/mount -t ext3 /dev/${VOLGROUP}/${host}-root ${NEW_ROOT} /bin/mkdir -p ${NEW_ROOT}/mnt/share /bin/umount ${NEW_ROOT} /bin/mount -t ext3 /dev/${VOLGROUP}/${host}-share ${NEW_ROOT} # In the guests, I use sda1 for / and sda2 for swap. sda3 is the # next logical choice. # -cgs echo "/dev/sda3 /mnt/share ext3 defaults 0 2" >> ${NEW_ROOT}/etc/fstab /bin/umount ${NEW_ROOT} done exit 0