123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- #!/bin/sh
- readonly PROGNAME=$(basename "$0")
- readonly REQTOOLS="xbps-install tar"
- readonly CURDIR="$(pwd)"
- . ./lib.sh
- trap 'bailout' INT TERM
- bailout() {
- [ -d "$BOOT_DIR" ] && rm -rf "$BOOT_DIR"
- die "An unchecked exception has occured!"
- }
- usage() {
- cat <<_EOF
- Usage: $PROGNAME [options] <rootfs>
- Options:
- -r <repo-url> Use this XBPS repository (may be specified multiple times).
- -c <cachedir> Use this XBPS cache directory.
- -i <lz4|gzip|bzip2|xz> Compression type for the initramfs image (xz if unset).
- -o <file> Output file name for the netboot tarball (auto if unset).
- -k <keymap> Console keymap to set (us if unset)
- -l <locale> Locale to set (en_US.UTF-8 if unset)
- -C "cmdline args" Add additional kernel command line arguments.
- -T "title" Modify the bootloader title.
- -S "splash image" Set a custom splash image for the bootloader
- The $PROGNAME script generates a network-bootable tarball of Void Linux
- _EOF
- exit 1
- }
- while getopts "r:c:C:T:i:o:h" opt; do
- case $opt in
- r) XBPS_REPOSITORY="--repository=$OPTARG $XBPS_REPOSITORY";;
- c) XBPS_CACHEDIR="--cachedir=$OPTARG";;
- i) INITRAMFS_COMPRESSION="$OPTARG";;
- o) OUTPUT_FILE="$OPTARG";;
- k) KEYMAP="$OPTARG";;
- l) LOCALE="$OPTARG";;
- C) BOOT_CMDLINE="$OPTARG";;
- T) BOOT_TITLE="$OPTARG";;
- S) SPLASH_IMAGE="OPTARG";;
- h) usage;;
- esac
- done
- shift $((OPTIND - 1))
- BASE_TARBALL="$1"
- XBPS_TARGET_ARCH=${BASE_TARBALL%%-ROOTFS*}
- XBPS_TARGET_ARCH=${XBPS_TARGET_ARCH##void-}
- set_cachedir
- if [ "$(id -u)" -ne 0 ]; then
- die "need root perms to continue, exiting."
- fi
- check_tools
- ROOTFS=$(mktemp -d) || die "failed to create ROOTFS tempdir, exiting..."
- BOOT_DIR=$(mktemp -d) || die "failed to create BOOT_DIR tempdir, exiting..."
- PXELINUX_DIR="$BOOT_DIR/pxelinux.cfg"
- info_msg "Expanding base tarball $BASE_TARBALL into $ROOTFS for $PLATFORM build."
- tar xf "$BASE_TARBALL" -C "$ROOTFS"
- info_msg "Install additional dracut modules"
- mkdir -p "$ROOTFS/usr/lib/dracut/modules.d/05netmenu"
- cp dracut/netmenu/* "$ROOTFS/usr/lib/dracut/modules.d/05netmenu/"
- cp installer.sh "$ROOTFS/usr/lib/dracut/modules.d/05netmenu/"
- mkdir -p "$ROOTFS/usr/lib/dracut/modules.d/01autoinstaller"
- cp dracut/autoinstaller/* "$ROOTFS/usr/lib/dracut/modules.d/01autoinstaller/"
- info_msg "Install kernel and additional required netboot packages"
- run_cmd_target "xbps-install $XBPS_CONFFILE $XBPS_CACHEDIR $XBPS_REPOSITORY -r $ROOTFS -Sy linux dracut syslinux binutils dracut-network dialog ${INITRAMFS_COMPRESSION-xz}"
- run_cmd_chroot "$ROOTFS" "xbps-reconfigure -a"
- KERNELVERSION=$(ls "$ROOTFS/usr/lib/modules/")
- info_msg "Building initrd for kernel version $KERNELVERSION"
- run_cmd_chroot "$ROOTFS" "env -i /usr/bin/dracut \
- -N \
- --${INITRAMFS_COMPRESSION-xz} \
- --add-drivers ahci \
- --force-add 'autoinstaller netmenu' \
- --omit systemd \
- /boot/initrd \
- $KERNELVERSION"
- [ $? -ne 0 ] && die "Failed to generate the initramfs"
- info_msg "Collect netboot components"
- mv -v "$ROOTFS/boot/initrd" "$BOOT_DIR"
- cp -v "$ROOTFS/boot/vmlinuz-$KERNELVERSION" "$BOOT_DIR/vmlinuz"
- chmod 0644 "$BOOT_DIR/initrd"
- for prog in pxelinux.0 ldlinux.c32 libcom32.c32 vesamenu.c32 libutil.c32 chain.c32 ; do
- cp -v "$ROOTFS/usr/share/syslinux/$prog" "$BOOT_DIR"
- done
- mkdir -p "$PXELINUX_DIR"
- cp -f pxelinux.cfg/pxelinux.cfg.in "$PXELINUX_DIR/default"
- cp -f "${SPLASH_IMAGE-data/splash.png}" "$BOOT_DIR"
- info_msg "Configuring pxelinux.0 default boot menu"
- sed -i -e "s|@@SPLASHIMAGE@@|$(basename "${SPLASH_IMAGE-splash.png}")|" \
- -e "s|@@KERNVER@@|${KERNELVERSION}|" \
- -e "s|@@KEYMAP@@|${KEYMAP-us}|" \
- -e "s|@@ARCH@@|$XBPS_TARGET_ARCH|" \
- -e "s|@@LOCALE@@|${LOCALE-en_US.UTF-8}|" \
- -e "s|@@BOOT_TITLE@@|${BOOT_TITLE-Void Linux}|" \
- -e "s|@@BOOT_CMDLINE@@|${BOOT_CMDLINE}|" \
- "$PXELINUX_DIR/default"
- OUTPUT_FILE="void-${XBPS_TARGET_ARCH}-NETBOOT-$(date +%Y%m%d).tar.gz"
- info_msg "Compressing results to $OUTPUT_FILE"
- cd "$BOOT_DIR" || die "Could not enter image dir"
- tar -zcvf "$CURDIR/$OUTPUT_FILE" .
- cd "$CURDIR" || die "Could not return to working directory"
- info_msg "Cleaning up and removing build directories"
- cleanup_chroot
- [ -d "$ROOTFS" ] && rm -rf "$ROOTFS"
- [ -d "$BOOT_DIR" ] && rm -rf "$BOOT_DIR"
|