recovery-init: Always use blkid(1) to find partitions 50/155250/3
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 12 Oct 2017 11:44:55 +0000 (13:44 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Fri, 13 Oct 2017 08:35:46 +0000 (10:35 +0200)
blkid(1) was introduced to find partition based on fs
label for targets that do not support partlabel (eg. rpi3).
However, blkid(1) can also search using partlabel, so it's
the only utility it's needed to locate partitions.

This commit makes recovery-init always use blkid(1),
allowing partx(1) to be dropped.

Change-Id: Ie021210b3c9ff359d1b112d51479920c1ba55c38

src/system-recovery/50-system-recovery.list.m4.in
src/system-recovery/recovery-init.in

index c5ca24f..74c7225 100644 (file)
@@ -37,7 +37,6 @@ WITHLIBS="
 /usr/bin/sync
 /usr/bin/touch
 /usr/bin/umount
-/usr/sbin/partx
 /usr/sbin/blkid
 /usr/bin/ls
 /usr/sbin/agetty
index ce84c8a..65f3772 100644 (file)
@@ -4,46 +4,19 @@ SYSTEM_RECOVERY_GUI="@SYSTEM_RECOVERY_LIBEXEC_DIR@/system-recovery.gui"
 SYSTEM_RECOVERY_NON_GUI="@SYSTEM_RECOVERY_LIBEXEC_DIR@/system-recovery.non_gui"
 FAKE_ROOT=/system
 
-GREP="/usr/bin/grep"
 MOUNT="/usr/bin/mount"
-PARTX="/usr/sbin/partx"
 BLKID="/usr/sbin/blkid"
 REBOOT="@INITRD_RECOVERY_LIBEXEC_DIR@/minireboot"
 SYNC="/usr/bin/sync"
-TOUCH="/usr/bin/touch"
 UMOUNT="/usr/bin/umount"
-TR="/usr/bin/tr"
-SED="/usr/bin/sed"
-CUT="/usr/bin/cut"
 
 #------------------------------------------------
 #       get partition id
 #------------------------------------------------
 get_partition_id() {
-    EMMC_DEVICE="/dev/mmcblk0"
-    RET_PARTX=$("$PARTX" -s ${EMMC_DEVICE})
-    TEST=$(echo "$RET_PARTX" | "$TR" -s ' ' | "$SED" -e '1d' -e 's/^ //' | "$CUT" -d ' ' -f 6)
-    if [ "z$TEST" == "z" ]; then
-        PART_ROOTFS=$("$BLKID" -L "rootfs" -o device)
-        PART_SYSTEM_DATA=$("$BLKID" -L "system-data" -o device)
-        PART_USER=$("$BLKID" -L "user" -o device)
-    else
-        PART_ROOTFS=${EMMC_DEVICE}p$(
-                       echo "$RET_PARTX" |
-                       "$TR" -s ' ' | "$TR" '[:upper:]' '[:lower:]' |
-                       "$GREP" "rootfs" | "$SED" 's/^ //' |
-                       "$CUT" -d ' ' -f 1)
-        PART_SYSTEM_DATA=${EMMC_DEVICE}p$(
-                       echo "$RET_PARTX" |
-                       "$TR" -s ' ' | "$TR" '[:upper:]' '[:lower:]' |
-                       "$GREP" "system-data" | "$SED" 's/^ //' |
-                       "$CUT" -d ' ' -f 1)
-        PART_USER=${EMMC_DEVICE}p$(
-                       echo "$RET_PARTX" |
-                       "$TR" -s ' ' | "$TR" '[:upper:]' '[:lower:]' |
-                       "$GREP" "user" | "$SED" 's/^ //' |
-                       "$CUT" -d ' ' -f 1)
-    fi
+    PART_ROOTFS=$("$BLKID" --match-token PARTLABEL=ROOTFS -o device || "$BLKID" --match-token LABEL=rootfs -o device)
+    PART_SYSTEM_DATA=$("$BLKID" --match-token PARTLABEL=SYSTEM-DATA -o device || "$BLKID" --match-token LABEL=system-data -o device)
+    PART_USER=$("$BLKID" --match-token PARTLABEL=USER -o device || "$BLKID" --match-token LABEL=user -o device)
 }
 
 #------------------------------------------------
@@ -71,7 +44,6 @@ mount_partitions() {
 umount_partitions() {
     echo "umount partitions"
    "$SYNC"
-    get_partition_id
 
     "$UMOUNT" ${FAKE_ROOT}/opt/usr
     "$UMOUNT" ${FAKE_ROOT}/opt