Skip to content

Commit

Permalink
Support UUID in addition to PARTUUID
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
matthijskooijman committed Mar 15, 2022
1 parent 28740b4 commit 5640545
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion rpi-clone
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,12 @@ do
then
src_label[p]="$label"
fi

fsuuid=`lsblk --raw --output UUID --noheadings "${src_device[p]}"`
if [ "$fsuuid" != "" ]
then
src_fsuuid[p]="$fsuuid"
fi
done


Expand Down Expand Up @@ -1118,7 +1124,8 @@ then
SD_slot_dst=1
dst_part_base=${dst_disk}p
if [ "$edit_fstab_name" == "" ] \
&& ! grep -q "^PARTUUID=" /etc/fstab
&& ! grep -q "^PARTUUID=" /etc/fstab \
&& ! grep -q "^UUID=" /etc/fstab
then
edit_fstab_name=$dst_part_base
assumed_fstab_edit=1
Expand Down Expand Up @@ -1206,6 +1213,11 @@ do
then
dst_label[p]="$label"
fi
fsuuid=`lsblk --raw --output UUID --noheadings "${dst_device[p]}"`
if [ "$fsuuid" != "" ]
then
dst_fsuuid[p]="$fsuuid"
fi
fi
done

Expand Down Expand Up @@ -1598,9 +1610,20 @@ Use -U for unattended even if initializing.
echo ""
fi
change_label "$p" "$fs_type" "$dst_dev"
# TODO: Change uuid in case filesystem uuid is used in fstab?
fi
fi
fi

# Wait for kernel and udev to process changes (i.e. new
# UUIDs and labels)
udevadm settle
# Update UUID, just in case it changed
fsuuid=`lsblk --raw --output UUID --noheadings "$dst_dev"`
if [ "$fsuuid" != "" ]
then
dst_fsuuid[p]="$fsuuid"
fi
done
ext_label=""
else
Expand Down Expand Up @@ -1780,6 +1803,11 @@ then
then
qecho "Editing $cmdline_txt PARTUUID to use $dst_disk_ID"
sed -i "s/${src_disk_ID}/${dst_disk_ID}/" "$cmdline_txt"
elif [ "${src_fsuuid[root_part_num]}" != "" ] && grep -q "${src_fsuuid[root_part_num]}" "$cmdline_txt"
then
new_fsuuid=${dst_fsuuid[root_part_num]}
qecho "Editing $cmdline_txt UUID to use $new_fsuuid"
sed -i "s/${src_fsuuid[root_part_num]}/${new_fsuuid}/" "$cmdline_txt"
elif [ "$edit_fstab_name" != "" ] && grep -q ${src_part_base} $cmdline_txt
then
qecho "Editing $cmdline_txt references from $src_part_base to $edit_fstab_name"
Expand All @@ -1797,6 +1825,20 @@ if grep -q $src_disk_ID $fstab
then
qecho "Editing $fstab PARTUUID to use $dst_disk_ID"
sed -i "s/${src_disk_ID}/${dst_disk_ID}/g" "$fstab"
elif grep -q ^UUID= $fstab
then
for ((p = 1; p <= n_src_parts; p++))
do
old_fsuuid=${src_fsuuid[p]}
new_fsuuid=${dst_fsuuid[p]}
if [ "$old_fsuuid" == "" -o "$new_fsuuid" == "" ] || ! grep -q "$old_fsuuid" "$fstab";
then
continue
fi

qecho "Editing $fstab partition $p UUID to use $new_fsuuid"
sed -i "s/$old_fsuuid/${new_fsuuid}/" "$fstab"
done
elif [ "$edit_fstab_name" != "" ] && grep -q ${src_part_base} $fstab
then
qecho "Editing $fstab references from $src_part_base to $edit_fstab_name"
Expand Down

0 comments on commit 5640545

Please sign in to comment.