From: Daniel Golle Date: Wed, 21 Apr 2021 16:08:17 +0000 (+0100) Subject: uvol: improve autopart and lvm scripts, fix F2FS volumes X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=1b570f7aad1bb160aa86d9d45b578551b93d49eb;p=feed%2Fpackages.git uvol: improve autopart and lvm scripts, fix F2FS volumes Use sfdisk to get GPT partition by name as partition names are not known by the kernel if added via partx. Make sure physical volume names are unique, if possible correlate with the disks serial number and/or card's cid. mkf2fs apparently returns 134 even in case format succeeded, so don't fail in that case (this fixes rw volumes large enough for F2FS to be selected by the lvm scripts of uvol). Signed-off-by: Daniel Golle --- diff --git a/utils/uvol/files/autopart.defaults b/utils/uvol/files/autopart.defaults index c35b238adc..b6a3cdd603 100644 --- a/utils/uvol/files/autopart.defaults +++ b/utils/uvol/files/autopart.defaults @@ -2,9 +2,29 @@ . /lib/functions.sh . /lib/upgrade/common.sh +. /usr/share/libubox/jshn.sh OWRT_VOLUMES=owrt-volumes + +get_partition_by_name_gpt() { + local dev="$1" + local part parts node name + json_load "$(sfdisk -J "/dev/$dev" 2>/dev/null)" + json_select "partitiontable" || return + json_select "partitions" || return + json_get_keys parts + for part in $parts; do + json_select "$part" + json_get_vars node name + if [ "$2" = "$name" ]; then + echo "$node" + break + fi + json_select .. + done +} + part_fixup() { echo "write" | sfdisk --force -q -w never $1 } @@ -57,20 +77,22 @@ lvm_init() { autopart_init() { local diskdev local lvmpart - local diskserial + local diskserial diskhash export_bootdevice && export_partdevice diskdev 0 [ "$diskdev" ] || return - [ -e "/sys/class/block/$diskdev/device/serial" ] && diskserial=$(cat /sys/class/block/$diskdev/device/serial) - + [ -e "/sys/class/block/$diskdev/device/serial" ] && diskserial="$(cat /sys/class/block/$diskdev/device/serial)" + [ -e "/sys/class/block/$diskdev/device/cid" ] && diskserial="$diskserial$(cat /sys/class/block/$diskdev/device/cid)" + [ "$diskserial" ] || diskserial="$(cat /proc/sys/kernel/random/uuid)" + diskhash="$(echo $diskserial | sha256sum | cut -d' ' -f1)" part_fixup /dev/$diskdev create_lvm_part /dev/$diskdev || return - lvmpart=$(get_partition_by_name $diskdev $OWRT_VOLUMES) + lvmpart=$(get_partition_by_name_gpt $diskdev $OWRT_VOLUMES) [ "$lvmpart" ] || return - lvm_init /dev/$lvmpart "${OWRT_VOLUMES}${diskserial:+-${diskserial:2}}" + lvm_init $lvmpart "${OWRT_VOLUMES}-${diskhash:0:16}" } autopart_init diff --git a/utils/uvol/files/lvm.sh b/utils/uvol/files/lvm.sh index 4a20f628d1..c250be534b 100644 --- a/utils/uvol/files/lvm.sh +++ b/utils/uvol/files/lvm.sh @@ -231,7 +231,9 @@ createvol() { [ "$lv_full_name" ] || return 22 lvm_cmd lvchange -a y "$lv_full_name" || return 1 if [ $lv_size -gt $(( 100 * 1024 * 1024 )) ]; then - mkfs.f2fs -f -l "$1" "$lv_path" || return 1 + mkfs.f2fs -f -l "$1" "$lv_path" + ret=$? + [ $ret != 0 ] && [ $ret != 134 ] && return 1 else mke2fs -F -L "$1" "$lv_path" || return 1 fi @@ -271,7 +273,7 @@ listvols() { local reports rep lv lvs lv_name lv_size lv_mode volname volname=${1:-.*} json_init - json_load "$(lvs -o lv_name,lv_size -S "lv_name=~^[rw][ow]_$volname\$ && vg_name=$vg_name")" + json_load "$(lvs -o lv_name,lv_size -S "lv_name=~^[rw][owp]_$volname\$ && vg_name=$vg_name")" json_select report json_get_keys reports for rep in $reports; do