#!/bin/bash set -e set -u TMP="${TMP:-/var/tmp}" DATE=$(date '+%Y-%m-%d-%H%M') DIST="${DIST:-bok}" REPO="${REPO:-http://apt.osdyson.org}" # We will search for usr archive on CD: USR_IMG=usr.img.$(echo $DATE | md5sum | cut -f1 -d ' ') ISOLABEL="${ISOLABEL:-dyson-netinst}" ISONAME="${ISONAME:-${ISOLABEL}-${DATE}}.iso" ROOT="${TMP}/ROOT" BOOTSTRAPFS="${BOOTSTRAPFS:-dyson/deb}" ROOT="/$BOOTSTRAPFS" BOOTARCH="${ROOT}/boot_archive" # Move files from usr to usr1, # Create links from usr to usr1. # E. g.: # usr_symlink_move usr/bin/bash # /usr/bin/bash -> /usr1/bin/bash # usr_symlink_move usr/lib/devfsadm # /usr/lib/devfsadm -> /usr1/lib/devfsadm usr_symlink_move() { f=${1#*/} # NO LEADING SLASH! d=$(dirname "$f") if [ ! -d "usr1/$d" ]; then mkdir -p "usr1/$d" fi mv -v "usr/$f" "usr1/$f" ln -sf "/usr1/$f" "usr/$f" } if [ -z "${ROOT}" ] || [ "${ROOT}" = / ]; then echo "WTF? Bad root: \`${ROOT}'" >&2 exit 1 fi rm -rf "${ROOT}"/* if zfs list "${BOOTSTRAPFS}@init"; then zfs rollback "${BOOTSTRAPFS}@init" else echo "Preparing base system (debootstrap)..." debootstrap \ --exclude=locales,syslogd,gawk,aptitude,aptitude-common,libboost-iostreams1.48.0,libboost-iostreams1.49.0,libcwidget3 \ --include=python-newt,truss,installgrub,illumos-grub-eltorito,illumos-kernel,mc,vim,screen,openssh-client,wget,bzip2,xz-utils,debootstrap,less,file,lynx,bash-completion \ "${DIST}" \ "${ROOT}" \ "${REPO}" zfs snapshot dyson/deb@init fi mkdir "$ROOT/usr/install" cp -a install DysonInstaller $ROOT/usr/install/ cat installer-screenrc > $ROOT/etc/screenrc cat bash_profile > $ROOT/root/.bash_profile cat vimrc > $ROOT/root/.vimrc # debootstrap copied from the host system: rm -f $ROOT/etc/resolv.conf mv $ROOT/var/lib/dpkg $ROOT/usr/dpkg ln -sf /usr/dpkg $ROOT/var/lib/dpkg rm -rf "${ROOT}"/var/cache/* rm -rf "${ROOT}"/etc/cron.* rm -rf "${ROOT}"/var/log/* rm -rf "${ROOT}"/usr/share/doc/* # Remove messages and localized mans: rm -rf "${ROOT}"/usr/share/locale/*/LC_MESSAGES rm -rf "${ROOT}"/usr/share/man/*/man[0-9]* #sed -i '/^PermitRootLogin/ s,no,yes,' /etc/ssh/sshd_config cat < $ROOT/etc/vfstab #device device mount FS fsck mount mount #to mount to fsck point type pass at boot options # /devices/ramdisk:a - / ufs 1 no rw,nologging fd - /dev/fd fd - no - swap - /tmp tmpfs - yes - VFSTAB echo "dyson-${DIST}-live" > "${ROOT}/etc/nodename" # Set root password (just "root"): echo 'root:root' | chpasswd -R "$ROOT" # Script to find and mount usr.lzma: sed "s/##USR_IMG##/$USR_IMG/g" "fs-root" > "${ROOT}/lib/svc/method/fs-root" cat console-login > "${ROOT}/lib/svc/method/console-login" cat net-physical > "${ROOT}/lib/svc/method/net-physical" chmod +x "${ROOT}/lib/svc/method"/* dummy_prog='#!/sbin/sh exit 0 ' echo "$dummy_prog" > "${ROOT}/lib/svc/method/fs-usr" echo "$dummy_prog" > "${ROOT}/lib/svc/method/boot-archive" echo "$dummy_prog" > "${ROOT}/lib/svc/method/boot-archive-update" echo "Importing manifests..." rm -f "${ROOT}/etc/svc/repository.db" # bash or ksh, please: bash "${ROOT}/lib/svc/method/manifest-import" \ -f "${ROOT}/etc/svc/repository.db" \ -d "${ROOT}/lib/svc/manifest" # Thank you! Bye-bye! echo "$dummy_prog" > "${ROOT}/lib/svc/method/manifest-import" mkdir -p "${BOOTARCH}" mkdir -p "${BOOTARCH}/usr" mkdir -p "${BOOTARCH}/cdrom" touch "${BOOTARCH}/reconfigure" pushd "${ROOT}" # We use 32-bit installgrub, but is not required to boot ;-) if [ -e lib32 ]; then mkdir -p usr/lib32 mv lib32/* usr/lib32/ ln -sf usr/lib32 $BOOTARCH/lib32 fi # Move some critical libs: march=`dpkg-architecture -qDEB_HOST_MULTIARCH` mkdir -p lib/$march for lib in \ libdiskmgt \ libexacct \ libfmevent \ libidmap \ libipmi \ liblzma \ libpool \ libproject \ libsmbios \ libsunavl \ libtecla \ libtopo \ libxml2 \ libz \ libzonecfg \ ; do mv -v -f usr/lib/$march/$lib.so.* lib/$march/ || \ mv -v -f usr/lib/$lib.so.* lib/$march/ done # Moving some files from usr to usr1 # and creating symlinks from usr to usr1 usr_symlink_move usr/bin/cat usr_symlink_move usr/bin/dash usr_symlink_move usr/bin/grep usr_symlink_move usr/bin/hostname usr_symlink_move usr/bin/ln usr_symlink_move usr/bin/ls usr_symlink_move usr/bin/rm usr_symlink_move usr/bin/sh usr_symlink_move usr/lib/devfsadm usr_symlink_move usr/lib/fs/hsfs/mount usr_symlink_move usr/lib/fs/ufs/mount usr_symlink_move usr/sbin/devfsadm usr_symlink_move usr/sbin/dladm usr_symlink_move usr/sbin/ipadm usr_symlink_move usr/sbin/lofiadm # usr2 will be packed and stored on CD: mv usr usr2 # This is usr before usr2 is mounted, # fs-root will mount usr2 and replace usr -> usr2 ln -sf usr1 usr ln -sf ../../sbin usr1/sbin # List here files or directories which # should be *moved* to boot archive. # Caution: files from /usr require # special treating: see above tar --remove-files -c -f - \ bin \ boot/solaris \ dev \ devices \ etc \ home \ kernel \ lib \ media \ mnt \ opt \ platform \ proc \ root \ run \ sbin \ srv \ system \ tmp \ usr \ usr1 \ var \ | tar xf - -C "${BOOTARCH}" # Restore the kernel: mkdir -p platform/i86pc/kernel/amd64 cp -p "${BOOTARCH}/platform/i86pc/kernel/amd64/unix" \ platform/i86pc/kernel/amd64/ # Mount point for compressed /usr: mkdir "${BOOTARCH}/usr2" popd # Exit from $ROOT find "${BOOTARCH}" -ls > bootarch.list echo "Making boot archive..." sync; sync size=$(du -s -m "${BOOTARCH}" | cut -f1) ((size+=20)) # +20 MB of free space dd if=/dev/zero of="${ROOT}/boot/boot_archive" bs=1M count="$size" lofidev=$(lofiadm -a "${ROOT}/boot/boot_archive") rlofidev="${lofidev/lofi/rlofi}" yes | newfs -m 0 "${rlofidev}" mkdir -p "${ROOT}/boot/boot_archive.mount" mount "${lofidev}" "${ROOT}/boot/boot_archive.mount" mv "${BOOTARCH}"/* "${ROOT}/boot/boot_archive.mount"/ umount "${ROOT}/boot/boot_archive.mount" lofiadm -d "${lofidev}" rmdir "${BOOTARCH}" rmdir "${ROOT}/boot/boot_archive.mount" gzip -9 -f "${ROOT}/boot/boot_archive" echo "Making usr archive..." # usr will be mounted from usr.lzma: genisoimage \ -o "${ROOT}/${USR_IMG}" \ -N -l -R -U \ -allow-multidot \ -quiet -no-iso-translate -cache-inodes -d -D \ -V "usr" \ "${ROOT}/usr2" rm -rf "${ROOT}/usr2" lofiadm -C lzma "${ROOT}/${USR_IMG}" echo "Configuring GRUB..." cat < "${ROOT}/boot/grub/menu.lst" default=0 timeout=3 foreground=ffffff background=215ECA title Dyson ($DIST) installer and LiveCD, $DATE kernel /platform/i86pc/kernel/amd64/unix module /boot/boot_archive.gz GRUB echo "Making final ${ISONAME}..." genisoimage \ -o "${ISONAME}" \ -b boot/grub/stage2_eltorito \ -c .catalog \ -no-emul-boot \ -boot-load-size 4 \ -boot-info-table \ -N -l -R -U \ -allow-multidot \ -no-iso-translate \ -cache-inodes \ -d -D \ -V "${ISOLABEL}" \ "${ROOT}" ls -lh "${ISONAME}" exit 0