#!/bin/bash set -e set -u dpkg -l ufsutils genisoimage debootstrap 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:-rpool/deb}" ROOT="/$BOOTSTRAPFS" BOOTARCH="${ROOT}/boot_archive" # Disable boot-archive trigger, need bootadm >= 2.10+1: export DEB_BOOTADM_DISABLE_UPDATE_ARCHIVE=1 # These packages are installed via APT, after debootstraping: EXTRA_PACKAGES=" bash-completion bzip2 debootstrap dnsutils drvtools dtrace file host illumos-nfs-common installgrub kmdb less lynx mc mdb-kvm mdb-proc openssh-client openssh-server pciutils ping python-apt python-newt screen snoop sysstat traceroute truss vim wget xz-utils " # 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" } mount_in_root() { mount -F lofs /devices $ROOT/devices mount -F lofs /proc $ROOT/proc mount -F lofs /dev $ROOT/dev } umount_in_root() { umount $ROOT/dev umount $ROOT/proc umount $ROOT/devices } if [ -z "${ROOT}" ] || [ "${ROOT}" = / ]; then echo "WTF? Bad root: \`${ROOT}'" >&2 exit 1 fi rm -rf "${ROOT}"/* if ! zfs list "${BOOTSTRAPFS}"; then zfs create "${BOOTSTRAPFS}" fi if zfs list "${BOOTSTRAPFS}@init"; then zfs rollback "${BOOTSTRAPFS}@init" else echo "Preparing base system (debootstrap)..." debootstrap \ --exclude=logrotate,locales,rsyslog,cron,gawk,aptitude,aptitude-common,libboost-iostreams1.48.0,libboost-iostreams1.49.0,libcwidget3,libboost-iostreams1.54.0 \ --include=illumos-grub-eltorito,illumos-kernel \ "${DIST}" \ "${ROOT}" \ "${REPO}" mount_in_root trap 'umount_in_root' SIGINT SIGTERM set -x chroot $ROOT apt-get update chroot $ROOT apt-get -y --no-install-recommends install $EXTRA_PACKAGES chroot $ROOT apt-get clean set +x trap - SIGINT SIGTERM umount_in_root zfs snapshot ${BOOTSTRAPFS}@init fi # http://osdyson.org/issues/120 # Dyson always boots with only one CPU if ! [ -e "${ROOT}/etc/mach" ]; then echo -e 'pcplusmp\napix\nxpv_psm\n' > "${ROOT}/etc/mach" fi dpkg -l --root "${ROOT}" > pkg.list 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]* # Enable root login by password, openssh >= 6.6: sed -i \ -e '/^PermitRootLogin/ s,without-password,yes,' \ "${ROOT}/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" # Disable SSH server by default sed -i 's,enabled="true",enabled="false",' "${ROOT}/lib/svc/manifest/network/ssh.xml" 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 \ libbrand \ libdiskmgt \ libexacct \ libfmevent \ libidmap \ libipmi \ liblzma \ libpool \ libproject \ libsmbios \ libsqlite \ libsunavl \ libtecla \ libtopo \ libxml2 \ 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 (cd "${BOOTARCH}" && find * -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