| 1 | #!/bin/bash |
|---|
| 2 | # |
|---|
| 3 | # Arch Linux bootstrap script. Released under the terms of the GPL. |
|---|
| 4 | # henning mueller <henning@orgizm.net> |
|---|
| 5 | # |
|---|
| 6 | # TODO |
|---|
| 7 | # * fstab generation gave "ome" instead of "/home" as a mountpoint |
|---|
| 8 | # * on_arch mode (without chroot) deleted due to errors on 2009.06 cd |
|---|
| 9 | # reintegrate? |
|---|
| 10 | # |
|---|
| 11 | |
|---|
| 12 | usage() { |
|---|
| 13 | cat >&2 <<EOF |
|---|
| 14 | usage: $(basename $0) [options] <ftp|cd> <target> [source] |
|---|
| 15 | |
|---|
| 16 | This script is for installing Arch Linux after manual partitioning and |
|---|
| 17 | network configuration. |
|---|
| 18 | |
|---|
| 19 | For the FTP installation, the original throttled Arch mirror is selected by |
|---|
| 20 | default, so run with another mirror as [source], please. The full URL is |
|---|
| 21 | expected in this case. Example: |
|---|
| 22 | ftp://mirrors.kernel.org/archlinux/core/os/i686 |
|---|
| 23 | |
|---|
| 24 | If you want to bootstrap another architecture than the script is currently |
|---|
| 25 | running on, you have to specify a custom source. |
|---|
| 26 | |
|---|
| 27 | Options: |
|---|
| 28 | -i <file> Include packages from <file> in the installation. <file> should |
|---|
| 29 | contain one package name per line. |
|---|
| 30 | -x Xen mode. Activate serial console and deactivate virtual |
|---|
| 31 | terminals. |
|---|
| 32 | |
|---|
| 33 | EOF |
|---|
| 34 | exit 1 |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | wget="wget -q -t0" |
|---|
| 38 | arch=$(uname -m) |
|---|
| 39 | |
|---|
| 40 | while [ $# -gt 1 ]; do |
|---|
| 41 | case $1 in |
|---|
| 42 | -i) |
|---|
| 43 | [ -f /usr/share/quickinst/$2 ] && |
|---|
| 44 | path=/usr/share/quickinst/$2 || |
|---|
| 45 | path=$2 |
|---|
| 46 | |
|---|
| 47 | [ ! -f $path ] && |
|---|
| 48 | echo "Package file '$path' does not exist." && |
|---|
| 49 | exit 1 |
|---|
| 50 | |
|---|
| 51 | addpkgs=$(cat $path | egrep -v ^# | tr "\n" " ") |
|---|
| 52 | shift; shift |
|---|
| 53 | ;; |
|---|
| 54 | -v) wget="wget -t0"; shift;; |
|---|
| 55 | -x) xen=true; shift;; |
|---|
| 56 | -h) usage;; |
|---|
| 57 | *) break |
|---|
| 58 | esac |
|---|
| 59 | done |
|---|
| 60 | |
|---|
| 61 | mode=$1 |
|---|
| 62 | target=$2 |
|---|
| 63 | source=$3 |
|---|
| 64 | |
|---|
| 65 | [ "$mode" == "" ] || [ "$target" == "" ] && usage |
|---|
| 66 | [ "$mode" == "ftp" ] || [ "$mode" == "cd" ] || usage |
|---|
| 67 | |
|---|
| 68 | [ "$UID" != "0" ] && |
|---|
| 69 | echo "run as root, please." >&2 && |
|---|
| 70 | exit 1 |
|---|
| 71 | |
|---|
| 72 | [ $(echo $target | egrep ^/) ] || |
|---|
| 73 | target=$(pwd)/$target |
|---|
| 74 | |
|---|
| 75 | [ -d "$target" ] || |
|---|
| 76 | mkdir -p $target |
|---|
| 77 | |
|---|
| 78 | [ "$source" == "" ] && |
|---|
| 79 | source=ftp://mirrors.kernel.org/archlinux/core/os/$arch || |
|---|
| 80 | arch=$(basename $source) |
|---|
| 81 | |
|---|
| 82 | cache=$target/var/cache/pacman/pkg |
|---|
| 83 | mkdir -p $cache |
|---|
| 84 | |
|---|
| 85 | [ "$mode" == "ftp" ] && { |
|---|
| 86 | install() { |
|---|
| 87 | cd $cache |
|---|
| 88 | echo " · $1" |
|---|
| 89 | |
|---|
| 90 | package=$(ls $1*.pkg.tar.*z 2>/dev/null | tail -1) |
|---|
| 91 | |
|---|
| 92 | [ ! -f "$package" ] && |
|---|
| 93 | $wget $source/$1*.pkg.tar.*z |
|---|
| 94 | |
|---|
| 95 | [ $? -gt 0 ] && |
|---|
| 96 | echo "wget returned error $?." >&2 && |
|---|
| 97 | exit 1 |
|---|
| 98 | |
|---|
| 99 | package=$(ls $1*.pkg.tar.*z | tail -1) |
|---|
| 100 | tar xf $package -C $target || |
|---|
| 101 | exit 1 |
|---|
| 102 | } |
|---|
| 103 | } |
|---|
| 104 | [ "$mode" == "cd" ] && { |
|---|
| 105 | install() { |
|---|
| 106 | exit 1 |
|---|
| 107 | } |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | echo · downloading and installing bash. |
|---|
| 111 | for package in glibc ncurses readline bash; do |
|---|
| 112 | install $package |
|---|
| 113 | done |
|---|
| 114 | |
|---|
| 115 | echo · downloading and installing pacman. |
|---|
| 116 | for package in libfetch libarchive acl attr zlib bzip2 expat; do |
|---|
| 117 | install $package |
|---|
| 118 | done |
|---|
| 119 | for package in openssl xz-utils pacman-?. pacman-mirrorlist; do |
|---|
| 120 | install $package |
|---|
| 121 | done |
|---|
| 122 | |
|---|
| 123 | echo · installing base. |
|---|
| 124 | cd $target |
|---|
| 125 | cp /etc/resolv.conf etc/resolv.conf |
|---|
| 126 | |
|---|
| 127 | mkdir sys proc dev tmp 2> /dev/null |
|---|
| 128 | |
|---|
| 129 | cp etc/pacman.d/mirrorlist etc/pacman.d/mirrorlist.original |
|---|
| 130 | tmp=$(echo $source | sed -e "s:core:\$repo:") |
|---|
| 131 | echo "Server = $tmp" > etc/pacman.d/mirrorlist |
|---|
| 132 | |
|---|
| 133 | mount -o bind /dev dev |
|---|
| 134 | mount -t proc proc proc |
|---|
| 135 | mount -t sysfs sys sys |
|---|
| 136 | |
|---|
| 137 | chroot $target /bin/bash <<EOF |
|---|
| 138 | pacman --noconfirm $config \ |
|---|
| 139 | -Sfy base $addpkgs || exit 1 |
|---|
| 140 | EOF |
|---|
| 141 | |
|---|
| 142 | [ $xen ] && { |
|---|
| 143 | echo · preparing for use in xen. |
|---|
| 144 | |
|---|
| 145 | vc=xvc0 |
|---|
| 146 | |
|---|
| 147 | [ -f /etc/debian_version ] && vc=hvc0 |
|---|
| 148 | |
|---|
| 149 | cat <<EOF > etc/inittab |
|---|
| 150 | rc::sysinit:/etc/rc.sysinit |
|---|
| 151 | rs:S1:wait:/etc/rc.single |
|---|
| 152 | rm:2345:wait:/etc/rc.multi |
|---|
| 153 | rh:06:wait:/etc/rc.shutdown |
|---|
| 154 | su:S:wait:/sbin/sulogin -p |
|---|
| 155 | c:2345:respawn:/sbin/agetty -8 38400 $vc linux |
|---|
| 156 | EOF |
|---|
| 157 | |
|---|
| 158 | echo $vc > etc/securetty |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | grep $target /proc/mounts | while read line; do |
|---|
| 162 | device=$(echo $line | cut -d ' ' -f 1) |
|---|
| 163 | uuid=$(/lib/udev/vol_id --uuid $device) |
|---|
| 164 | |
|---|
| 165 | [ "$(echo $line | sed -e "s:$target::" | cut -d ' ' -f 2)" == "" ] && |
|---|
| 166 | repl='/' || repl='' |
|---|
| 167 | |
|---|
| 168 | [ "$uuid" != "" ] && |
|---|
| 169 | echo $line | sed -e "s:$target:$repl:" -e "s:$device:UUID=$uuid:" \ |
|---|
| 170 | >> etc/fstab |
|---|
| 171 | done |
|---|
| 172 | |
|---|
| 173 | echo · cleaning up. |
|---|
| 174 | umount sys proc dev |
|---|
| 175 | mv etc/resolv.conf.pacorig etc/resolv.conf |
|---|
| 176 | rm -f etc/*.pac* .FILELIST .INSTALL .PKGINFO |
|---|
| 177 | cp usr/lib/grub/* boot/grub |
|---|
| 178 | |
|---|
| 179 | echo -e "\nPackage installation complete.\n" |
|---|
| 180 | |
|---|
| 181 | [ ! $xen ] && cat <<EOF |
|---|
| 182 | Probably you have to install a boot loader. |
|---|
| 183 | Therefor chroot into your system (you have to be root): |
|---|
| 184 | # mount -o bind /dev $target/dev |
|---|
| 185 | # mount -t proc none $target/proc |
|---|
| 186 | # mount -t sysfs none $target/sys |
|---|
| 187 | # chroot $target /bin/bash |
|---|
| 188 | |
|---|
| 189 | # grub |
|---|
| 190 | grub> root (hd0,0) |
|---|
| 191 | grub> setup (hd0) |
|---|
| 192 | |
|---|
| 193 | A default initramfs setup was created during the package installation process. |
|---|
| 194 | If you have special demands, generate a new one after editing |
|---|
| 195 | /etc/mkinitcpio.conf and /etc/mkinitcpio.d/kernel26-fallback.conf: |
|---|
| 196 | mkinitcpio -p kernel26 -k <kernel-version> (example: 2.6.33-ARCH) |
|---|
| 197 | |
|---|
| 198 | Don't forget to set a root password. |
|---|
| 199 | |
|---|
| 200 | For completing the installation, edit /etc/rc.conf and check /etc/fstab before |
|---|
| 201 | unmounting the devices and rebooting. |
|---|
| 202 | |
|---|
| 203 | EOF |
|---|
| 204 | |
|---|
| 205 | [ $xen ] && cat <<EOF |
|---|
| 206 | Don't forget to set a root password: |
|---|
| 207 | # chroot $target /bin/bash |
|---|
| 208 | # passwd |
|---|
| 209 | |
|---|
| 210 | For completing the installation, edit /etc/rc.conf and /etc/fstab before |
|---|
| 211 | creating the xen guest. |
|---|
| 212 | |
|---|
| 213 | Your xen config could look like this: |
|---|
| 214 | kernel = '/boot/vmlinuz26-xen' |
|---|
| 215 | memory = 256 |
|---|
| 216 | name = 'guest' |
|---|
| 217 | disk = [ 'phy:/dev/mapper/lvm-guest,sda1,w' ] |
|---|
| 218 | vif = [ 'bridge=br0' ] |
|---|
| 219 | ramdisk = '/boot/kernel26-xen.img' |
|---|
| 220 | root = '/dev/sda1 ro' |
|---|
| 221 | vcpus = 1 |
|---|
| 222 | extra = '3 console=xvc0' |
|---|
| 223 | restart = 'onreboot' |
|---|
| 224 | |
|---|
| 225 | EOF |
|---|