Skip to content

Commit 5640545

Browse files
Support UUID in addition to PARTUUID
This supports systems where the filesystem's UUID is specified in fstab and on the kernel commandline. This is the first step in supporting Armbian, which uses UUID rather than PARTUUID.
1 parent 28740b4 commit 5640545

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

rpi-clone

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,12 @@ do
801801
then
802802
src_label[p]="$label"
803803
fi
804+
805+
fsuuid=`lsblk --raw --output UUID --noheadings "${src_device[p]}"`
806+
if [ "$fsuuid" != "" ]
807+
then
808+
src_fsuuid[p]="$fsuuid"
809+
fi
804810
done
805811

806812

@@ -1118,7 +1124,8 @@ then
11181124
SD_slot_dst=1
11191125
dst_part_base=${dst_disk}p
11201126
if [ "$edit_fstab_name" == "" ] \
1121-
&& ! grep -q "^PARTUUID=" /etc/fstab
1127+
&& ! grep -q "^PARTUUID=" /etc/fstab \
1128+
&& ! grep -q "^UUID=" /etc/fstab
11221129
then
11231130
edit_fstab_name=$dst_part_base
11241131
assumed_fstab_edit=1
@@ -1206,6 +1213,11 @@ do
12061213
then
12071214
dst_label[p]="$label"
12081215
fi
1216+
fsuuid=`lsblk --raw --output UUID --noheadings "${dst_device[p]}"`
1217+
if [ "$fsuuid" != "" ]
1218+
then
1219+
dst_fsuuid[p]="$fsuuid"
1220+
fi
12091221
fi
12101222
done
12111223

@@ -1598,9 +1610,20 @@ Use -U for unattended even if initializing.
15981610
echo ""
15991611
fi
16001612
change_label "$p" "$fs_type" "$dst_dev"
1613+
# TODO: Change uuid in case filesystem uuid is used in fstab?
16011614
fi
16021615
fi
16031616
fi
1617+
1618+
# Wait for kernel and udev to process changes (i.e. new
1619+
# UUIDs and labels)
1620+
udevadm settle
1621+
# Update UUID, just in case it changed
1622+
fsuuid=`lsblk --raw --output UUID --noheadings "$dst_dev"`
1623+
if [ "$fsuuid" != "" ]
1624+
then
1625+
dst_fsuuid[p]="$fsuuid"
1626+
fi
16041627
done
16051628
ext_label=""
16061629
else
@@ -1780,6 +1803,11 @@ then
17801803
then
17811804
qecho "Editing $cmdline_txt PARTUUID to use $dst_disk_ID"
17821805
sed -i "s/${src_disk_ID}/${dst_disk_ID}/" "$cmdline_txt"
1806+
elif [ "${src_fsuuid[root_part_num]}" != "" ] && grep -q "${src_fsuuid[root_part_num]}" "$cmdline_txt"
1807+
then
1808+
new_fsuuid=${dst_fsuuid[root_part_num]}
1809+
qecho "Editing $cmdline_txt UUID to use $new_fsuuid"
1810+
sed -i "s/${src_fsuuid[root_part_num]}/${new_fsuuid}/" "$cmdline_txt"
17831811
elif [ "$edit_fstab_name" != "" ] && grep -q ${src_part_base} $cmdline_txt
17841812
then
17851813
qecho "Editing $cmdline_txt references from $src_part_base to $edit_fstab_name"
@@ -1797,6 +1825,20 @@ if grep -q $src_disk_ID $fstab
17971825
then
17981826
qecho "Editing $fstab PARTUUID to use $dst_disk_ID"
17991827
sed -i "s/${src_disk_ID}/${dst_disk_ID}/g" "$fstab"
1828+
elif grep -q ^UUID= $fstab
1829+
then
1830+
for ((p = 1; p <= n_src_parts; p++))
1831+
do
1832+
old_fsuuid=${src_fsuuid[p]}
1833+
new_fsuuid=${dst_fsuuid[p]}
1834+
if [ "$old_fsuuid" == "" -o "$new_fsuuid" == "" ] || ! grep -q "$old_fsuuid" "$fstab";
1835+
then
1836+
continue
1837+
fi
1838+
1839+
qecho "Editing $fstab partition $p UUID to use $new_fsuuid"
1840+
sed -i "s/$old_fsuuid/${new_fsuuid}/" "$fstab"
1841+
done
18001842
elif [ "$edit_fstab_name" != "" ] && grep -q ${src_part_base} $fstab
18011843
then
18021844
qecho "Editing $fstab references from $src_part_base to $edit_fstab_name"

0 commit comments

Comments
 (0)