diff options
author | Kroy <kroy@kroy.io> | 2018-11-05 15:43:19 -0600 |
---|---|---|
committer | Kroy <kroy@kroy.io> | 2018-11-05 15:43:19 -0600 |
commit | a7731785aeb928ace93a176a9c574267a00836e4 (patch) | |
tree | 8ca0e77a6f4c1123d162568e7b9d284684b20317 /scripts | |
parent | 018860f21eb4151df5e0b719ad9b66331786ac4e (diff) | |
download | vyatta-cfg-system-a7731785aeb928ace93a176a9c574267a00836e4.tar.gz vyatta-cfg-system-a7731785aeb928ace93a176a9c574267a00836e4.zip |
T955: Integrating EFI into the installer
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/install/install-functions | 11 | ||||
-rwxr-xr-x | scripts/install/install-get-partition | 101 | ||||
-rwxr-xr-x | scripts/install/install-image | 8 | ||||
-rwxr-xr-x | scripts/install/install-postinst-new | 37 | ||||
-rwxr-xr-x | scripts/vyatta-grub-setup | 6 |
5 files changed, 108 insertions, 55 deletions
diff --git a/scripts/install/install-functions b/scripts/install/install-functions index d241e040..a038686c 100755 --- a/scripts/install/install-functions +++ b/scripts/install/install-functions @@ -174,10 +174,13 @@ select_drive () { local drv='' # list the drives in /proc/partitions. Remove partitions and empty lines. # the first grep pattern looks for devices named c0d0, hda, and sda. - drives=$(cat /proc/partitions | \ - awk '{ if ($4!="name") { print $4 } }' | \ - egrep "c[0-9]d[0-9]$|[hsv]d[a-z]$" | \ - egrep -v "^$") + #drives=$(cat /proc/partitions | \ + # awk '{ if ($4!="name") { print $4 } }' | \ + # egrep "c[0-9]d[0-9]$|[hsv]d[a-z]$" | \ + # egrep -v "^$") + + #should be better about finding installable drives + drives=$(lsblk -dn -o name -I8) # take the first drive as the default drv=$(echo $drives | /usr/bin/awk '{ print $1 }') diff --git a/scripts/install/install-get-partition b/scripts/install/install-get-partition index d6bb5524..5f4aee09 100755 --- a/scripts/install/install-get-partition +++ b/scripts/install/install-get-partition @@ -34,6 +34,8 @@ PARTITION='' # default file system type ROOT_FSTYPE='ext4' +EFI_PARTITION=0 + warn_of_dire_consequences () { # Give the user a requisite warning that we are about to nuke their drive response='' @@ -668,43 +670,72 @@ create_partitions() { echo "Error: $ldrive is only $size"MB" large. Desired root is $root_part_size" exit 1 fi + if [ -d /sys/firmware/efi ]; then + #Need room for the EFI partition. 512 is standard, but 256 is probably okay here + root_part_size=$((root_part_size - 256)) + + ##Do GPT/EFI Setup + sgdisk --zap-all /dev/$ldrive + # part1 = BIOS BOOT (backwards compatibility) + # part2 = EFI + # part3 = ROOT + sgdisk -a1 -n1:34:2047 -t1:EF02 \ + -n2:2048:+256M -t2:EF00 \ + -n3:0:0:+$root_part_size -t3:8300 /dev/$ldrive + status=$? + if [ "$status" != 0 ]; then + echo -e "Error creating primary partition on $ldrive.\nPlease see $INSTALL_LOG for more details.\nExiting..." + lecho "Error creating primary partition on $ldrive.\nparted /dev/$ldrive mkpart primary 0% $root_part_size\n$output" + exit 1 + fi + # set the partition number on the device. + if [ -n "$( echo $ldrive | grep -E "cciss|ida" )" ]; then + # if this is a cciss + ROOT_PARTITION=$ldrive"p3" + EFI_PARTITION=$ldrive"p2" + else + # else... the rest of the world + ROOT_PARTITION=$ldrive"3" + EFI_PARTITION=$ldrive"2" + fi + else + # Force FAT label creation + lecho "Creating a new disklabel on $ldrive" + parted -s /dev/$ldrive mklabel msdos + + # Make sure you can print disk info using parted + parted --script /dev/$ldrive p >/dev/null 2>&1 + + # If we still can't, something has gone terribly wrong + if [ "$?" != "0" ]; then + echo "Unable to read disk label. Exiting." + exit 1 + fi - # Force FAT label creation - lecho "Creating a new disklabel on $ldrive" - parted -s /dev/$ldrive mklabel msdos - - # Make sure you can print disk info using parted - parted --script /dev/$ldrive p >/dev/null 2>&1 - - # If we still can't, something has gone terribly wrong - if [ "$?" != "0" ]; then - echo "Unable to read disk label. Exiting." - exit 1 - fi - - lecho "Creating root partition on /dev/$ldrive" + lecho "Creating root partition on /dev/$ldrive" - # Make the root partition - # if optimal_io_size is empty use default of 2048s - if [ $(cat /sys/block/$ldrive/queue/optimal_io_size) -gt 0 ]; then - output=$(parted --script --align optimal /dev/$ldrive mkpart primary 0% $root_part_size) - else - output=$(parted --script --align optimal /dev/$ldrive mkpart primary 2048s $root_part_size) - fi - status=$? - if [ "$status" != 0 ]; then - echo -e "Error creating primary partition on $ldrive.\nPlease see $INSTALL_LOG for more details.\nExiting..." - lecho "Error creating primary partition on $ldrive.\nparted /dev/$ldrive mkpart primary 0% $root_part_size\n$output" - exit 1 - fi + # Make the root partition + # if optimal_io_size is empty use default of 2048s + if [ $(cat /sys/block/$ldrive/queue/optimal_io_size) -gt 0 ]; then + output=$(parted --script --align optimal /dev/$ldrive mkpart primary 0% $root_part_size) + else + output=$(parted --script --align optimal /dev/$ldrive mkpart primary 2048s $root_part_size) + fi + status=$? + if [ "$status" != 0 ]; then + echo -e "Error creating primary partition on $ldrive.\nPlease see $INSTALL_LOG for more details.\nExiting..." + lecho "Error creating primary partition on $ldrive.\nparted /dev/$ldrive mkpart primary 0% $root_part_size\n$output" + exit 1 + fi - # set the partition number on the device. - if [ -n "$( echo $ldrive | grep -E "cciss|ida" )" ]; then - # if this is a cciss - ROOT_PARTITION=$ldrive"p1" - else - # else... the rest of the world - ROOT_PARTITION=$ldrive"1" + # set the partition number on the device. + if [ -n "$( echo $ldrive | grep -E "cciss|ida" )" ]; then + # if this is a cciss + ROOT_PARTITION=$ldrive"p1" + else + # else... the rest of the world + ROOT_PARTITION=$ldrive"1" + fi fi # udev takes time to re-add the device file, so wait for it while [ ! -b "/dev/$ROOT_PARTITION" ]; do @@ -958,7 +989,7 @@ if [ -z "$ROOT_PARTITION" ]; then exit 1 fi -echo "$ROOT_PARTITION_TYPE $ROOT_PARTITION $INSTALL_DRIVE" >$OUTFILE +echo "$ROOT_PARTITION_TYPE $ROOT_PARTITION $INSTALL_DRIVE $EFI_PARTITION" >$OUTFILE becho 'Done!' exit 0 diff --git a/scripts/install/install-image b/scripts/install/install-image index 1b482a19..f99d4ce8 100755 --- a/scripts/install/install-image +++ b/scripts/install/install-image @@ -202,6 +202,7 @@ install_new () { local root_part=$1 local inst_drv=$2 + local efi_part=$3 if [ ! -e "/dev/$root_part" ] || [ ! -e "/dev/$inst_drv" ]; then fail_exit "Invalid drive/partition ($inst_drv and $root_part)." @@ -214,7 +215,7 @@ install_new () # postinst operations if ! /opt/vyatta/sbin/install-postinst-new \ - "$inst_drv" "$root_part" union; then + "$inst_drv" "$root_part" union "$efi_part"; then exit 1 fi } @@ -291,13 +292,14 @@ fi root_part_type='' root_part='' inst_drv='' -eval "read root_part_type root_part inst_drv <$PART_FILE" >&/dev/null +efi_part='' +eval "read root_part_type root_part inst_drv efi_part <$PART_FILE" >&/dev/null rm -f $PART_FILE >&/dev/null # handle different types case "$root_part_type" in new) - install_new "$root_part" "$inst_drv" + install_new "$root_part" "$inst_drv" "$efi_part" exit 0 ;; union|old) diff --git a/scripts/install/install-postinst-new b/scripts/install/install-postinst-new index 2457cdd3..187f812b 100755 --- a/scripts/install/install-postinst-new +++ b/scripts/install/install-postinst-new @@ -20,6 +20,8 @@ INSTALL_DRIVE=$1 ROOT_PARTITION=$2 # install type: "union" or "old" INSTALL_TYPE=$3 +# EFI partition. 0 or partition +EFI_PARTITION=$4 # Default user DEFAULT_USER=vyos @@ -122,20 +124,29 @@ install_grub () { # members. progress_indicator start - - if [[ $grub_inst_drv == "md raid" ]]; then - for slave in $raid_slaves; do - grub_inst_drv=${slave:0:3} - output=$(grub-install --no-floppy --recheck --root-directory=$grub_root \ - /dev/$grub_inst_drv 2>&1) - lecho "$output" - done - else - output=$(grub-install --no-floppy --recheck --root-directory=$grub_root \ - /dev/$grub_inst_drv 2>&1) - lecho "$output" + + #TODO EFI needs to go on every disk + if [ -b /dev/$EFI_PARTITION ]; then + mkdosfs -F 32 -n EFI /dev/$EFI_PARTITION + mkdir -p $grub_root/boot/efi + mount /dev/$EFI_PARTITION $grub_root/boot/efi + output=$(grub-install --no-floppy --recheck --target=x86_64-efi --root-directory=$grub_root --efi-directory=$grub_root/boot/efi --bootloader-id="VyOS") + umount $grub_root/boot/efi + else + if [[ $grub_inst_drv == "md raid" ]]; then + for slave in $raid_slaves; do + grub_inst_drv=${slave:0:3} + output=$(grub-install --no-floppy --recheck --root-directory=$grub_root \ + /dev/$grub_inst_drv 2>&1) + lecho "$output" + done + else + output=$(grub-install --no-floppy --recheck --root-directory=$grub_root \ + /dev/$grub_inst_drv 2>&1) + lecho "$output" + fi fi - + progress_indicator stop output=$(/opt/vyatta/sbin/vyatta-grub-setup $grub_setup_args \ diff --git a/scripts/vyatta-grub-setup b/scripts/vyatta-grub-setup index ea4dc905..3959547d 100755 --- a/scripts/vyatta-grub-setup +++ b/scripts/vyatta-grub-setup @@ -54,6 +54,7 @@ shift `expr $OPTIND - 1` ROOT_PARTITION="$1" GRUB_OPTIONS="$2" ROOTFSDIR="$3" +EFI_PARTITION="$4" [ "$ROOT_PARTITION" ] || exit 1 @@ -155,6 +156,11 @@ fi echo -e "serial --unit=0 --speed=9600" echo "terminal_output --append serial" + if [ -b /dev/$EFI_PARTITION ]; then + echo -e "insmod efi_gop" + echo -e "insmod efi_uga" + fi + if [ ${ROOT_PARTITION:0:2} = "md" ]; then uuid_root_disk=`/sbin/tune2fs -l /dev/${root_disk}1 | grep UUID | awk '{print $3}'` uuid_root_md=`/sbin/tune2fs -l /dev/md${ROOT_PARTITION#md} | grep UUID | awk '{print $3}'` |