123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- #!/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 <<-EOH
- Usage: $PROGNAME [options] <rootfs-tarball>
- Generates a network-bootable tarball from a Void Linux ROOTFS generated by mkrootfs.
- OPTIONS
- -r <repo> Use this XBPS repository. May be specified multiple times
- -c <cachedir> Use this XBPS cache directory (default: )
- -i <lz4|gzip|bzip2|xz>
- Compression type for the initramfs image (default: xz)
- -o <file> Output file name for the netboot tarball (default: automatic)
- -K linux<version> Install a custom Linux version on ISO image (default: linux metapackage)
- -k <keymap> Default keymap to use (default: us)
- -l <locale> Default locale to use (default: en_US.UTF-8)
- -C "<arg> ..." Add additional kernel command line arguments
- -T <title> Modify the bootloader title (default: Void Linux)
- -S <image> Set a custom splash image for the bootloader (default: data/splash.png)
- -h Show this help and exit
- -V Show version and exit
- EOH
- }
- while getopts "r:c:C:T:K:i:o:k:l:S:Vh" opt; do
- case $opt in
- r) XBPS_REPOSITORY="--repository=$OPTARG $XBPS_REPOSITORY";;
- c) XBPS_CACHEDIR="--cachedir=$OPTARG";;
- i) INITRAMFS_COMPRESSION="$OPTARG";;
- K) KERNELPKG="$OPTARG";;
- o) OUTPUT_FILE="$OPTARG";;
- k) KEYMAP="$OPTARG";;
- l) LOCALE="$OPTARG";;
- C) BOOT_CMDLINE="$OPTARG";;
- T) BOOT_TITLE="$OPTARG";;
- S) SPLASH_IMAGE="$OPTARG";;
- V) version; exit 0;;
- h) usage; exit 0;;
- *) usage >&2; exit 1;;
- 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"
- if [ -z "${XBPS_TARGET_ARCH##*86*}" ] ; then
-
-
- info_msg "Selecting syslinux bootloader"
- bootloader_pkg=syslinux
- else
-
-
-
- info_msg "Selecting u-boot bootloader"
- bootloader_pkg=uboot-mkimage
- fi
- run_cmd_target "xbps-install $XBPS_CONFFILE $XBPS_CACHEDIR $XBPS_REPOSITORY -r $ROOTFS -Sy ${KERNELPKG-linux} dracut binutils dracut-network dialog ${INITRAMFS_COMPRESSION-xz} ${bootloader_pkg}"
- 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"
- if [ ${bootloader_pkg} = "syslinux" ] ; then
-
-
-
-
- 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/lib/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"
- else
-
-
- if [ ! -f "$ROOTFS/boot/uImage" ] ; then
-
-
-
-
- run_cmd_chroot "$ROOTFS" "env -i /usr/bin/mkimage -A arm -O linux -T kernel -C none -a 0x00000000 -e 0x00000000 -n 'Void Kernel' -d /boot/zImage /boot/uImage"
-
-
- run_cmd_chroot "$ROOTFS" "env -i /usr/bin/mkimage -A arm -O linux -T ramdisk -C none -a 0 -e 0 -n 'Void Installer Initrd' -d /boot/initrd /boot/uInitrd"
-
- cp "$ROOTFS/boot/uImage" "$BOOT_DIR"
- cp "$ROOTFS/boot/uInitrd" "$BOOT_DIR"
- cp -r "$ROOTFS/boot/dtbs" "$BOOT_DIR"
- else
-
- cp "$ROOTFS/boot/uImage" "$BOOT_DIR"
- fi
- fi
- OUTPUT_FILE="void-${XBPS_TARGET_ARCH}-NETBOOT-$(date -u +%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"
|