update.sh: be more careful searching for the correct disk
otherwise we might catch the install USB stick still inserted
This commit is contained in:
parent
1dc7a0fae6
commit
1138c7c1ec
64
update.sh
64
update.sh
|
@ -69,27 +69,61 @@ CURRENT_ROOT_HASH=${CURRENT_ROOT_HASH%% *}
|
||||||
|
|
||||||
CURRENT_ROOT_UUID=${CURRENT_ROOT_HASH:32:8}-${CURRENT_ROOT_HASH:40:4}-${CURRENT_ROOT_HASH:44:4}-${CURRENT_ROOT_HASH:48:4}-${CURRENT_ROOT_HASH:52:12}
|
CURRENT_ROOT_UUID=${CURRENT_ROOT_HASH:32:8}-${CURRENT_ROOT_HASH:40:4}-${CURRENT_ROOT_HASH:44:4}-${CURRENT_ROOT_HASH:48:4}-${CURRENT_ROOT_HASH:52:12}
|
||||||
|
|
||||||
[[ /dev/disk/by-partlabel/root1 -ef /dev/disk/by-partuuid/${CURRENT_ROOT_UUID} ]] \
|
bootdisk() {
|
||||||
&& NEW_ROOT_NUM=2 && OLD_ROOT_NUM=1
|
UUID=$({ read -r -n 1 -d '' _; read -n 72 uuid; echo -n ${uuid,,}; } < /sys/firmware/efi/efivars/LoaderDevicePartUUID-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f)
|
||||||
|
|
||||||
[[ /dev/disk/by-partlabel/root2 -ef /dev/disk/by-partuuid/${CURRENT_ROOT_UUID} ]] \
|
[[ $UUID ]] || return 1
|
||||||
&& NEW_ROOT_NUM=1 && OLD_ROOT_NUM=2
|
echo "/dev/disk/by-partuuid/$UUID"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
if ! [[ $NEW_ROOT_NUM ]]; then
|
get_disk() {
|
||||||
|
for dev in /dev/disk/by-path/*; do
|
||||||
|
[[ $dev -ef $1 ]] || continue
|
||||||
|
echo ${dev%-part*}
|
||||||
|
return 0
|
||||||
|
done
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
ROOT_DEV=$(get_disk $(bootdisk))
|
||||||
|
|
||||||
|
if ! [[ $ROOT_DEV ]]; then
|
||||||
echo "Current partitions booted from not found!"
|
echo "Current partitions booted from not found!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## find base device and partition number
|
unset FOUND
|
||||||
for dev in /dev/disk/by-path/*; do
|
for dev in ${ROOT_DEV}-part*; do
|
||||||
if ! [[ $ROOT_PARTNO ]] && [[ /dev/disk/by-partlabel/root${NEW_ROOT_NUM} -ef $dev ]]; then
|
[[ $(blkid -o value -s PARTLABEL $dev) == root1 ]] &&
|
||||||
ROOT_PARTNO=${dev##*-part}
|
ROOT1_DEV=$dev
|
||||||
ROOT_DEV=${dev%-part*}
|
|
||||||
fi
|
[[ $(blkid -o value -s PARTLABEL $dev) == root2 ]] &&
|
||||||
[[ $ROOT_PARTNO ]] && break
|
ROOT2_DEV=$dev
|
||||||
|
|
||||||
|
[[ $(blkid -o value -s PARTUUID $dev) == $CURRENT_ROOT_UUID ]] &&
|
||||||
|
CURRENT_ROOT_DEV=$dev
|
||||||
|
|
||||||
|
[[ $ROOT1_DEV ]] && [[ $ROOT2_DEV ]] && [[ $CURRENT_ROOT_DEV ]] && break
|
||||||
done
|
done
|
||||||
|
|
||||||
if ! [[ $ROOT_PARTNO ]] || ! [[ $ROOT_DEV ]]; then
|
if ! [[ $ROOT1_DEV ]] || ! [[ $ROOT2_DEV ]] || ! [[ $CURRENT_ROOT_DEV ]]; then
|
||||||
|
echo "Couldn't find partition numbers"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
[[ $CURRENT_ROOT_DEV == $ROOT2_DEV ]] \
|
||||||
|
&& NEW_ROOT_NUM=1 && OLD_ROOT_NUM=2 \
|
||||||
|
&& NEW_ROOT_PARTNO=${ROOT1_DEV##*-part}
|
||||||
|
|
||||||
|
|
||||||
|
[[ $CURRENT_ROOT_DEV == $ROOT1_DEV ]] \
|
||||||
|
&& NEW_ROOT_NUM=2 && OLD_ROOT_NUM=1 \
|
||||||
|
&& NEW_ROOT_PARTNO=${ROOT2_DEV##*-part}
|
||||||
|
|
||||||
|
ROOT_PARTNO=${CURRENT_ROOT_DEV##*-part}
|
||||||
|
|
||||||
|
if ! [[ $NEW_ROOT_PARTNO ]] || ! [[ $ROOT_PARTNO ]] || ! [[ $ROOT_DEV ]]; then
|
||||||
echo "Couldn't find partition numbers"
|
echo "Couldn't find partition numbers"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -129,12 +163,12 @@ if ! [[ $NO_CHECK ]]; then
|
||||||
sha512sum -c sha512sum.txt
|
sha512sum -c sha512sum.txt
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dd status=progress if=root.img of=/dev/disk/by-partlabel/root${NEW_ROOT_NUM}
|
dd status=progress if=root.img of=${ROOT_DEV}-part${NEW_ROOT_PARTNO}
|
||||||
|
|
||||||
# set the new partition uuids
|
# set the new partition uuids
|
||||||
ROOT_UUID=${ROOT_HASH:32:8}-${ROOT_HASH:40:4}-${ROOT_HASH:44:4}-${ROOT_HASH:48:4}-${ROOT_HASH:52:12}
|
ROOT_UUID=${ROOT_HASH:32:8}-${ROOT_HASH:40:4}-${ROOT_HASH:44:4}-${ROOT_HASH:48:4}-${ROOT_HASH:52:12}
|
||||||
|
|
||||||
sfdisk --part-uuid ${ROOT_DEV} ${ROOT_PARTNO} ${ROOT_UUID}
|
sfdisk --part-uuid ${ROOT_DEV} ${NEW_ROOT_PARTNO} ${ROOT_UUID}
|
||||||
|
|
||||||
# install to /efi
|
# install to /efi
|
||||||
mkdir -p /efi/EFI/${NAME}
|
mkdir -p /efi/EFI/${NAME}
|
||||||
|
|
Loading…
Reference in a new issue