Skip to content

Commit

Permalink
T955: Integrating EFI into the installer
Browse files Browse the repository at this point in the history
  • Loading branch information
kroy-the-rabbit committed Nov 6, 2018
1 parent a773178 commit 13ef90f
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 39 deletions.
14 changes: 7 additions & 7 deletions scripts/install/install-functions
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ get_drive_size () {
# Probe hardrives not shown in /proc/partitions by default
probe_drives () {
# Find drives that may not be in /proc/partitions since not mounted
drive=$(ls /sys/block | grep '[hsv]d.')
drive=$(ls /sys/block | grep '[hsv]d.|nvme.')

# now exclude all drives that are read-only
for drive in $drive; do
Expand All @@ -174,13 +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]$|nvme[0-9]n[0-9]" | \
egrep -v "^$")

#should be better about finding installable drives
drives=$(lsblk -dn -o name -I8)
#this needs more testing to decide if better than above
#drives=$(lsblk -dn -o name -I8)

# take the first drive as the default
drv=$(echo $drives | /usr/bin/awk '{ print $1 }')
Expand Down
48 changes: 31 additions & 17 deletions scripts/install/install-get-partition
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ PARTITION=''
ROOT_FSTYPE='ext4'

EFI_PARTITION=0
if [ -d /sys/firmware/efi ]; then
EFI_PARTITION=1
fi

warn_of_dire_consequences () {
# Give the user a requisite warning that we are about to nuke their drive
Expand Down Expand Up @@ -277,13 +280,19 @@ check_for_new_raid () {
let root_size-=$part_start_offset

for drive in $drives; do
echo "Creating data partition: /dev/${drive}${data_dev}"
create_partitions "$drive" $root_size $part_start_offset "no"
sfdisk --change-id /dev/$drive $data_dev 0xfd
# mark data partition as bootable
lecho "Marking /dev/$drive partition $data_dev bootable"
output=$(parted -s /dev/$drive set $data_dev boot on 2>&1)
lecho "$output"
create_partitions "$drive" $root_size "no"
if [ "$EFI_PARTITION" -eq "1" ]; then
#EFI moves the data parition on RAID to 3
data_dev=3
echo "Create data partition: /dev/${drive}${data_dev}"
else
echo "Creating data partition: /dev/${drive}${data_dev}"
sfdisk --change-id /dev/$drive $data_dev 0xfd
# mark data partition as bootable
lecho "Marking /dev/$drive partition $data_dev bootable"
output=$(parted -s /dev/$drive set $data_dev boot on 2>&1)
lecho "$output"
fi
done

# Must give partition device time to settle
Expand Down Expand Up @@ -670,7 +679,7 @@ 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
if [ "$EFI_PARTITION" -eq "1" ]; then
#Need room for the EFI partition. 512 is standard, but 256 is probably okay here
root_part_size=$((root_part_size - 256))

Expand All @@ -689,15 +698,17 @@ create_partitions() {
exit 1
fi
# set the partition number on the device.
if [ -n "$( echo $ldrive | grep -E "cciss|ida" )" ]; then
if [ -n "$( echo $ldrive | grep -E "cciss|ida|nvme" )" ]; then
# if this is a cciss
ROOT_PARTITION=$ldrive"p3"
EFI_PARTITION=$ldrive"p2"
efipart=$ldrive"p2"
else
# else... the rest of the world
ROOT_PARTITION=$ldrive"3"
EFI_PARTITION=$ldrive"2"
efipart=$ldrive"2"
fi
#Add the drive to the file so grub can install
echo $efipart >> /tmp/efiparts.tmp
else
# Force FAT label creation
lecho "Creating a new disklabel on $ldrive"
Expand Down Expand Up @@ -729,7 +740,7 @@ create_partitions() {
fi

# set the partition number on the device.
if [ -n "$( echo $ldrive | grep -E "cciss|ida" )" ]; then
if [ -n "$( echo $ldrive | grep -E "cciss|ida|nvme" )" ]; then
# if this is a cciss
ROOT_PARTITION=$ldrive"p1"
else
Expand Down Expand Up @@ -855,6 +866,7 @@ setup_method_auto () {
echo -n "How big of a root partition should I create? ($ROOT_MIN"MB" - $size"MB") [$size]MB: "
response=$(get_response "$size")
# TODO: need to have better error checking on this value
# TODO: This should also probably take into account the size of the EFI partition (256MB)
root_part_size=$(echo "$response" | sed 's/[^0-9]//g')
if [ $root_part_size -lt $ROOT_MIN ] \
|| [ $root_part_size -gt $size ]; then
Expand All @@ -868,10 +880,12 @@ setup_method_auto () {

# now take the data and create the partitions
create_partitions "$INSTALL_DRIVE" "$root_part_size" "yes"
# mark data partition as bootable
lecho "Marking /dev/$INSTALL_DRIVE partition 1 as bootable"
output=$(parted -s /dev/$INSTALL_DRIVE set 1 boot on 2>&1)
lecho "$output"
if ! [ "$EFI_PARTITION" -eq "1" ]; then
# mark data partition as bootable
lecho "Marking /dev/$INSTALL_DRIVE partition 1 as bootable"
output=$(parted -s /dev/$INSTALL_DRIVE set 1 boot on 2>&1)
lecho "$output"
fi
# Must give partition device time to settle
sleep 5
}
Expand Down Expand Up @@ -989,7 +1003,7 @@ if [ -z "$ROOT_PARTITION" ]; then
exit 1
fi

echo "$ROOT_PARTITION_TYPE $ROOT_PARTITION $INSTALL_DRIVE $EFI_PARTITION" >$OUTFILE
echo "$ROOT_PARTITION_TYPE $ROOT_PARTITION $INSTALL_DRIVE" >$OUTFILE
becho 'Done!'
exit 0

8 changes: 3 additions & 5 deletions scripts/install/install-image
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ 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)."
Expand All @@ -215,7 +214,7 @@ install_new ()

# postinst operations
if ! /opt/vyatta/sbin/install-postinst-new \
"$inst_drv" "$root_part" union "$efi_part"; then
"$inst_drv" "$root_part" union; then
exit 1
fi
}
Expand Down Expand Up @@ -292,14 +291,13 @@ fi
root_part_type=''
root_part=''
inst_drv=''
efi_part=''
eval "read root_part_type root_part inst_drv efi_part <$PART_FILE" >&/dev/null
eval "read root_part_type root_part inst_drv <$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" "$efi_part"
install_new "$root_part" "$inst_drv"
exit 0
;;
union|old)
Expand Down
38 changes: 29 additions & 9 deletions scripts/install/install-postinst-new
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ INSTALL_DRIVE=$1
ROOT_PARTITION=$2
# install type: "union" or "old"
INSTALL_TYPE=$3
# EFI partition. 0 or partition
EFI_PARTITION=$4
# For passing into vyatta-grub-setup
EFI_PARTITION=0

# Default user
DEFAULT_USER=vyos
Expand Down Expand Up @@ -125,13 +125,33 @@ install_grub () {

progress_indicator start

#TODO EFI needs to go on every disk
if [ -b /dev/$EFI_PARTITION ]; then
mkdosfs -F 32 -n EFI /dev/$EFI_PARTITION
if [ -f "/tmp/efiparts.tmp" ]; then
EFI_PARTITION=1
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
readarray parts < /tmp/efiparts.tmp
part_length=${#parts[@]}
bootloader_name="VyOS"
I=0
for part in "${parts[@]}"
do
#Name the bootloaders something different if we have a RAID
if [ "$part_length" -gt "1" ]; then
bootloader_name="VyOS (RAID disk $I)"
((I++))
fi
mkdosfs -F 32 -n EFI /dev/$part
mount /dev/$part $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="$bootloader_name")
umount $grub_root/boot/efi
##TODO DO we need these to be in fstab??
#
#This is what I've used in the past
#if [ $I -gt 0 ]; then
# RAIDPART="#"
#fi
#echo "${RAIDPART}PARTUUID=$(blkid -s PARTUUID -o value $part) /boot/efi vfat defaults 0 1" >> /etc/fstab
done
rm /tmp/efiparts.tmp
else
if [[ $grub_inst_drv == "md raid" ]]; then
for slave in $raid_slaves; do
Expand All @@ -150,7 +170,7 @@ install_grub () {
progress_indicator stop

output=$(/opt/vyatta/sbin/vyatta-grub-setup $grub_setup_args \
"$ROOT_PARTITION" '' $grub_root 2>&1)
"$ROOT_PARTITION" '' $grub_root "$EFI_PARTITION" 2>&1)
ret=$?
lecho "$output"
if [ $ret == 0 ]; then
Expand Down
3 changes: 2 additions & 1 deletion scripts/vyatta-grub-setup
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ fi
echo -e "serial --unit=0 --speed=9600"
echo "terminal_output --append serial"

if [ -b /dev/$EFI_PARTITION ]; then
# EFI needs a few extra modules
if [ "$EFI_PARTITION" -eq "1" ]; then
echo -e "insmod efi_gop"
echo -e "insmod efi_uga"
fi
Expand Down

0 comments on commit 13ef90f

Please sign in to comment.