From 1e8b9fab1cb43e01fdd5f40c1d46f4384c996d87 Mon Sep 17 00:00:00 2001 From: Kim Hagen Date: Wed, 28 Jul 2021 06:24:19 -0500 Subject: create vyos hdd image --- functions/configuration.sh | 2 +- scripts/build/binary_hdd | 204 ++++++++++++++++++++------------------------ scripts/build/chroot_devpts | 100 ++++++++++++++++------ 3 files changed, 166 insertions(+), 140 deletions(-) diff --git a/functions/configuration.sh b/functions/configuration.sh index c7d2dfc0f..6f52bdad4 100755 --- a/functions/configuration.sh +++ b/functions/configuration.sh @@ -782,7 +782,7 @@ Validate_config_dependencies () fi if In_list "grub-pc" ${LB_BOOTLOADERS} || In_list "grub-efi" ${LB_BOOTLOADERS} || In_list "grub-legacy" ${LB_BOOTLOADERS}; then - if In_list "${LB_IMAGE_TYPE}" hdd netboot; then + if In_list "${LB_IMAGE_TYPE}" netboot; then Echo_error "You have selected an invalid combination of bootloaders and live image type; the grub-* bootloaders are not compatible with hdd and netboot types." exit 1 fi diff --git a/scripts/build/binary_hdd b/scripts/build/binary_hdd index ac5247b19..83e068c23 100755 --- a/scripts/build/binary_hdd +++ b/scripts/build/binary_hdd @@ -48,32 +48,10 @@ case "${LB_BINARY_FILESYSTEM}" in esac Check_package chroot /usr/share/doc/mtools mtools -Check_package chroot /sbin/parted parted +Check_package chroot /usr/sbin/sgdisk gdisk Check_package host /sbin/fdisk fdisk Check_package host /sbin/losetup mount -case "${LB_BOOTLOADER_BIOS}" in - grub-legacy) - Check_package chroot /usr/sbin/grub grub - ;; - - syslinux) - case ${LB_BINARY_FILESYSTEM} in - fat*|ntfs) - _BOOTLOADER=syslinux - ;; - ext[234]|btrfs) - _BOOTLOADER=extlinux - ;; - *) - Echo_error "syslinux/extlinux doesn't support ${LB_BINARY_FILESYSTEM}" - exit 1 - ;; - esac - Check_package chroot /usr/bin/${_BOOTLOADER} ${_BOOTLOADER} - ;; -esac - # Restoring cache Restore_package_cache binary @@ -149,8 +127,6 @@ fi echo "!!! The following error/warning messages can be ignored !!!" Losetup $FREELO chroot/binary.img 0 -PARTITION_TABLE_TYPE="msdos" - case "${LB_BINARY_FILESYSTEM}" in ext2|ext3|ext4) PARTITION_TYPE="ext2" @@ -172,48 +148,50 @@ esac case "${LB_BUILD_WITH_CHROOT}" in true) - Chroot chroot "parted -s ${FREELO} mklabel ${PARTITION_TABLE_TYPE}" || true - if [ "x${LB_HDD_PARTITION_START}" = "x" ]; - then - Chroot chroot "parted -a optimal -s ${FREELO} mkpart primary\ - ${PARTITION_TYPE} 0% 100%" || true - else - Echo_message "using partition start at ${LB_HDD_PARTITION_START}" - Chroot chroot "parted -s ${FREELO} mkpart primary ${PARTITION_TYPE}\ - ${LB_HDD_PARTITION_START} 100%" || true - fi - Chroot chroot "parted -s ${FREELO} set 1 boot on" || true - Chroot chroot "parted -s ${FREELO} set 1 lba off" || true - - if [ "${LB_BOOTLOADER_BIOS}" = "syslinux" ]; then - dd if=chroot/usr/lib/$(echo ${_BOOTLOADER} | tr [a-z] [A-Z])/mbr.bin of=${FREELO} bs=440 count=1 - fi + Chroot chroot "sgdisk --zap-all ${FREELO}" || true + if [ "${LB_BOOTLOADER_EFI}" = "grub-efi" ]; + then + Chroot chroot "sgdisk -a1 -n1:34:2047 -t1:EF02 \ + -n2:2048:+256M -t2:EF00 \ + -n3:0:0:+100% -t3:8300 ${FREELO}" || true + else + if [ "x${LB_HDD_PARTITION_START}" = "x" ]; + then + Chroot chroot "sgdisk -a1 -n1:34:2047 -t1:EF02 \ + -n2:0:0:+100% -t2:8300 ${FREELO}" || true + else + Echo_message "using partition start at ${LB_HDD_PARTITION_START}" + Chroot chroot "sgdisk -a1 -n1:34:2047 -t1:EF02 \ + -n2:${LB_HDD_PARTITION_START}:+100% -t2:8300 ${FREELO}" || true + fi + fi ;; false) - parted -s ${FREELO} mklabel ${PARTITION_TABLE_TYPE} || true - if [ "x${LB_HDD_PARTITION_START}" = "x" ]; - then - parted -a optimal -s ${FREELO} mkpart primary ${PARTITION_TYPE}\ - 0% 100% || true - else - Echo_message "using partition start at ${LB_HDD_PARTITION_START}" - parted -s ${FREELO} mkpart primary ${PARTITION_TYPE}\ - ${LB_HDD_PARTITION_START} 100% || true - fi - parted -s "${FREELO}" set 1 boot on || true - parted -s "${FREELO}" set 1 lba off || true - - if [ "${LB_BOOTLOADER_BIOS}" = "syslinux" ]; then - dd if=/usr/lib/$(echo ${_BOOTLOADER} | tr [a-z] [A-Z])/mbr.bin of=${FREELO} bs=440 count=1 - fi + sgdisk --zap-all ${FREELO} || true + if [ "${LB_BOOTLOADER_EFI}" = "grub-efi" ]; + then + sgdisk -a1 -n1:34:2047 -t1:EF02 \ + -n2:2048:+256M -t2:EF00 \ + -n3:0:0:+100% -t3:8300 ${FREELO} || true + else + if [ "x${LB_HDD_PARTITION_START}" = "x" ]; + then + sgdisk -a1 -n1:34:2047 -t1:EF02 \ + -n2:2048:+100% -t2:8300 ${FREELO} || true + else + Echo_message "using partition start at ${LB_HDD_PARTITION_START}" + sgdisk -a1 -n1:34:2047 -t1:EF02 \ + -n2:${LB_HDD_PARTITION_START}:+100% -t2:8300 ${FREELO} || true + fi + fi ;; esac Lodetach ${FREELO} FREELO="$(losetup -f)" -Losetup $FREELO chroot/binary.img 1 +Losetup $FREELO chroot/binary.img 0 case "${LB_BINARY_FILESYSTEM}" in ext2|ext3|ext4) @@ -243,11 +221,21 @@ esac case "${LB_BUILD_WITH_CHROOT}" in true) - Chroot chroot "mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO}" + if [ "${LB_BOOTLOADER_EFI}" = "grub-efi" ]; + then + Chroot chroot "mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO}p3" + else + Chroot chroot "mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO}p2" + fi ;; false) - mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO} + if [ "${LB_BOOTLOADER_EFI}" = "grub-efi" ]; + then + mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO}p3 + else + mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO}p2 + fi ;; esac @@ -264,63 +252,55 @@ esac Echo_message "Copying binary contents into image..." mkdir -p chroot/binary.tmp -mount ${MOUNT_OPTIONS} ${FREELO} chroot/binary.tmp +if [ "${LB_BOOTLOADER_EFI}" = "grub-efi" ]; +then + mount ${MOUNT_OPTIONS} ${FREELO}p3 chroot/binary.tmp +else + mount ${MOUNT_OPTIONS} ${FREELO}p2 chroot/binary.tmp +fi cp -T ${CP_OPTIONS} binary/ chroot/binary.tmp -FIXME() -{ -if [ "${LB_BOOTLOADER_BIOS}" = "grub-legacy" ]; then - -cat > chroot/grub.sh << EOF -#!/bin/sh -cd binary.tmp -grub --batch << EOM -find /live/vmlinuz -EOM -EOF - - rootpartition="$(Chroot chroot 'sh grub.sh' 2>/dev/null | grep -A 1 'find /live/vmlinuz' | grep -v 'find /live/vmlinuz')" - hdddev="$(echo $rootpartition | sed -e 's|,[[:digit:]]||')" - echo "Root partition is $rootpartition, device is: $hdddev" - - echo "WAITING..." && read WAIT - -#cat > chroot/grub.sh << EOF -#!/bin/sh -#grub --batch << EOM -#root $rootpartition -#setup $hdddev -#EOM -#EOF - -#Chroot chroot "sh grub.sh" - - rm -f chroot/grub.sh +if [ "${LB_BOOTLOADER_BIOS}" = "grub-pc" ]; +then + case "${LB_BUILD_WITH_CHROOT}" in + true) + Chroot chroot "grub-install --no-floppy --target=i386-pc --root-directory=/binary.tmp ${FREELO} --force" + ;; + + false) + grub-install --no-floppy --target=i386-pc --root-directory=/binary.tmp ${FREELO} --force + ;; + esac fi -} - -case "${_BOOTLOADER}" in - syslinux) - _SYSLINUX_INSTALLER="syslinux ${FREELO}" - ;; - extlinux) - _SYSLINUX_INSTALLER="extlinux --install /binary.tmp/boot/extlinux" - ;; - *) - _SYSLINUX_INSTALLER="" - ;; -esac -if [ -n "${_SYSLINUX_INSTALLER}" ] +if [ "${LB_BOOTLOADER_EFI}" = "grub-efi" ]; then - case "${LB_BUILD_WITH_CHROOT}" in - true) - Chroot chroot "${_SYSLINUX_INSTALLER}" - ;; - false) - ${_SYSLINUX_INSTALLER} - ;; - esac + MKFSEFI="vfat" + MKFSEFI_OPTIONS="-n EFI -F 32 -s 1" + MOUNTEFI_OPTIONS="" + + case "${LB_BUILD_WITH_CHROOT}" in + true) + Chroot chroot "mkfs.${MKFSEFI} ${MKFSEFI_OPTIONS} ${FREELO}p2" + ;; + false) + mkfs.${MKFSEFI} ${MKFSEFI_OPTIONS} ${FREELO}p2 + ;; + esac + mkdir -p chroot/efi.tmp + mount ${MOUNTEFI_OPTIONS} ${FREELO}p2 chroot/efi.tmp + case "${LB_BUILD_WITH_CHROOT}" in + true) + Chroot chroot "grub-install --no-floppy --recheck --target=x86_64-efi --force-extra-removable --root-directory=/binary.tmp --efi-directory=/efi.tmp --bootloader-id='VyOS' --no-uefi-secure-boot" + ;; + + false) + grub-install --no-floppy --recheck --target=x86_64-efi --force-extra-removable --root-directory=/binary.tmp --efi-directory=/efi.tmp --bootloader-id='VyOS' --no-uefi-secure-boot + ;; + esac + + umount chroot/efi.tmp + rmdir chroot/efi.tmp fi umount chroot/binary.tmp diff --git a/scripts/build/chroot_devpts b/scripts/build/chroot_devpts index 3877fac83..f25a3861a 100755 --- a/scripts/build/chroot_devpts +++ b/scripts/build/chroot_devpts @@ -29,43 +29,89 @@ Require_stagefiles config bootstrap case "${_ACTION}" in install) - Echo_message "Begin mounting /dev/pts..." + if [ "${LB_IMAGE_TYPE}" = "hdd" ]; then + Echo_message "Begin mounting /dev..." - # Checking stage file - Check_stagefile + # Checking stage file + Check_stagefile - # Acquire lock file - Acquire_lockfile + # Acquire lock file + Acquire_lockfile - # Creating mountpoint - mkdir -p chroot/dev/pts + # Mounting /dev/pts + mount --bind /dev chroot/dev || true + mount -t devpts -o gid=5,mode=620,x-gvfs-hide devpts-live chroot/dev/pts || true - # Mounting /dev/pts - mount -t devpts -o gid=5,mode=620,x-gvfs-hide devpts-live chroot/dev/pts || true + # Creating stage file + Create_stagefile + else + Echo_message "Begin mounting /dev/pts..." - # Creating stage file - Create_stagefile - ;; + # Checking stage file + Check_stagefile - remove) - Echo_message "Begin unmounting /dev/pts..." + # Acquire lock file + Acquire_lockfile - # Checking stage file - Ensure_stagefile_exists + # Creating mountpoint + mkdir -p chroot/dev/pts - # Acquire lock file - Acquire_lockfile + # Mounting /dev/pts + mount -t devpts -o gid=5,mode=620,x-gvfs-hide devpts-live chroot/dev/pts || true - # Unmounting /dev/pts - if grep -qs "$(pwd)/chroot/dev/pts" /proc/mounts || Find_files chroot/dev/pts/* - then - umount chroot/dev/pts - else - umount -f chroot/dev/pts > /dev/null 2>&1 || true - fi + # Creating stage file + Create_stagefile + fi + ;; - # Removing stage file - Remove_stagefile + remove) + if [ "${LB_IMAGE_TYPE}" = "hdd" ]; then + Echo_message "Begin unmounting /dev..." + + # Checking stage file + Ensure_stagefile_exists + + # Acquire lock file + Acquire_lockfile + + # Unmounting /dev/pts + if grep -qs "$(pwd)/chroot/dev/pts" /proc/mounts || Find_files chroot/dev/pts/* + then + umount chroot/dev/pts + else + umount -f chroot/dev/pts > /dev/null 2>&1 || true + fi + + # Unmounting /dev + if grep -qs "$(pwd)/chroot/dev" /proc/mounts || Find_files chroot/dev/* + then + umount chroot/dev + else + umount -f chroot/dev > /dev/null 2>&1 || true + fi + + # Removing stage file + Remove_stagefile + else + Echo_message "Begin unmounting /dev/pts..." + + # Checking stage file + Ensure_stagefile_exists + + # Acquire lock file + Acquire_lockfile + + # Unmounting /dev/pts + if grep -qs "$(pwd)/chroot/dev/pts" /proc/mounts || Find_files chroot/dev/pts/* + then + umount chroot/dev/pts + else + umount -f chroot/dev/pts > /dev/null 2>&1 || true + fi + + # Removing stage file + Remove_stagefile + fi ;; *) -- cgit v1.2.3