diff --git a/create-vmachine.sh b/create-vmachine.sh index 2c10adb..e43554e 100755 --- a/create-vmachine.sh +++ b/create-vmachine.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Creates a new virtual machine from the given stage3 tarball +# Creates a new virtual machine from the given stage4 tarball DOMNAME="$1" STAGE_TBZ="$2" @@ -7,7 +7,7 @@ VMNAME=$(echo "${DOMNAME}" | tr '[:upper:]' '[:lower:]') VM_FQDN="${VMNAME}.$(hostname -d)" if [[ -z $STAGE_TBZ || -z $VMNAME ]]; then - echo "Usage: $(basename $0) " >&2 + echo "Usage: $(basename $0) " >&2 exit 2 fi @@ -68,40 +68,6 @@ mount -t tmpfs tmpfs "${MOUNTPOINT}"/run echo "Extracting stage tarball..." tar -xjpf "${STAGE_TBZ}" -C "${MOUNTPOINT}" -cp -L /etc/resolv.conf "${MOUNTPOINT}/etc/resolv.conf" - -echo "Installing critical packages..." -# Installing packages must be done in a chroot instead of using the $ROOT -# Portage environment variable because several ebuilds use enewuser/enewgroup -# to create system users, which creates the user on the host system, not the -# target system. See Gentoo bug #53269 for details on the problem. - -mkdir "${MOUNTPOINT}"/usr/portage -mount -obind "${PORTDIR}" "${MOUNTPOINT}"/usr/portage -mount -obind "${DISTDIR}" "${MOUNTPOINT}"/usr/portage/distfiles -mount -obind "${PKGDIR}" "${MOUNTPOINT}"/usr/portage/packages -mount -t tmpfs tmpfs "${MOUNTPOINT}"/tmp -mount -t proc proc "${MOUNTPOINT}"/proc -mount -t sysfs sysfs "${MOUNTPOINT}"/sys - -cat < "${MOUNTPOINT}"/build-base.sh -#!/bin/bash - -set -e - -export EMERGE_DEFAULT_OPTS="--binpkg-respect-use=y" -export FEATURES="-news buildpkg" - -env-update -USE=-thin emerge -jkv xfsprogs nfs-utils lvm2 iproute2 acpid -rc-update add lvm boot -rc-update add acpid default -rc-update add nfsmount default -EOF -chmod u+x "${MOUNTPOINT}"/build-base.sh -chroot "${MOUNTPOINT}" /build-base.sh -rm "${MOUNTPOINT}"/build-base.sh - echo "Setting hostname..." sed -i "s/localhost/${VMNAME}/" "${MOUNTPOINT}"/etc/conf.d/hostname @@ -109,7 +75,7 @@ echo "Configuring network..." echo 'config_eth0="dhcp"' > "${MOUNTPOINT}"/etc/conf.d/net ln -s net.lo "${MOUNTPOINT}"/etc/init.d/net.eth0 ln -s /etc/init.d/net.eth0 "${MOUNTPOINT}"/etc/runlevels/default/ -ln -s /etc/init.d/sshd "${MOUNTPOINT}"/etc/runlevels/default/ +chroot "${MOUNTPOINT}" /etc/init.d/sshd gen_keys echo "Configuring fstab..." cat << EOF > "${MOUNTPOINT}"/etc/fstab @@ -134,9 +100,7 @@ echo "Enabling serial console..." sed -i 's/#s0/s0/' "${MOUNTPOINT}"/etc/inittab echo "Cleaning up..." -umount "${MOUNTPOINT}"/usr/portage/{packages,distfiles,} -rmdir "${MOUNTPOINT}"/usr/portage -umount "${MOUNTPOINT}"/{tmp,proc,sys,run,usr,var,home,} +umount "${MOUNTPOINT}"/{run,usr,var,home,} vgchange -an ${VMNAME} echo "Creating libvirt domain..."