summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Hagen <kim@sentrium.io>2021-07-23 08:14:26 -0500
committerKim Hagen <kim@sentrium.io>2021-07-23 08:14:26 -0500
commitca2a4e78bedd6ec8d6dffd94009163596c1c5e1c (patch)
treebfd403077e0124ab8af60f7e79bc61e3412436d8
parenta410b8345de730b947d949f387730109f902c6c8 (diff)
downloadvyos-live-build-ca2a4e78bedd6ec8d6dffd94009163596c1c5e1c.tar.gz
vyos-live-build-ca2a4e78bedd6ec8d6dffd94009163596c1c5e1c.zip
create vyos hdd image
-rwxr-xr-xscripts/build/binary_grub-efi4
-rwxr-xr-xscripts/build/binary_grub-pc4
-rwxr-xr-xscripts/build/binary_hdd212
-rwxr-xr-xscripts/build/chroot_devpts101
4 files changed, 178 insertions, 143 deletions
diff --git a/scripts/build/binary_grub-efi b/scripts/build/binary_grub-efi
index 7afa07eb7..db8dfcbe4 100755
--- a/scripts/build/binary_grub-efi
+++ b/scripts/build/binary_grub-efi
@@ -24,6 +24,10 @@ Arguments "${@}"
Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
Set_defaults
+if In_list "${LIVE_IMAGE_TYPE}" hdd netboot; then
+ exit 0
+fi
+
Check_Any_Bootloader_Role "grub-efi"
Echo_message "Begin preparing Grub based EFI support..."
diff --git a/scripts/build/binary_grub-pc b/scripts/build/binary_grub-pc
index 6d111a7d0..2bdadeb39 100755
--- a/scripts/build/binary_grub-pc
+++ b/scripts/build/binary_grub-pc
@@ -24,6 +24,10 @@ Arguments "${@}"
Read_conffiles config/all config/common config/bootstrap config/chroot config/binary config/source
Set_defaults
+if In_list "${LIVE_IMAGE_TYPE}" hdd netboot; then
+ exit 0
+fi
+
Check_Any_Bootloader_Role "grub-pc"
Echo_message "Begin installing grub-pc..."
diff --git a/scripts/build/binary_hdd b/scripts/build/binary_hdd
index a0d45392b..dee92017e 100755
--- a/scripts/build/binary_hdd
+++ b/scripts/build/binary_hdd
@@ -55,36 +55,20 @@ 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
-echo "${LB_BOOTLOADERS}" | \
-while IFS="," read -r BOOTLOADER
-do
+LB_BOOTLOADERS="$(echo "${LB_BOOTLOADERS}" | tr "," " ")"
+for BOOTLOADER in $LB_BOOTLOADERS; do
case "${BOOTLOADER}" in
- grub)
- Check_package chroot /usr/sbin/grub grub
+ grub-pc)
+ GRUB_PC_ENABLED="true"
+ ;;
+ grub-efi)
+ EFI_ENABLED="true"
;;
esac
done
-case ${LB_FIRST_BOOTLOADER} in
- 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_cache cache/packages.binary
@@ -109,7 +93,6 @@ case "${LB_BINARY_FILESYSTEM}" in
;;
esac
-
# Enforce fat32 if we find individual files bigger than 2GB
if [ "${LB_BINARY_FILESYSTEM}" = "fat16" ] && [ -n "$(find binary -size +1999M)" ]
then
@@ -159,8 +142,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"
@@ -182,50 +163,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_FIRST_BOOTLOADER}" = "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 [ -n "${EFI_ENABLED}" ]
+ 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_FIRST_BOOTLOADER}" = "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 [ -n "${EFI_ENABLED}" ]
+ 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="$(${LB_LOSETUP} -f)"
-Losetup $FREELO chroot/binary.img 1
+Losetup $FREELO chroot/binary.img 0
case "${LB_BINARY_FILESYSTEM}" in
ext2|ext3|ext4)
@@ -255,11 +236,21 @@ esac
case "${LB_BUILD_WITH_CHROOT}" in
true)
- Chroot chroot "mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO}"
+ if [ -n "${EFI_ENABLED}" ]
+ 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 [ -n "${EFI_ENABLED}" ]
+ then
+ mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO}p3
+ else
+ mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO}p2
+ fi
;;
esac
@@ -276,62 +267,55 @@ esac
Echo_message "Copying binary contents into image..."
mkdir -p chroot/binary.tmp
-mount ${MOUNT_OPTIONS} ${FREELO} chroot/binary.tmp
+if [ -n "${EFI_ENABLED}" ]
+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_FIRST_BOOTLOADER}" = "grub" ]
+if [ -n "${GRUB_PC_ENABLED}" ]
then
-
-cat > chroot/grub.sh << EOF
-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
-#grub --batch << EOM
-#root $rootpartition
-#setup $hdddev
-#EOM
-#EOF
-
-#Chroot chroot "sh grub.sh"
-
- rm -f chroot/grub.sh
+ 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 [ -n "${EFI_ENABLED}" ]
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 d917bc4d4..713ff28ae 100755
--- a/scripts/build/chroot_devpts
+++ b/scripts/build/chroot_devpts
@@ -29,46 +29,89 @@ Require_stagefile .build/config .build/bootstrap
case "${1}" in
install)
- Echo_message "Begin mounting /dev/pts..."
+ if [ "${LIVE_IMAGE_TYPE}" = "hdd" ]; then
+ Echo_message "Begin mounting /dev..."
- # Checking stage file
- Check_stagefile .build/chroot_devpts
+ # Checking stage file
+ Check_stagefile .build/chroot_devpts
- # Checking lock file
- Check_lockfile .lock
+ # Checking lock file
+ Check_lockfile .lock
- # Creating lock file
- Create_lockfile .lock
+ # Creating lock file
+ Create_lockfile .lock
- # Creating mountpoint
- mkdir -p chroot/dev/pts
+ # Creating mountpoint
+ mount --bind /dev chroot/dev || true
+ mount devpts-live -t devpts -o gid=5,mode=620 chroot/dev/pts || true
- # Mounting /dev/pts
- mount devpts-live -t devpts -o gid=5,mode=620 chroot/dev/pts || true
+ # Creating stage file
+ Create_stagefile .build/chroot_devpts
+ else
+ Echo_message "Begin mounting /dev/pts..."
- # Creating stage file
- Create_stagefile .build/chroot_devpts
- ;;
+ # Checking stage file
+ Check_stagefile .build/chroot_devpts
- remove)
- Echo_message "Begin unmounting /dev/pts..."
+ # Checking lock file
+ Check_lockfile .lock
- # Checking lock file
- Check_lockfile .lock
+ # Creating lock file
+ Create_lockfile .lock
- # Creating lock file
- Create_lockfile .lock
+ # Creating mountpoint
+ mkdir -p chroot/dev/pts
- # 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
+ # Mounting /dev/pts
+ mount devpts-live -t devpts -o gid=5,mode=620 chroot/dev/pts || true
- # Removing stage file
- rm -f .build/chroot_devpts
+ # Creating stage file
+ Create_stagefile .build/chroot_devpts
+ fi
+ ;;
+
+ remove)
+ if [ "${LIVE_IMAGE_TYPE}" = "hdd" ]; then
+ Echo_message "Begin unmounting /dev..."
+
+ # Checking lock file
+ Check_lockfile .lock
+
+ # Creating lock file
+ Create_lockfile .lock
+
+ # Unmounting /dev
+ if grep -qs "$(pwd)/chroot/dev" /proc/mounts || Find_files chroot/dev/*
+ then
+ umount chroot/dev/pts
+ umount chroot/dev
+ else
+ umount -f chroot/dev/pts > /dev/null 2>&1 || true
+ umount -f chroot/dev > /dev/null 2>&1 || true
+ fi
+
+ # Removing stage file
+ rm -f .build/chroot_devpts
+ else
+ Echo_message "Begin unmounting /dev/pts..."
+
+ # Checking lock file
+ Check_lockfile .lock
+
+ # Creating lock file
+ Create_lockfile .lock
+
+ # 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
+ rm -f .build/chroot_devpts
+ fi
;;
*)