Skip to content

Commit 31e571f

Browse files
committed
2.0.18 - Add -L option for ext partition labeling.
If label ends with '#', label all ext partitions and replace '#' with partition number.
1 parent 0f0e299 commit 31e571f

File tree

2 files changed

+82
-31
lines changed

2 files changed

+82
-31
lines changed

README.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,44 +114,47 @@ run rpi-clone without any arguments:
114114
pi@rpi0: $ sudo rpi-clone
115115
No destination disk given.
116116
117-
usage: rpi-clone sdN {-v|--verbose} {-f|--force-initialize} {-f2}
117+
usage: sys-clone sdN {-v|--verbose} {-f|--force-initialize} {-f2}
118118
{-u|--unattended} {-U|--Unattended} {-q|--quiet}
119-
{-s|--setup} {-e|--edit-fstab sdX }
120-
{-m|--mountdir dir } {-l|--leave-sd-usb-boot}
119+
{-s|--setup host} {-e|--edit-fstab sdX } {-m|--mountdir dir }
120+
{-L|--label-partitions label} {-l|--leave-sd-usb-boot}
121121
{-a|--all-sync} {-F|--Force-sync} {-x} {-V|--version}
122122
{--convert-fstab-to-partuuid}
123123
124-
-v - verbose rsync, list all files as they are copied.
125-
-f - force initialize the destination disk by imaging the booted disk
126-
partition structure. File systems are then synced or imaged.
127-
-f2 - force initialize only the first 2 partitions to the destination.
128-
So a multi partition USB boot can initialize clone back to
129-
a 2 partition SD card.
130-
-u - unattended clone if not initializing. No confirmations asked,
131-
but abort if disk needs initializing or on error.
124+
-v - verbose rsync, list all files as they are copied.
125+
-f - force initialize the destination disk by imaging the booted disk
126+
partition structure. File systems are then synced or imaged.
127+
-f2 - force initialize only the first 2 partitions to the destination.
128+
So a multi partition USB boot can initialize clone back to
129+
a 2 partition SD card.
130+
-u - unattended clone if not initializing. No confirmations asked,
131+
but abort if disk needs initializing or on error.
132132
-U - unattended even if initializing. No confirmations asked,
133133
but abort only on errors.
134134
-q - quiet mode, no output unless errors or initializing. Implies -u.
135135
-s host - add 'host' to args passed to script rpi-clone-setup and run it
136136
after cloning but before unmounting partitions. For setting
137-
clone disk hostname, but args can be what the script expects.
138-
You can give multiple "-s arg" options.
137+
clone disk hostname, but args can be what the script expects.
138+
You can give multiple -s arg options.
139139
-e sdX - edit destination fstab to change booted device names to new
140-
device 'sdX'. This is Only for fstabs that use device names.
140+
device 'sdX'. This is Only for fstabs that use device names.
141141
Used for setting up a USB bootable disk.
142142
-m dir - Add dir to a custom list of mounted directories to sync. Then
143143
the custom list will be synced instead of the default of all
144144
mounted directories. The root directory is always synced.
145145
Not for when initializing.
146+
-L lbl - label for ext type partitions. If ends with '#', replace with
147+
partition number and label all ext partitions. Otherwise,
148+
apply label to root partition only.
146149
-l - leave SD card to USB boot alone when cloning to SD card mmcblk0
147150
from a USB boot. This preserves a SD card to USB boot setup
148-
by leaving the SD card cmdline.txt using the USB root. When
151+
by leaving the SD card cmdline.txt using the USB root. When
149152
cloning to USB from SD card this option sets up the SD card
150153
cmdline.txt to boot to the USB disk.
151154
-a - Sync all partitions if types compatible, not just mounted ones.
152155
-F - force file system sync even if errors.
153156
If source used > destination space error, do the sync anyway.
154-
If a source partition mount error, skip it and do other syncs.
157+
If a source partition mount error, skip it and do other syncs.
155158
-x - use set -x for very verbose bash shell script debugging
156159
-V - print rpi-clone version.
157160
```

rpi-clone

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
version=2.0.17
3+
version=2.0.18
44

55
# auto run grub-install if grub detected
66
grub_auto=1
@@ -70,8 +70,8 @@ usage()
7070
echo $"
7171
usage: $PGM sdN {-v|--verbose} {-f|--force-initialize} {-f2}
7272
{-u|--unattended} {-U|--Unattended} {-q|--quiet}
73-
{-s|--setup} {-e|--edit-fstab sdX }
74-
{-m|--mountdir dir } {-l|--leave-sd-usb-boot}
73+
{-s|--setup host} {-e|--edit-fstab sdX } {-m|--mountdir dir }
74+
{-L|--label-partitions label} {-l|--leave-sd-usb-boot}
7575
{-a|--all-sync} {-F|--Force-sync} {-x} {-V|--version}
7676
{--convert-fstab-to-partuuid}
7777
@@ -97,6 +97,9 @@ usage: $PGM sdN {-v|--verbose} {-f|--force-initialize} {-f2}
9797
the custom list will be synced instead of the default of all
9898
mounted directories. The root directory is always synced.
9999
Not for when initializing.
100+
-L lbl - label for ext type partitions. If ends with '#', replace with
101+
partition number and label all ext partitions. Otherwise,
102+
apply label to root partition only.
100103
-l - leave SD card to USB boot alone when cloning to SD card mmcblk0
101104
from a USB boot. This preserves a SD card to USB boot setup
102105
by leaving the SD card cmdline.txt using the USB root. When
@@ -414,6 +417,18 @@ print_options()
414417
printf "%-22s : %s\n" "-e clone fstab edit" \
415418
"edit $src_part_base device entries to $edit_fstab_name"
416419
fi
420+
if [ "$ext_label" != "" ]
421+
then
422+
rep="${ext_label: -1}"
423+
if [ "$rep" == "#" ]
424+
then
425+
msg="all ext partition types"
426+
else
427+
msg="root partition only"
428+
fi
429+
printf "%-22s : %s\n" "-L $ext_label" \
430+
"volume label for $msg."
431+
fi
417432
if ((leave_sd_usb_boot))
418433
then
419434
if ((SD_slot_dst))
@@ -442,6 +457,28 @@ print_options()
442457
printf "%-23s:\n" "-----------------------"
443458
}
444459

460+
ext_label()
461+
{
462+
pnum=$1
463+
fs_type=$2
464+
flag=$3
465+
label_arg=""
466+
467+
if [ "$ext_label" != "" ] && [[ "$fs_type" == *"ext"* ]]
468+
then
469+
rep="${ext_label: -1}"
470+
if [ "$rep" == "#" ]
471+
then
472+
label_arg=${ext_label:: -1}
473+
label_arg="$flag $label_arg$pnum"
474+
elif ((pnum == root_part_num))
475+
then
476+
label_arg="$flag $ext_label"
477+
fi
478+
fi
479+
printf -v "${4}" "%s" "$label_arg"
480+
}
481+
445482
get_src_disk()
446483
{
447484
partition=${1#/dev/}
@@ -628,6 +665,7 @@ done
628665
#
629666
setup_args=""
630667
edit_fstab_name=""
668+
ext_label=""
631669
verbose="no"
632670

633671
force_initialize=0
@@ -718,6 +756,10 @@ do
718756
fi
719757
custom_sync=1
720758
;;
759+
-L|--label_partitions)
760+
shift
761+
ext_label=$1
762+
;;
721763
-l|--leave-sd-usb-boot)
722764
leave_sd_usb_boot=1
723765
;;
@@ -1170,11 +1212,10 @@ Use -U for unattended even if initializing.
11701212
fi
11711213
confirm "Initialize and clone to the destination disk ${dst_disk}?" "abort"
11721214

1173-
root_label=""
1174-
if ((!Unattended))
1215+
if ((!Unattended)) && [ "$ext_label" == "" ]
11751216
then
1176-
printf "Optional destination rootfs $dst_root_dev label (16 chars max): "
1177-
read root_label
1217+
printf "Optional destination ext type file system label (16 chars max): "
1218+
read ext_label
11781219
fi
11791220

11801221
start_time=`date '+%H:%M:%S'`
@@ -1282,6 +1323,11 @@ Use -U for unattended even if initializing.
12821323
printf " => fsck -p $dst_dev ..."
12831324
fsck -p $dst_dev &>> /tmp/$PGM-log
12841325
echo ""
1326+
ext_label $p $fs_type "" label
1327+
if [ "$label" != "" ]
1328+
then
1329+
e2label $dst_dev $label
1330+
fi
12851331
else
12861332
if [ "$fs_type" == "swap" ]
12871333
then
@@ -1298,9 +1344,10 @@ Use -U for unattended even if initializing.
12981344
then
12991345
fs_type="vfat -F 32"
13001346
fi
1301-
printf " => mkfs -t $fs_type $dst_dev ..."
1302-
mkfs -t "$fs_type" "$dst_dev" &>> /tmp/$PGM-output <<< "yes"
1303-
# mkfs -t "$fs_type" "$dst_dev" <<< "yes"
1347+
ext_label $p $fs_type "-L" label
1348+
printf " => mkfs -t $fs_type $label $dst_dev ..."
1349+
yes | mkfs -t "$fs_type" $label "$dst_dev" &>> /tmp/$PGM-output
1350+
# mkfs -t "$fs_type" "$dst_dev" &>> /tmp/$PGM-output <<< "yes"
13041351
echo ""
13051352
if ((p == n_image_parts))
13061353
then
@@ -1320,15 +1367,16 @@ Use -U for unattended even if initializing.
13201367
else
13211368
echo ""
13221369
fi
1370+
ext_label $p $fs_type "" label
1371+
if [ "$label" != "" ]
1372+
then
1373+
echo " e2label $dst_dev $label"
1374+
e2label $dst_dev $label
1375+
fi
13231376
fi
13241377
fi
13251378
fi
13261379
done
1327-
1328-
if [ "$root_label" != "" ]
1329-
then
1330-
e2label $dst_root_dev "$root_label"
1331-
fi
13321380
else
13331381
qecho "== SYNC $src_disk file systems to $dst_disk =="
13341382
print_sync_actions

0 commit comments

Comments
 (0)