Skip to content

Instantly share code, notes, and snippets.

@fbettag
Created December 22, 2010 16:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbettag/751680 to your computer and use it in GitHub Desktop.
Save fbettag/751680 to your computer and use it in GitHub Desktop.
arch domU install script
#! /bin/bash
# new arch-domU install
#
# Copyright (c) 2010, Franz Bettag <franz@bett.ag>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by the Bettag Systems
# and its contributors.
#
# THIS SOFTWARE IS PROVIDED BY FRANZ BETTAG ''AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL FRANZ BETTAG BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
DESTHOSTNAME="archy"
NETIF="172.16.1.5 netmask 255.255.255.0"
NETGW="172.16.1.1"
DESTDIR=/mnt/cdrom
alias pacman="pacman --config /etc/pacman.conf"
# Get path to directory containing this script
SCRIPTDIR="`dirname \`readlink -f $0\``"
echo "Changing current directory to $SCRIPTDIR"
cd $SCRIPTDIR
echo
echo "newarch will do an automated Archlinux installation to the directory"
echo " $DESTDIR"
echo
if [ "$(whoami)" != 'root' ]; then
echo "You must run this as 'root'"
exit 1
fi
if [ -z "`echo $DESTDIR | grep '^/'`" ]; then
DESTDIR=`pwd`/$DESTDIR
fi
if [ ! -d $DESTDIR ]; then
mkdir -p $DESTDIR
else
rm -rf $DESTDIR/*
if [ $? -ne 0 ]; then
echo "ERROR: couldn't remove $DESTDIR"
exit 1
fi
fi
mkdir -p $DESTDIR/var/lib/pacman/
cp /etc/resolv.conf $DESTDIR/etc/resolv.conf
PACMAN="pacman --config /etc/pacman.conf --noconfirm"
mkdir -p $DESTDIR/etc/pacman.d
echo
echo "************** Synchronising package dbs **************"
echo
$PACMAN -r $DESTDIR -Sy
echo
echo "************** Installing package set **************"
echo
PKGLIST="linux-api-headers tzdata glibc zlib binutils gcc ncurses readline iana-etc db cracklib pam shadow attr acl gmp libcap coreutils filesystem util-linux-ng bzip2 pcre glib2 module-init-tools udev device-mapper libgpg-error libgcrypt popt cryptsetup dcron diffutils e2fsprogs file findutils gawk gettext grep sed grub gzip net-tools kbd sysvinit initscripts iputils linux-firmware which less licenses logrotate gdbm perl texinfo groff man-db man-pages nano xz openssl expat libarchive libfetch pacman pacman-mirrorlist pciutils sysfsutils libnl libpcap procps psmisc eventlog tcp_wrappers syslog-ng tar vi vim curl wget openssh git tcpdump netcat screen sudo unzip zip base-devel abs"
echo "Installing following packages:"
echo $PKGLIST
$PACMAN -r $DESTDIR -S $PKGLIST
if [ $? -gt 0 ]; then
echo
echo "Package installation from $PKGLIST FAILED."
echo
exit 1
fi
# This installs packer into the domU, nifty tool
wget https://github.com/bruenig/packer/raw/HEAD/packer --no-check-certificate -O $DESTDIR/usr/bin/packer
chmod +x $DESTDIR/usr/bin/packer
PACMAN="chroot $DESTDIR /usr/bin/packer -S --noconfirm"
cd $DESTDIR/dev
rm console ; mknod -m 600 console c 5 1
rm null ; mknod -m 666 null c 1 3
rm zero ; mknod -m 666 zero c 1 5
echo
echo "************** Set root password **************"
echo
chroot $DESTDIR passwd
echo
echo "************** Synchronising package dbs **************"
echo
# change the source to fit yours
cp -r /etc/pacman.d/mirrorlist $DESTDIR/etc/pacman.d/mirrorlist
chroot $DESTDIR pacman -S -y
echo
echo "************** Configuring system **************"
echo
# this removes hardwareclock (dom0 is doing that) and sets everything else accordingly (+ sshd boot)
sed -i -e 's;^HARDWARECLOCK=.*$;HARDWARECLOCK=;g' \
-e 's;^TIMEZONE=.*$;TIMEZONE="Europe/Berlin";g' \
-e 's;^KEYMAP=.*;KEYMAP="de";g' \
-e 's;^MOD_AUTOLOAD="yes";MOD_AUTOLOAD="no";g' \
-e "s;^HOSTNAME=.*;HOSTNAME=\"$DESTHOSTNAME\";g" \
-e "s;^eth0=.*;eth0=\"eth0 $NETIF\";g" \
-e "s;^gateway=.*;gateway=\"default gw $NETGW\";g" \
-e "s;^ROUTES=.*;ROUTES=(gateway);g" \
-e "s;^DAEMONS=(syslog-ng network netfs crond);DAEMONS=(network syslog-ng crond sshd);g" \
$DESTDIR/etc/rc.conf
# set the wanted charset
sed -i -e "s/^#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g" $DESTDIR/etc/locale.gen
chroot $DESTDIR locale-gen
# this removes errors during startup which try to set charset (dom0 is doing that)
sed -i -e 's;^.*/usr/bin/kbd_mode;#/usr/bin/kbd_mode;' \
-e 's;^.*\\033%%G.*$;echo -n;' \
$DESTDIR/etc/rc.sysinit
cat > $DESTDIR/etc/fstab <<EOF
devpts /dev/pts devpts defaults 0 0
shm /dev/shm tmpfs nodev,nosuid 0 0
/dev/sda1 / ext3 noatime 0 1
/dev/sda2 none swap noatime 0 0
#/dev/sda3 /data auto noatime 0 0
EOF
# i don't like those folders.
rm -rf $DESTDIR/srv $DESTDIR/media
echo
echo "************** Extracting base config **************"
echo
# you should create a folder somewhere, mkdir -p {etc,home/youruser} and put files in there
# which you want extracted in the new systems's root.
chroot $DESTDIR /usr/bin/curl http://your.server/baseconfig.tbz2 > $DESTDIR/base.tbz2
chroot $DESTDIR tar -jxvpf base.tbz2
chroot $DESTDIR rm base.tbz2
# Removes the clear-screen from issue.net (i want to see startup in a domU)
echo 'Arch Linux \r (\n) (\l)' > $DESTDIR/etc/issue
echo >> $DESTDIR/etc/issue
echo
echo "+++ All done! +++"
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment