tazinst rev 106

tazinst: add efibootmgr support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Sep 18 14:06:43 2020 +0000 (2020-09-18)
parents 888cefc4002e
children 26b2bbcfb6ec
files tazinst
line diff
     1.1 --- a/tazinst	Thu Aug 20 07:05:35 2020 +0000
     1.2 +++ b/tazinst	Fri Sep 18 14:06:43 2020 +0000
     1.3 @@ -40,6 +40,9 @@
     1.4  export TEXTDOMAIN='tazinst'
     1.5  
     1.6  
     1.7 +# common kernels arguments
     1.8 +readonly KERNEL_ARGS="video=-32 quiet"
     1.9 +
    1.10  # files
    1.11  readonly DEFAULT_INSTALL_FILE=./tazinst.rc
    1.12  readonly SOURCE_ROOT=/media/source
    1.13 @@ -619,7 +622,7 @@
    1.14  	local pt_list="gpt msdos"
    1.15  	# get root uuid
    1.16  	local uuid="$(get root_uuid)"
    1.17 -	if [ "$(/sbin/blkid | grep -c "$uuid")" = "1" ]; then
    1.18 +	if [ "$(blkid | grep -c "$uuid")" = "1" ]; then
    1.19  		if ! printf "%s" "$(p_table $uuid)" | \
    1.20  				egrep -q "$(regex "$pt_list")"; then
    1.21  			_ 'Error: Unsupported Partition Table.' 1>&2
    1.22 @@ -797,12 +800,10 @@
    1.23  	web)
    1.24  		printf "%s" "$LST_WEB" | \
    1.25  			/bin/busybox awk -F: '/..*/{printf "%-12s%s\n", $1, $3}' ;;
    1.26 -	root_uuid)
    1.27 -	 	/sbin/blkid -s TYPE -s LABEL | sort ;;
    1.28  	root_format)
    1.29  	 	printf "%s" "$LST_FORMAT" | \
    1.30  			/bin/busybox awk -F: '/..*/{printf "%-12s%s\n", $1, $2}' ;;
    1.31 -	home_uuid)
    1.32 +	home_uuid|root_uuid)
    1.33  		/sbin/blkid -s TYPE -s LABEL | sort ;;
    1.34  	home_format)
    1.35  		printf "%s" "$LST_FORMAT" | \
    1.36 @@ -858,7 +859,7 @@
    1.37  			if readlink $DEV | grep -q usb; then
    1.38  				DEV=$(basename $DEV)
    1.39  				if [ -d /sys/block/${DEV}/${DEV}1 ]; then
    1.40 -					/sbin/blkid /dev/$DEV* | tr ' ' '\n' | /bin/busybox awk '
    1.41 +					blkid /dev/$DEV* | tr ' ' '\n' | /bin/busybox awk '
    1.42  						/^\/dev\// {
    1.43  							DEV=$1
    1.44  							gsub(/:/,"",DEV)
    1.45 @@ -951,13 +952,13 @@
    1.46  		if (match($1,"^/dev")){
    1.47  			disknum++
    1.48  			part=0
    1.49 -			disk=substr($1,1,8)
    1.50 -			dev=substr($1,6,3)
    1.51 +			disk=$1
    1.52 +			dev=substr($1,6)
    1.53  			# get removable status
    1.54  			file="/sys/block/"dev"/removable"
    1.55  			"cat " file | getline removable
    1.56  			close("cat ")
    1.57 -	}
    1.58 +		}
    1.59  		# Count partitions
    1.60  		if (match($1,"[0-9][0-9]?")){
    1.61  			# List fixed drives only
    1.62 @@ -1055,20 +1056,17 @@
    1.63  # print dev from uuid
    1.64  uuid2dev()
    1.65  {
    1.66 -	local uuid="$1" id
    1.67 -	if [ "$(printf "%s" $uuid | cut -d '=' -f1)" = "UUID" ]; then
    1.68 -		id="$(printf "%s" $uuid | cut -d'=' -f2)"
    1.69 -		printf "$(/sbin/blkid -U $id)"
    1.70 -	else
    1.71 -		printf "%s" "$uuid"
    1.72 +	local uuid="$1"
    1.73 +	if [ "${uuid%=*}" = "UUID" ]; then
    1.74 +		uuid="$(blkid | sed '/ UUID="'${uuid#*=}'"/!d;s|:.*||')"
    1.75  	fi
    1.76 +	printf "%s" "$uuid"
    1.77  }
    1.78  
    1.79  # print disk from uuid
    1.80  uuid2disk()
    1.81  {
    1.82 -	local uuid="$1"
    1.83 -	printf "%s" "$(uuid2dev $uuid | /bin/busybox awk '{print substr($0,1,8)}')"
    1.84 +	printf "%s" "$(uuid2dev $1 | /bin/busybox sed 's|p*[0-9]*$||')"
    1.85  }
    1.86  
    1.87  dev2uuid()
    1.88 @@ -1105,9 +1103,9 @@
    1.89  # return removable status from uuid
    1.90  is_removable()
    1.91  {
    1.92 -	local uuid="$1" removable=1
    1.93 -	local disk="$(uuid2disk $uuid | /bin/busybox awk '{print substr($0,6,3)}')"
    1.94 -	if [ "$(printf "%s" $disk | wc -w)" -eq "1" ]; then
    1.95 +	local removable=1
    1.96 +	local disk="$(uuid2disk $1 | sed 's|/dev/||')"
    1.97 +	if [ "$disk" ]; then
    1.98  		[ "$(cat /sys/block/"$disk"/removable 2> /dev/null)" -gt "0" ] \
    1.99  			&& removable=0
   1.100  	fi
   1.101 @@ -1492,22 +1490,21 @@
   1.102  			syslinux_config
   1.103  			log "$(_ 'No bootloader to install.')" ;;
   1.104  	esac
   1.105 +	[ -d /sys/firmware/efi ] && efiboot_install
   1.106  }
   1.107  
   1.108  # print disk num
   1.109  disknum()
   1.110  {
   1.111 -	local partition="$(uuid2dev $1)"
   1.112 -	partition="${partition%%[0-9]*}"
   1.113 +	local disk="$(uuid2dev $1 | /bin/busybox sed 's|p*[0-9]*$||')"
   1.114  	/usr/sbin/parted -lms 2>&1 | grep "^/dev" | \
   1.115 -		/bin/busybox awk -v PART="$partition" '{if (match($0,PART)) print NR-1}'
   1.116 +		/bin/busybox awk -v PART="$disk:" '{if (match($0,PART)) print NR-1}'
   1.117  }
   1.118  
   1.119  # print partition num
   1.120  partnum()
   1.121  {
   1.122 -	local partition="$(uuid2dev $1)"
   1.123 -	printf "%s\n" "$((${partition#/dev/[hs]d[a-z]}-1))"
   1.124 +	printf "%s" "$(($(uuid2dev $1 | /bin/busybox sed 's|.*[^0-9]||')-1))"
   1.125  }
   1.126  
   1.127  # print root device
   1.128 @@ -1529,7 +1526,7 @@
   1.129  # add rootdelay for removable devices
   1.130  rootdelay()
   1.131  {
   1.132 -	is_removable "$ROOT_UUID" && printf "%s" "rootdelay=9"
   1.133 +	is_removable "$ROOT_UUID" && printf "%s" " rootdelay=9"
   1.134  }
   1.135  
   1.136  # print winboot uuid
   1.137 @@ -1578,7 +1575,7 @@
   1.138  #
   1.139  title SliTaz GNU/Linux $(cat $TARGET_ROOT/etc/slitaz-release) (Kernel $KERNEL)
   1.140  root (hd$(disknum $ROOT_UUID),$(partnum $ROOT_UUID))
   1.141 -kernel /boot/$KERNEL root=$(rootdev $ROOT_UUID) video=-32 quiet $(rootdelay)
   1.142 +kernel /boot/$KERNEL root=$(rootdev $ROOT_UUID) $KERNEL_ARGS$(rootdelay)
   1.143  
   1.144  _EOF_
   1.145  
   1.146 @@ -1679,7 +1676,7 @@
   1.147  LABEL slitaz
   1.148  	MENU LABEL SliTaz GNU/Linux $version
   1.149  	LINUX /boot/$KERNEL
   1.150 -	APPEND root=$(rootdev $ROOT_UUID) video=-32 quiet $(rootdelay)
   1.151 +	APPEND root=$(rootdev $ROOT_UUID) $KERNEL_ARGS$(rootdelay)
   1.152  
   1.153  LABEL cmdline
   1.154  	MENU LABEL Command Line
   1.155 @@ -1752,6 +1749,32 @@
   1.156  }
   1.157  
   1.158  
   1.159 +#-------------
   1.160 +# 5.3 efiboot
   1.161 +#-------------
   1.162 +
   1.163 +efiboot_install()
   1.164 +{
   1.165 +	local esp_fs_uuid mnt="/media/esp$$" efiboot="/EFI/SLITAZ"
   1.166 +	# We need efi stub support
   1.167 +	[ "$(strings $TARGET_ROOT/boot/$KERNEL | head | grep reloc)" ] || return
   1.168 +	# And the esp partition
   1.169 +	esp_fs_uuid="$(blkid | sed '/EFI system partition/!d;s|.* UUID="||;s|".*||;q')"
   1.170 +	[ "$esp_fs_uuid" ] || return
   1.171 +	# Copy SliTaz kernel and cmdline in esp partition
   1.172 +	mkdir $mnt &&
   1.173 +	mount "$(uuid2dev UUID=$esp_fs_uuid)" $mnt &&
   1.174 +	mkdir -p $mnt$efiboot 2> /dev/null
   1.175 +	if cp $TARGET_ROOT/boot/$KERNEL $mnt$efiboot/BZIMAGE.EFI; then
   1.176 +		log "$(_ 'Updating UEFI boot files')"
   1.177 +		echo "root=$(rootdev $ROOT_UUID) $KERNEL_ARGS$(rootdelay)" > $mnt$efiboot/linux.cmdline
   1.178 +		efibootmgr -v | grep -q SliTaz ||
   1.179 +		efibootmgr -c -d "$(uuid2disk UUID=$esp_fs_uuid)" -p "$(partnum UUID=$esp_fs_uuid)" \
   1.180 +			-L "SliTaz GNU/Linux" -l "${efiboot//\//\\}\\BZIMAGE.EFI"
   1.181 +	fi
   1.182 +	umount $mnt && rmdir $mnt
   1.183 +}
   1.184 +
   1.185  #--------------------
   1.186  # 6. execute section
   1.187  #--------------------