diff --git a/mkimage.sh.in b/mkimage.sh.in index 3da09b6..ad81a70 100644 --- a/mkimage.sh.in +++ b/mkimage.sh.in @@ -32,26 +32,26 @@ trap 'printf "\nInterrupted! exiting...\n"; cleanup; exit 0' INT TERM HUP mount_pseudofs() { for f in sys dev proc; do - mkdir -p $ROOTFSDIR/$f - mount --bind /$f $ROOTFSDIR/$f + mkdir -p $ROOTFS/$f + mount --bind /$f $ROOTFS/$f done } umount_pseudofs() { - umount -f $ROOTFSDIR/sys >/dev/null 2>&1 - umount -f $ROOTFSDIR/dev >/dev/null 2>&1 - umount -f $ROOTFSDIR/proc >/dev/null 2>&1 + umount -f $ROOTFS/sys >/dev/null 2>&1 + umount -f $ROOTFS/dev >/dev/null 2>&1 + umount -f $ROOTFS/proc >/dev/null 2>&1 } cleanup() { unmount_pseudofs - umount -f ${ROOTFSDIR}/boot 2>/dev/null - umount -f ${ROOTFSDIR} 2>/dev/null + umount -f ${ROOTFS}/boot 2>/dev/null + umount -f ${ROOTFS} 2>/dev/null if [ -e "$LOOPDEV" ]; then partx -d $LOOPDEV 2>/dev/null losetup -d $LOOPDEV 2>/dev/null fi - [ -d "$ROOTFSDIR" ] && rmdir $ROOTFSDIR + [ -d "$ROOTFS" ] && rmdir $ROOTFS } info_msg() { @@ -147,7 +147,7 @@ esac info_msg "Creating disk image ($IMGSIZE) ..." truncate -s "${IMGSIZE}" $FILENAME >/dev/null 2>&1 -ROOTFSDIR=$(mktemp -d) +ROOTFS=$(mktemp -d) info_msg "Creating disk image partitions/filesystems ..." if [ "$BOOT_FSTYPE" = "vfat" ]; then @@ -162,7 +162,7 @@ label: dos _EOF LOOPDEV=$(losetup --show --find --partscan $FILENAME) mkfs.${ROOT_FSTYPE} -O '^64bit,^extra_isize,^has_journal' ${LOOPDEV}p1 >/dev/null 2>&1 - mount ${LOOPDEV}p1 $ROOTFSDIR + mount ${LOOPDEV}p1 $ROOTFS ROOT_UUID=$(blkid -o value -s UUID ${LOOPDEV}p1) ;; *) @@ -177,9 +177,9 @@ _EOF ext[34]) disable_journal="-O ^has_journal";; esac mkfs.${ROOT_FSTYPE} $disable_journal ${LOOPDEV}p2 >/dev/null 2>&1 - mount ${LOOPDEV}p2 $ROOTFSDIR - mkdir -p ${ROOTFSDIR}/boot - mount ${LOOPDEV}p1 ${ROOTFSDIR}/boot + mount ${LOOPDEV}p2 $ROOTFS + mkdir -p ${ROOTFS}/boot + mount ${LOOPDEV}p1 ${ROOTFS}/boot BOOT_UUID=$(blkid -o value -s UUID ${LOOPDEV}p1) ROOT_UUID=$(blkid -o value -s UUID ${LOOPDEV}p2) ;; @@ -188,85 +188,85 @@ esac info_msg "Unpacking rootfs tarball ..." if [ "$PLATFORM" = "beaglebone" ]; then fstab_args=",noauto" - tar xfp $ROOTFS_TARBALL -C $ROOTFSDIR ./boot/MLO - tar xfp $ROOTFS_TARBALL -C $ROOTFSDIR ./boot/u-boot.img - touch $ROOTFSDIR/boot/uEnv.txt - umount $ROOTFSDIR/boot + tar xfp $ROOTFS_TARBALL -C $ROOTFS ./boot/MLO + tar xfp $ROOTFS_TARBALL -C $ROOTFS ./boot/u-boot.img + touch $ROOTFS/boot/uEnv.txt + umount $ROOTFS/boot fi -tar xfp $ROOTFS_TARBALL --xattrs --xattrs-include='*' -C $ROOTFSDIR +tar xfp $ROOTFS_TARBALL --xattrs --xattrs-include='*' -C $ROOTFS fspassno="1" if [ "$ROOT_FSTYPE" = "f2fs" ]; then fspassno="0" fi -echo "UUID=$ROOT_UUID / $ROOT_FSTYPE defaults 0 ${fspassno}" >> ${ROOTFSDIR}/etc/fstab +echo "UUID=$ROOT_UUID / $ROOT_FSTYPE defaults 0 ${fspassno}" >> ${ROOTFS}/etc/fstab if [ -n "$BOOT_UUID" ]; then - echo "UUID=$BOOT_UUID /boot $BOOT_FSTYPE defaults${fstab_args} 0 2" >> ${ROOTFSDIR}/etc/fstab + echo "UUID=$BOOT_UUID /boot $BOOT_FSTYPE defaults${fstab_args} 0 2" >> ${ROOTFS}/etc/fstab fi case "$PLATFORM" in bananapi*|cubieboard2*|cubietruck*) - dd if=${ROOTFSDIR}/boot/u-boot-sunxi-with-spl.bin of=${LOOPDEV} bs=1024 seek=8 >/dev/null 2>&1 + dd if=${ROOTFS}/boot/u-boot-sunxi-with-spl.bin of=${LOOPDEV} bs=1024 seek=8 >/dev/null 2>&1 ;; odroid-c2*) - dd if=${ROOTFSDIR}/boot/bl1.bin.hardkernel of=${LOOPDEV} bs=1 count=442 >/dev/null 2>&1 - dd if=${ROOTFSDIR}/boot/bl1.bin.hardkernel of=${LOOPDEV} bs=512 skip=1 seek=1 >/dev/null 2>&1 - dd if=${ROOTFSDIR}/boot/u-boot.bin of=${LOOPDEV} bs=512 seek=97 >/dev/null 2>&1 + dd if=${ROOTFS}/boot/bl1.bin.hardkernel of=${LOOPDEV} bs=1 count=442 >/dev/null 2>&1 + dd if=${ROOTFS}/boot/bl1.bin.hardkernel of=${LOOPDEV} bs=512 skip=1 seek=1 >/dev/null 2>&1 + dd if=${ROOTFS}/boot/u-boot.bin of=${LOOPDEV} bs=512 seek=97 >/dev/null 2>&1 ;; odroid-u2*) - dd if=${ROOTFSDIR}/boot/E4412_S.bl1.HardKernel.bin of=${LOOPDEV} seek=1 >/dev/null 2>&1 - dd if=${ROOTFSDIR}/boot/bl2.signed.bin of=${LOOPDEV} seek=31 >/dev/null 2>&1 - dd if=${ROOTFSDIR}/boot/u-boot.bin of=${LOOPDEV} seek=63 >/dev/null 2>&1 - dd if=${ROOTFSDIR}/boot/E4412_S.tzsw.signed.bin of=${LOOPDEV} seek=2111 >/dev/null 2>&1 + dd if=${ROOTFS}/boot/E4412_S.bl1.HardKernel.bin of=${LOOPDEV} seek=1 >/dev/null 2>&1 + dd if=${ROOTFS}/boot/bl2.signed.bin of=${LOOPDEV} seek=31 >/dev/null 2>&1 + dd if=${ROOTFS}/boot/u-boot.bin of=${LOOPDEV} seek=63 >/dev/null 2>&1 + dd if=${ROOTFS}/boot/E4412_S.tzsw.signed.bin of=${LOOPDEV} seek=2111 >/dev/null 2>&1 ;; usbarmory*) - dd if=${ROOTFSDIR}/boot/u-boot.imx of=${LOOPDEV} bs=512 seek=2 conv=fsync >/dev/null 2>&1 + dd if=${ROOTFS}/boot/u-boot.imx of=${LOOPDEV} bs=512 seek=2 conv=fsync >/dev/null 2>&1 ;; ci20*) - dd if=${ROOTFSDIR}/boot/u-boot-spl.bin of=${LOOPDEV} obs=512 seek=1 >/dev/null 2>&1 - dd if=${ROOTFSDIR}/boot/u-boot.img of=${LOOPDEV} obs=1K seek=14 >/dev/null 2>&1 + dd if=${ROOTFS}/boot/u-boot-spl.bin of=${LOOPDEV} obs=512 seek=1 >/dev/null 2>&1 + dd if=${ROOTFS}/boot/u-boot.img of=${LOOPDEV} obs=1K seek=14 >/dev/null 2>&1 ;; GCP*) # Setup GRUB mount_pseudofs - chroot ${ROOTFSDIR} grub-install ${LOOPDEV} - sed -i "s:page_poison=1:page_poison=1 console=ttyS0,38400n8d:" ${ROOTFSDIR}/etc/default/grub - chroot ${ROOTFSDIR} update-grub + chroot ${ROOTFS} grub-install ${LOOPDEV} + sed -i "s:page_poison=1:page_poison=1 console=ttyS0,38400n8d:" ${ROOTFS}/etc/default/grub + chroot ${ROOTFS} update-grub umount_pseudofs # Setup the GCP Guest services for _service in dhcpcd sshd agetty-console nanoklogd socklog-unix GCP-Guest-Initialization GCP-accounts GCP-clock-skew GCP-ip-forwarding ; do - chroot ${ROOTFSDIR} ln -sv /etc/sv/$_service /etc/runit/runsvdir/default/$_service + chroot ${ROOTFS} ln -sv /etc/sv/$_service /etc/runit/runsvdir/default/$_service done # Turn off the agetty's since we can't use them anyway - rm -v ${ROOTFSDIR}/etc/runit/runsvdir/default/agetty-tty* + rm -v ${ROOTFS}/etc/runit/runsvdir/default/agetty-tty* # Disable root login over ssh and lock account - sed -i "s:PermitRootLogin yes:PermitRootLogin no:" ${ROOTFSDIR}/etc/ssh/sshd_config - chroot ${ROOTFSDIR} passwd -l root + sed -i "s:PermitRootLogin yes:PermitRootLogin no:" ${ROOTFS}/etc/ssh/sshd_config + chroot ${ROOTFS} passwd -l root # Set the Timezone - chroot ${ROOTFSDIR} ln -svf /usr/share/zoneinfo/UTC /etc/localtime + chroot ${ROOTFS} ln -svf /usr/share/zoneinfo/UTC /etc/localtime # Generate glibc-locales if necessary (this is a noop on musl) if [ "$PLATFORM" = GCP ] ; then - chroot ${ROOTFSDIR} xbps-reconfigure -f glibc-locales + chroot ${ROOTFS} xbps-reconfigure -f glibc-locales fi # Remove SSH host keys (these will get rebuilt on first boot) - rm -v ${ROOTFSDIR}/etc/ssh/*key* - rm -v ${ROOTFSDIR}/etc/ssh/moduli + rm -v ${ROOTFS}/etc/ssh/*key* + rm -v ${ROOTFS}/etc/ssh/moduli # Force hte hostname since this isn't read from DHCP - echo "void-GCE" > ${ROOTFSDIR}/etc/hostname + echo "void-GCE" > ${ROOTFS}/etc/hostname ;; esac -mountpoint -q ${ROOTFSDIR}/boot && umount ${ROOTFSDIR}/boot -umount $ROOTFSDIR +mountpoint -q ${ROOTFS}/boot && umount ${ROOTFS}/boot +umount $ROOTFS losetup -d $LOOPDEV -rmdir $ROOTFSDIR +rmdir $ROOTFS chmod 644 $FILENAME case "$PLATFORM" in diff --git a/mkrootfs.sh.in b/mkrootfs.sh.in index 27feb85..8f72781 100644 --- a/mkrootfs.sh.in +++ b/mkrootfs.sh.in @@ -38,7 +38,7 @@ info_msg() { die() { echo "FATAL: $@" umount_pseudofs - [ -d "$rootfs" ] && rm -rf $rootfs + [ -d "$ROOTFS" ] && rm -rf $ROOTFS exit 1 } @@ -57,24 +57,24 @@ Options -c Set XBPS cache directory (defaults to \$PWD/xbps-cachedir-) -C Full path to the XBPS configuration file -h Show this help - -p Additional packages to install into the rootfs (separated by blanks) + -p Additional packages to install into the ROOTFS (separated by blanks) -r Set XBPS repository (may be set multiple times) - -k Call "cmd " after building the rootfs + -k Call "cmd " after building the ROOTFS -V Show version _EOF } mount_pseudofs() { for f in dev proc sys; do - [ ! -d $rootfs/$f ] && mkdir -p $rootfs/$f - mount -r --bind /$f $rootfs/$f + [ ! -d $ROOTFS/$f ] && mkdir -p $ROOTFS/$f + mount -r --bind /$f $ROOTFS/$f done } umount_pseudofs() { - if [ -d "${rootfs}" ]; then + if [ -d "${ROOTFS}" ]; then for f in dev proc sys; do - umount -f $rootfs/$f >/dev/null 2>&1 + umount -f $ROOTFS/$f >/dev/null 2>&1 done fi } @@ -113,7 +113,7 @@ register_binfmt() { die "Unknown target architecture!" ;; esac - cp -f $(which $QEMU_BIN) $rootfs/usr/bin || die "failed to copy $QEMU_BIN to the rootfs" + cp -f $(which $QEMU_BIN) $ROOTFS/usr/bin || die "failed to copy $QEMU_BIN to the ROOTFS" } # @@ -203,14 +203,14 @@ fi # # Check if package base-system is available. # -rootfs=$(mktemp -d) || die "failed to create tempdir, exiting..." -mkdir -p $rootfs/var/db/xbps/keys -cp keys/*.plist $rootfs/var/db/xbps/keys +ROOTFS=$(mktemp -d) || die "failed to create tempdir, exiting..." +mkdir -p $ROOTFS/var/db/xbps/keys +cp keys/*.plist $ROOTFS/var/db/xbps/keys -run_cmd_target "xbps-install -S $XBPS_CONFFILE $XBPS_CACHEDIR $XBPS_REPOSITORY -r $rootfs" -run_cmd_target "xbps-query -R -r $rootfs $XBPS_CONFFILE $XBPS_CACHEDIR $XBPS_REPOSITORY -ppkgver $PKGBASE" +run_cmd_target "xbps-install -S $XBPS_CONFFILE $XBPS_CACHEDIR $XBPS_REPOSITORY -r $ROOTFS" +run_cmd_target "xbps-query -R -r $ROOTFS $XBPS_CONFFILE $XBPS_CACHEDIR $XBPS_REPOSITORY -ppkgver $PKGBASE" -chmod 755 $rootfs +chmod 755 $ROOTFS case "$PLATFORM" in i686*|x86_64*) PKGS="${PKGBASE}" ;; @@ -220,14 +220,14 @@ esac mount_pseudofs # -# Install base-system to the rootfs directory. +# Install base-system to the ROOTFS directory. # -run_cmd_target "xbps-install -S $XBPS_CONFFILE $XBPS_CACHEDIR $XBPS_REPOSITORY -r $rootfs -y ${PKGS}" +run_cmd_target "xbps-install -S $XBPS_CONFFILE $XBPS_CACHEDIR $XBPS_REPOSITORY -r $ROOTFS -y ${PKGS}" -# Enable en_US.UTF-8 locale and generate it into the target rootfs. -if [ -e $rootfs/etc/default/libc-locales ]; then +# Enable en_US.UTF-8 locale and generate it into the target ROOTFS. +if [ -e $ROOTFS/etc/default/libc-locales ]; then LOCALE=en_US.UTF-8 - sed -e "s/\#\(${LOCALE}.*\)/\1/g" -i $rootfs/etc/default/libc-locales + sed -e "s/\#\(${LOCALE}.*\)/\1/g" -i $ROOTFS/etc/default/libc-locales fi # @@ -238,46 +238,46 @@ if [ -n "${_ARCH}" ]; then info_msg "Reconfiguring packages for ${_ARCH} ..." case "$PLATFORM" in i686*|x86_64*|GCP*) - run_cmd "XBPS_ARCH=${PLATFORM} xbps-reconfigure -r $rootfs base-files" + run_cmd "XBPS_ARCH=${PLATFORM} xbps-reconfigure -r $ROOTFS base-files" ;; *) register_binfmt - run_cmd "xbps-reconfigure -r $rootfs base-files" - run_cmd "chroot $rootfs env -i xbps-reconfigure -f base-files" - rmdir $rootfs/usr/lib32 2>/dev/null - rm -f $rootfs/lib32 $rootfs/lib64 $rootfs/usr/lib64 + run_cmd "xbps-reconfigure -r $ROOTFS base-files" + run_cmd "chroot $ROOTFS env -i xbps-reconfigure -f base-files" + rmdir $ROOTFS/usr/lib32 2>/dev/null + rm -f $ROOTFS/lib32 $ROOTFS/lib64 $ROOTFS/usr/lib64 ;; esac - run_cmd "chroot $rootfs xbps-reconfigure -a" + run_cmd "chroot $ROOTFS xbps-reconfigure -a" fi # # Setup default root password. # -run_cmd "chroot $rootfs sh -c 'echo "root:voidlinux" | chpasswd -c SHA512'" +run_cmd "chroot $ROOTFS sh -c 'echo "root:voidlinux" | chpasswd -c SHA512'" if [ -n "$POST_HOOK" ]; then - run_cmd "$POST_HOOK $rootfs" + run_cmd "$POST_HOOK $ROOTFS" fi umount_pseudofs # -# Cleanup rootfs. +# Cleanup ROOTFS. # -rm -f $rootfs/etc/.pwd.lock 2>/dev/null -rm -rf $rootfs/var/cache/* 2>/dev/null +rm -f $ROOTFS/etc/.pwd.lock 2>/dev/null +rm -rf $ROOTFS/var/cache/* 2>/dev/null # # Generate final tarball. # arch=$ARCH if [ -n "${_ARCH}" ]; then - rm -f $rootfs/usr/bin/$QEMU_BIN + rm -f $ROOTFS/usr/bin/$QEMU_BIN arch=${_ARCH} fi -tarball=void-${PLATFORM}-rootfs-$(date '+%Y%m%d').tar.xz -run_cmd "tar -cp --posix --xattrs -C $rootfs . | xz -T0 -9 > $tarball " +tarball=void-${PLATFORM}-ROOTFS-$(date '+%Y%m%d').tar.xz +run_cmd "tar -cp --posix --xattrs -C $ROOTFS . | xz -T0 -9 > $tarball " -rm -rf $rootfs +rm -rf $ROOTFS info_msg "Successfully created $tarball ($PLATFORM)"