Skip to content

Commit 8b22bea

Browse files
committed
Add -p size option so first partition can be resized.
V 2.0.21 The recent Rasbian Buster release increases the /boot partition to 256M so added the -p option so a Stretch system updated to Buster can increase the destination /boot when cloning.
1 parent 033cb61 commit 8b22bea

File tree

2 files changed

+313
-142
lines changed

2 files changed

+313
-142
lines changed

README.md

Lines changed: 57 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
## rpi-clone
2+
Latest version: 2.0.21
3+
24
Version 2 is a complete rewrite with improved capability over
35
the original. See the examples below.
46

@@ -7,48 +9,32 @@ Raspberry Pi booted source disk (SD card or USB disk) to a destination
79
disk which will be bootable. Destination disks are SD cards in the SD
810
card slot or a USB card reader, USB flash disks, or USB hard drives.
911

10-
rpi-clone may work in SD card booted devices other than a
11-
Raspberry Pi because when initializing a disk, rpi-clone images a
12-
first /boot partition and boot loader setup can be captured.
13-
But this will depend on how the boot loading is handled on each device.
12+
I also use rpi-clone on my Debian desktop, but there are too many
13+
variables in how an /etc/fstab can be set up and a desktop bootloader like
14+
grub can be configured for this to be an officially supported way of
15+
using rpi-clone. See On other OS below.
1416

15-
I also am now using rpi-clone on my Debian desktop, but there are too many
16-
variables in how a /etc/fstab can be set up and a desktop bootloader like
17-
grub can be configured for this to be an officially supported way of
18-
using rpi-clone.
1917

2018
#### Clone by initialization
21-
Source disk mounted partition types are compared to
22-
corresponding destination disk partitions.
23-
If the types are not compatible, then the clone is an
24-
initialization. First, the destination partition structure is
25-
initialized to match the source disk. This is is a convenience that gets
19+
An initialization clone starts by imaging the source disk partition
20+
table to the destination disk This is is a convenience that gets
2621
the destination disk partitioned so you can avoid manual partitioning.
27-
All partitions are then cloned either
28-
by imaging source unmounted partitions to corresponding destination
29-
partitions or by doing a destination mkfs followed by a file system
30-
sync of source mounted partitions to the destination partitions.
31-
So to avoid file system inconsistencies, live partitions are synced
32-
and not imaged with one exception. If the first partition
33-
is the /boot partition, it is imaged so that bootloader install state
34-
can be preserved. This is not an issue on a Pi where the GPU knows how
35-
to boot, but could be on other systems that have a bootloader install.
36-
A mounted /boot is rarely active so its file system
37-
state should be consistent, just don't be doing anything to modify your
38-
boot configuration when running rpi-clone.
22+
Partitions are then cloned by making destination file systems matching
23+
the source file system types followed by file system syncs to the
24+
destinations. Initialization clones are used when the source file system
25+
types or number of partitions do not match the destination. An initialization
26+
clone can also be forced by command line option. An alternative to
27+
imaging the source partition table is to manually create partitions on
28+
a destination disk with file systems made to match the types in the
29+
source partitions. See example 7 below.
3930

4031
#### Clone by syncing
41-
If the file system types
42-
are compatible, the destination partitions will be mounted and the clone
43-
is a sync of modified files from source to destination. After an
44-
initialize clone, subsequent clones will be syncs. You can skip
45-
the initialize clone and go straight to a sync clone
46-
if a destination disk is manually partitioned and file
47-
systems created (mkfs) that match the mounted source partitions. In
48-
this case a destination disk does not need all partitions to match, only
49-
the mounted ones. Doing this you can have special case use of partitions on
50-
different systems. See my Pi3 example below.
51-
32+
If the source and destination disk partition file system types match,
33+
the clone does not start over with a partition table image and making of
34+
filesytems, but instead mounts destination partitions corresponding to the
35+
source and syncs the file systems. After a first clone of a disk, this
36+
operation is an incremental sync which copies only the files that have
37+
changed in the source disk and is much faster than an initilization clone.
5238

5339
## Install
5440
rpi-clone is on github and is downloaded by cloning the repository.
@@ -63,7 +49,8 @@ only Debian packages with apt-get.
6349
$ cd rpi-clone
6450
$ sudo cp rpi-clone rpi-clone-setup /usr/local/sbin
6551
```
66-
Run rpi-clone or rpi-clone-setup with no args to print usage.
52+
Make sure /usr/local/sbin is in your $PATH and then run
53+
rpi-clone or rpi-clone-setup with no args to print usage.
6754

6855
rpi-clone-setup is for setting the hostname in /etc/hostname and /etc/hosts
6956
files. It is run automatically by rpi-clone if -s args are given,
@@ -84,14 +71,17 @@ add them to the rpi-clone-setup script.
8471
$ sudo cp rpi-clone /usr/local/sbin/sys-clone
8572
$ sudo cp rpi-clone-setup /usr/local/sbin/sys-clone-setup
8673
```
87-
88-
If your other OS is a SD card booted system, it will possibly work because
89-
an initialize clone images a first /boot partition.
90-
However it currently does not work for emmc booted devices.
74+
On SD card systems other than Raspberry Pi, rpi-clone may work
75+
because an initialize clone images the sectors through the start
76+
of partition 1 to capture the partition table and possible boot loader blocks.
77+
However, unlike the Pi, a bootloader install may need to be run in
78+
the setup script.
79+
As of version 2.0.21 this may be a new requirement for some systems
80+
because rpi-clone no longer images past the end of the first partition.
9181

92-
rpi-clone does not directly support usage on a desktop OS because there
82+
rpi-clone does not directly support a traditional desktop OS because there
9383
are different possible bootloaders and while device names or PARTUUID
94-
are handled for /etc/fstab, UUID is not handled.
84+
are handled for /etc/fstab, file system UUIDs are not handled.
9585
However, it works for me and I use rpi-clone renamed as sys-clone on
9686
my Debian desktop because I use PARTUUID in my fstab and I use the grub
9787
bootloader (rpi-clone will run grub-install if it detects it installed
@@ -107,6 +97,7 @@ mount my internal drive partitions instead of the USB partitions. But
10797
I use PARTUUID so there will not be cross mounting. And I have a couple
10898
of extra grub menu entries with other root variations just in case.
10999

100+
110101
## Usage
111102
To get a usage screen showing available options,
112103
run rpi-clone without any arguments:
@@ -123,18 +114,21 @@ usage: sys-clone sdN {-v|--verbose} {-f|--force-initialize} {-f2}
123114
124115
-v - verbose rsync, list all files as they are copied.
125116
-f - force initialize the destination disk by imaging the booted disk
126-
partition structure. File systems are then synced or imaged.
117+
partition structure. File systems are then synced or imaged.
127118
-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.
119+
So a multi partition USB boot can initialize clone back to
120+
a 2 partition SD card.
121+
-p size - resize destination partition 1 to 'size' bytes. For two partition
122+
initialize (when first clone to blank disk or using -f2 or -f).
123+
Use 'sizeM' for MiB size units. eg -p 256M equals -p 268435456
130124
-u - unattended clone if not initializing. No confirmations asked,
131-
but abort if disk needs initializing or on error.
125+
but abort if disk needs initializing or on error.
132126
-U - unattended even if initializing. No confirmations asked,
133127
but abort only on errors.
134128
-q - quiet mode, no output unless errors or initializing. Implies -u.
135129
-s host - add 'host' to args passed to script rpi-clone-setup and run it
136130
after cloning but before unmounting partitions. For setting
137-
clone disk hostname, but args can be what the script expects.
131+
clone disk hostname, but args can be what the script expects.
138132
You can give multiple -s arg options.
139133
-e sdX - edit destination fstab to change booted device names to new
140134
device 'sdX'. This is Only for fstabs that use device names.
@@ -143,18 +137,18 @@ usage: sys-clone sdN {-v|--verbose} {-f|--force-initialize} {-f2}
143137
the custom list will be synced instead of the default of all
144138
mounted directories. The root directory is always synced.
145139
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.
140+
-L lbl - label for ext type partitions. If 'lbl' ends with #, replace
141+
the # with a partition number and label all ext partitions.
142+
Otherwise apply label to root partition only.
149143
-l - leave SD card to USB boot alone when cloning to SD card mmcblk0
150144
from a USB boot. This preserves a SD card to USB boot setup
151145
by leaving the SD card cmdline.txt using the USB root. When
152146
cloning to USB from SD card this option sets up the SD card
153147
cmdline.txt to boot to the USB disk.
154148
-a - Sync all partitions if types compatible, not just mounted ones.
155-
-F - force file system sync even if errors.
149+
-F - force file system sync or image for some errors. eg:
156150
If source used > destination space error, do the sync anyway.
157-
If a source partition mount error, skip it and do other syncs.
151+
If a source partition mount error, skip it and do other syncs.
158152
-x - use set -x for very verbose bash shell script debugging
159153
-V - print rpi-clone version.
160154
```
@@ -170,6 +164,15 @@ and cmdline.txt, so have a backup first.
170164
directory mounted on will not stat and the directory will not be made on the
171165
clone. You will get a readlink stat error from rsync because root can't access
172166
a users FUSE mount - only the user can.
167+
+ The examples below show a /boot partition smaller than recommended for the
168+
recent Rasbian Buster release. rpi-clone version 2.0.21 adds the -p option so
169+
the /boot partition can be resized at the same time the root partition is
170+
resized to the end of the disk. If you upgraded Stretch to Buster and are
171+
running with a small /boot, then for the clone to have a resized /boot, run:
172+
```
173+
$ rpi-clone -f -p 256M sda
174+
```
175+
173176

174177
## rpi-clone Example Runs
175178
#### 0) Examples review - a quick guide to what the examples cover in detail.
@@ -243,7 +246,7 @@ so I can keep track of my clones.
243246
to use the PARTUUID of the destination SD card. The SD card will
244247
bootable when plugged in to the SD card slot.
245248
+ If fstab and cmdline.txt use device names (mmcblk0), then rpi-clone
246-
does need to edit and the card will be bootable when plugged
249+
does need to edit the fstab and the card will be bootable when plugged
247250
into a SD card slot.
248251
```
249252
pi@rpi0: $ sudo rpi-clone sdb

0 commit comments

Comments
 (0)