@@ -18,19 +18,46 @@ check_existence "grep"
1818check_existence " unsquashfs"
1919check_existence " mktemp"
2020check_existence " id"
21+ check_existence " head"
22+ check_existence " tail"
23+ check_existence " fdisk"
24+ check_existence " cat"
2125log_end " seems sane"
2226
2327# # Setup essential variables; allow overriding with input
2428root_mount=$( mount | grep " / " | sed ' s/ /\n/' | head -n1)
2529root_type=$( mount | grep -Eo " / type \w+" | sed ' s/ /\n/g' | tail -n1)
26- if grep ' /dev/nvme' <<< $root_mount ; then
27- grub_device=$( echo $root_mount | sed " s|p[0-9]\+$||" ) ;
28- elif grep ' /dev/sd' <<< $root_mount ; then
29- grub_device=$( echo $root_mount | sed " s|[0-9]\+||" ) ;
30- elif grep ' /dev/vd' <<< $root_mount ; then
31- grub_device=$( echo $root_mount | sed " s|[0-9]\+||" ) ;
30+
31+ expect_one_line () {
32+ ERROR_MESSAGE_ZERO=$1
33+ ERROR_MESSAGE_MULTIPLE=$2
34+ (set -eu;
35+ IFS=' ' read -r x || (echo " $ERROR_MESSAGE_ZERO " >& 2; exit 1)
36+ (! IFS=' ' read -r) || (echo " $ERROR_MESSAGE_MULTIPLE " >& 2; exit 1)
37+ printf " %s\n" " $x " );
38+ }
39+
40+ if [ -d /sys/firmware/efi ]; then
41+ boot_type=uefi
42+ boot_device=$(
43+ set -euo pipefail
44+ fdisk -l -o ' Device,Type' |
45+ grep ' EFI System' |
46+ sed -r ' s_([^ ]*) *EFI System$_\1_' |
47+ expect_one_line \
48+ " Fdisk found no EFI System Partitions: please specify with -g option" \
49+ " Found multiple EFI System Partitions: please specify with -g option" )
3250else
33- echo " Unable to determine your grub boot device! Please specify with the -g option."
51+ boot_type=mbr
52+ if grep ' /dev/nvme' <<< " $root_mount" ; then
53+ boot_device=$( echo " $root_mount " | sed " s|p[0-9]\+$||" ) ;
54+ elif grep ' /dev/sd' <<< " $root_mount" ; then
55+ boot_device=$( echo " $root_mount " | sed " s|[0-9]\+||" ) ;
56+ elif grep ' /dev/vd' <<< " $root_mount" ; then
57+ boot_device=$( echo " $root_mount " | sed " s|[0-9]\+||" ) ;
58+ else
59+ echo " Unable to determine your grub boot device! Please specify with the -g option."
60+ fi
3461fi
3562working_directory=$( mktemp -d)
3663
@@ -48,7 +75,7 @@ digitalocean=false
4875while getopts " :g:r:t:Gdw:h" opt; do
4976 case $opt in
5077 g)
51- grub_device =$OPTARG
78+ boot_device =$OPTARG
5279 ;;
5380 r)
5481 root_mount=$OPTARG
@@ -100,9 +127,22 @@ then
100127 fi
101128fi
102129
130+ boot_description=$(
131+ case $boot_type in
132+ uefi)
133+ echo " uefi boot with esp at $boot_device "
134+ ;;
135+ mbr)
136+ echo " mbr at $boot_device "
137+ ;;
138+ * )
139+ echo " bad boot type" >&2
140+ exit 1
141+ ;;
142+ esac)
103143# # Give one last chance to back out
104144log " NixOS installer (nixos-in-place)"
105- log " GRUB => $grub_device "
145+ log " Boot => $boot_description "
106146log " Root => $root_mount ($root_type )"
107147log " ISO => $iso "
108148log " Digital Ocean => $digitalocean "
@@ -134,7 +174,7 @@ pushd "$working_directory"
134174
135175 # # Setup the chroot environment before install
136176 log " Embarking stage1!"
137- " $here /stage1" " $here " " $root_mount " " $root_type " " $grub_device " " $digitalocean "
177+ " $here /stage1" " $here " " $root_mount " " $root_type " " $boot_type " " $boot_device " " $digitalocean "
138178
139179 # # Minimize residual space usage
140180 # /var/empty is immutable https://github.com/NixOS/nixpkgs/pull/18365
0 commit comments