@@ -107,22 +107,23 @@ pi@rpi0: $ sudo ./rpi-clone
107
107
No destination disk given.
108
108
109
109
usage: rpi-clone sdN {-v|--verbose} {-f|--force-initialize}
110
- {-u|--unattended} {-U|--Unattended}
110
+ {-u|--unattended} {-U|--Unattended} {-q|--quiet}
111
111
{-s|--setup} {-e|--edit-fstab name }
112
112
{-m|--mountdir dir }
113
113
{-a|--all-sync} {-F|--Force-sync} {-x} {-V|--version}
114
114
115
- -v - list all files as they are copied.
115
+ -v - verbose rsync, list all files as they are copied.
116
116
-f - force initialize the destination disk by imaging the booted disk.
117
117
-u - unattended clone if not initializing. No confirmations asked,
118
118
but abort if disk needs initializing or on error.
119
119
-U - unattended even if initializing. No confirmations asked,
120
120
but abort only on errors.
121
+ -q - quiet mode, no output unless errors or initializing. Implies -u.
121
122
-s host - add 'host' to args passed to script rpi-clone-setup and run it
122
123
after cloning but before unmounting partitions. For setting
123
124
clone disk hostname, but args can be what the script expects.
124
- -e sdX - edit fstab to change booted device names to new device 'sdX'.
125
- Only for device names . Don't use if fstab uses PARTUUID, etc .
125
+ -e sdX - edit destination fstab to change booted device names to new
126
+ device 'sdX' . This is Only for fstabs that use device names .
126
127
-m dir - Add dir to a custom list of mounted directories to sync. The
127
128
root directory is always synced. NA when initializing.
128
129
-a - Sync all partitions if types compatible, not just mounted ones.
@@ -139,17 +140,23 @@ usage: rpi-clone sdN {-v|--verbose} {-f|--force-initialize}
139
140
+ rpi-clone version 1 briefly had a -s option that is replaced with a
140
141
-s option that has different meaning.
141
142
142
- ## Raspberry Pi SD Card Booted Examples
143
- #### First clone to a new SD card
144
- The destination SD card is in a USB card reader which when plugged in to
145
- my Pi shows up as sdb because I have another USB disk sda plugged in.
146
- Look in /proc/partitions to see where yours is. The SD card does not
147
- have matching partition types, so the clone is an initialize where
148
- the source partition structure is cloned to the destination. Because
149
- the destination is smaller, the last partition will be resized down.
150
- When disks are initialized a label can be given for the
151
- destination root file system. I do that so I can keep track of
152
- my cloned cards. When you run rpi-clone, it tells you what it will do:
143
+ ## rpi-clone Example Runs
144
+ #### 1) First clone to a new SD card
145
+ In this example a new SD card in a USB card reader has been plugged in
146
+ that I want to clone to. It shows up as sdb because I have another USB
147
+ disk sda plugged in. Look in /proc/partitions to see where yours is.
148
+ The destination disk does not have partition types matching the booted disk.
149
+
150
+ + The clone will be an initialize because of partition types mismatch.
151
+ + The destination last partition will be resized down in this case because
152
+ the destination disk is smaller than the booted disk.
153
+ + rpi-clone will ask for a destination root label which I will give
154
+ so I can keep track of my clones.
155
+ + If PARTUUID is used in fstab and cmdline.txt, those files will be edited
156
+ to use the PARTUUID of the destination SD card. The SD card will
157
+ bootable when plugged in to the SD card slot.
158
+ + If fstab and cmdline.txt use device names (mmcblk0), then no edits are
159
+ necessary and the card will be bootable when plugged into a SD card slot.
153
160
```
154
161
pi@rpi0: $ sudo ./rpi-clone sdb
155
162
@@ -175,14 +182,15 @@ Optional destination rootfs /dev/sdb2 label (16 chars max): SD-RPI-8a
175
182
...
176
183
```
177
184
178
- #### Subsequent clone to the same card
179
- This is a pure sync clone because now the SD card has matching partition
180
- and file system types. Only modified files will be copied from the
181
- source disk to the destination. Also, now I want to setup the clone to
182
- have another hostname to use on another Pi, so I give the -s option.
183
- The rpi-clone-setup script will be called and it will edit /etc/hosts
184
- and /etc/hostname.
185
- ```
185
+ #### 2) Subsequent clone to the same SD card as example 1
186
+ This time the destination partition type will match the source booted
187
+ types, and I'll add a rpi-clone-setup script -s arg to set a
188
+ different destination disk hostname.
189
+
190
+ + The clone will be a pure sync where only modified files will be copied.
191
+ + The setup script will set the hostnames in the destination disk files
192
+ /etc/hostname and /etc/hosts to what I give with -s, in this case rpi2.
193
+ ```
186
194
pi@rpi0: $ sudo ./rpi-clone sdb -s rpi2
187
195
188
196
Booted disk: mmcblk0 16.0GB Destination disk: sdb 8.0GB
@@ -200,56 +208,87 @@ Verbose mode : no
200
208
-----------------------:
201
209
202
210
Ok to proceed with the clone? (yes/no):
203
- ...
204
211
```
205
- #### Clone to manually partitioned hard drive
212
+
213
+ #### 3) Creating a USB bootable disk - fstab uses device names
214
+ Assuming the destination USB flash or hard drive disk shows up as sdb
215
+ when plugged in, run the command:
216
+ ```
217
+ $ rpi-clone -e sda sdb
218
+ ```
219
+ + Destination disk "sdb" will be synced (or initialized if required).
220
+ + The "-e sda" means to edit the destination /etc/fstab to use "sda"
221
+ for the root (will be sda1) and /boot (will be sda2) lines.
222
+ Also, the destination disk /boot/cmdline.txt
223
+ will be edited to use root=/dev/sda2.
224
+ I am expecting that when the disk is plugged in for booting
225
+ to, it will be sda.
226
+ + rpi-clone will not edit the currently booted SD card cmdline.txt, so
227
+ the destination cannot be USB booted until there is a boot with a SD card
228
+ plugged in that has had its /boot/cmdline.txt edited as well. The edit
229
+ will need to set root=/dev/sda2.
230
+
231
+ Now when the Pi is booted with a SD card that has a root=/dev/sda2 in its
232
+ cmdline.txt, sda2 will be the root that is booted. The fstab there will
233
+ cause /dev/sda1 to be mounted on /boot. So, after the boot, the /boot from
234
+ the SD card that initiated the boot is not being used.
235
+
236
+ #### 4) Cloning back to a mmcblk0 SD card from a USB boot - fstab uses device names
237
+ For this example, assume the USB bootable disk created in example 3
238
+ has been booted. The SD card used to initiate the boot is no longer in use
239
+ because the booted file system has /boot mounted from /dev/sda1 as was
240
+ edited into the fstab and not /dev/mmcblk0p1.
241
+ So the SD card can be removed and another inserted that
242
+ I want to clone to. I do that and run:
243
+ ```
244
+ $ rpi-clone mmcblk0
245
+ ````
246
+ + The destination disk mmcblk0 will be synced or initialized.
247
+ + When cloning to mmcblk0, rpi-clone knows that it is an SD card
248
+ and assumes the fstab and cmdline.txt need to edited so that the
249
+ card will be bootable. So "-e mmcblk0p" is assumed and does not need
250
+ to be given in the rpi-clone command.
251
+
252
+
253
+ #### 5) Cloning a Pi3 when fstab uses PARTUUID
254
+ If fstab and cmdline.txt use PARTUUID, rpi-clone always edits
255
+ the destination fstab and cmdline.txt to use the PARTUUID of the
256
+ destination disk. So the destination is always bootable. If it
257
+ is a USB flash or hard drive it is automatically bootable on a Pi3
258
+ as a USB disk so long as the Pi3 has been USB boot enabled with
259
+ a program_usb_boot_mode=1 line in /boot/config.txt. No special
260
+ -e command line arg or SD card preparation is necessary.
261
+
262
+
263
+ #### 6) Creating a Pi3 bootable USB hard drive with extra partitions
206
264
I wanted to have a Pi3 hard drive USB boot with extra data partitions
207
265
and I want to be able to clone back to 2 partition SD cards for use
208
- in other SD card booted Pis. So my USB connected hard drive, which
209
- was showing up as sdc, was manually partitioned with partitions of
210
- the appropriate types and file systems made with mkfs.
211
-
212
- Raspbian on the Raspberry Pi needs for the first two partitions to be:
266
+ in other SD card booted Pis. So when I initially clone to the hard drive
267
+ from my booted SD card I don't want the rpi-clone run to intialize the
268
+ hard drive with the SD card partition structure.
269
+ I connected my USB hard drive and it showed up as sdc. I then
270
+ manually partitioned it with cfdisk so that it had the first two
271
+ partitions matching the partition types of the two booted SD card partitions
272
+ mmcblk0p1 and mmcblk0p2. Then I added additional partitions as I liked
273
+ and added a swap partition for possible later use since this was a
274
+ hard drive.
275
+ The requirement to make this work is getting the first two partitions
276
+ right, the sizes may be different, but the partition types have to match the
277
+ SD card and file systems must be made on the partitions. If you forget
278
+ to make file systems, rpi-clone will fail to mount the partitions.
279
+ With the Raspbian on my SD card, the first two partition requirements are:
213
280
```
214
281
Partition Type File System Type
215
282
1: type c W95 FAT32 (LBA) mkfs -t vfat /dev/sdc1
216
283
2: type 83 Linux mkfs.ext4 /dev/sdc2
217
284
```
218
285
Although the first partition file system could be mkfs -t vfat -F 32.
219
- I made the extra partitions mkfs.ext4 and I made a swap partition for
220
- possible later use (since this is a hard drive and not a flash drive).
221
- Now when rpi-clone is run it will see that the destination disk has
222
- matching types for the booted partitions 1 and 2, so it will do a
223
- sync clone without trying to initialize the destination and my extra
224
- partitions 5 and 6 will not be touched. This will be the first clone
225
- attempt to my manually partitioned disk. The partition types match so
226
- rpi-clone will go straight to a sync clone.
227
-
228
- Notes:
229
- + When manually preparing partitions like this and you make partition types
230
- match, don't forget that you must also make the matching file systems.
231
- rpi-clone won't know if you've forgotten that until it tries to mount the
232
- partitions.
233
- + What I say here applies generally, not just for manually partitioned
234
- drives. The clone to create a bootable USB disk can work without
235
- any additional steps beyond the rpi-clone run I show in
236
- this example if you are on a Pi3 that uses PARTUUID in cmdline.txt and fstab
237
- because rpi-clone automatically edits those.
238
- But if you are using device names and are setting up to have a
239
- system that SD card boots but uses a USB root, then you have to add an
240
- argument to the rpi-clone run:
241
- + Use the "-e sdX" option and rpi-clone will edit the destination
242
- /etc/fstab and /boot/cmdline.txt to reference sdX partition names
243
- instead of the SD card mmcblk0p partition names.
244
- + Once you boot your system and are running with a USB root, then the
245
- SD card slot is available and you can put a SD card into it and clone
246
- the running USB disk back to it. In that case you would
247
- run: "rpi-clone mmcblk0". If you do this, rpi-clone assumes you want
248
- to make the SD card standalone bootable and assumes "-e mmcblk0p"
249
- and you don't have to explicitly add the argument.
250
- + But rpi-clone will not edit the currently booted SD card cmdline.txt.
251
- You must do that yourself.
252
-
286
+ On the extra partitions I made ext4 file systems and ran mkswap on the
287
+ swap partition.
288
+ Now with the first two partitions set up as shown, I can run rpi-clone
289
+ on the disk and it will not try to initialize. It will sync to the
290
+ first two partitions and my extra partitions 5 and 6 will not be touched.
291
+ My rpi-clone command was simply:
253
292
```
254
293
pi@rpi0: $ sudo ./rpi-clone sdc
255
294
@@ -273,16 +312,19 @@ Verbose mode : no
273
312
274
313
Ok to proceed with the clone? (yes/no):
275
314
```
276
-
277
- ## Raspberry Pi USB Hard Drive Booted Examples
278
- Now I have booted the USB hard drive I cloned to in the example just
279
- above. I'm going to show several examples here because things get
280
- interesting with rpi-clone's flexibility.
281
-
282
- #### Routine USB disk clone to 16GB SD card
283
- For this case the Pi is booted and only the /boot partition is mounted.
284
- Nothing much to see here, I'll just type "yes" and only the /boot and
285
- root partitions will be synced.
315
+ After running this command, I powered down the Pi, removed the SD card
316
+ and powered back on into a hard drive boot. I had previously boot
317
+ enabled the Pi3.
318
+
319
+ ## Cloning from a USB booted Pi with extra partitions
320
+ Now I have booted the USB hard drive I cloned to in example 6 and will
321
+ try a few clones.
322
+
323
+ #### 7) USB disk routine clone to 16GB SD card
324
+ For this case I haven't mounted any of the extra partitions and
325
+ the Pi has only the /boot partition mounted. The kernel has seen my hard
326
+ drive as sdb but I'm using PARTUUID in fstab so there's no problem.
327
+ The card I want to clone to shows up as sda:
286
328
```
287
329
pi@rpi0: ~ $ sudo rpi-clone sda
288
330
@@ -307,9 +349,8 @@ Verbose mode : no
307
349
Ok to proceed with the clone? (yes/no):
308
350
```
309
351
310
- #### USB disk with mounted partition 5 clone to 16GB SD card
311
- Now I have one of my extra partitions mounted and happen to want to
312
- clone to a SD card for another Pi. So here's what I get:
352
+ #### 8) USB disk with mounted partition 5 clone to 16GB SD card
353
+ Now I try the clone with one of my extra partitions mounted:
313
354
```
314
355
pi@rpi0: ~ $ sudo rpi-clone sda
315
356
@@ -329,10 +370,10 @@ The destination disk is too small.
329
370
330
371
```
331
372
rpi-clone sees the mounted partition 5 and wants to clone it but finds
332
- there's not enough space on the destination drive and won't let me.
373
+ there's not enough space on the destination disk and won't let me.
333
374
A bigger disk is needed to clone all the way through partition 5.
334
375
335
- #### USB disk with mounted partition 5 clone to 16GB SD card try 2
376
+ #### 9) USB disk with mounted partition 5 clone to 16GB SD card try 2
336
377
I've got things I'm working on and don't want to unmount the partition
337
378
to make the clone work, so I use the -m option to tell rpi-clone to
338
379
only clone root and /boot and exclude any other directory mounts not given
@@ -363,55 +404,21 @@ Verbose mode : no
363
404
Ok to proceed with the clone? (yes/no):
364
405
365
406
```
407
+ And the clone to the two partition SD card is a go. But if my USB disk
408
+ root partition had used space greater than the size
409
+ of the destination partition, rpi-clone would detect that and refuse
410
+ to clone unless I were to give the -F option.
366
411
367
- #### USB disk clone to 4GB SD card
368
- I happen to have an old 4GB SD card and here's a try to clone to it:
369
- ```
370
- pi@rpi0: ~$ sudo rpi-clone sda -m /boot
371
-
372
- Booted disk: sdb 160.0GB Destination disk: sda 4.0GB
373
- ---------------------------------------------------------------------------
374
- Part Size FS Label Part Size FS Label
375
- 1 /boot 104.4MB fat16 -- 1 58.4MB fat16 --
376
- 2 root 34.4GB ext4 -- 2 3.9GB ext4 --
377
- 3 10.7GB swap --
378
- 4 114.8GB EXT --
379
- 5 /mnt/mnt 53.7GB ext4 --
380
- 6 61.1GB ext4 --
381
- ---------------------------------------------------------------------------
382
- == SYNC sdb file systems to sda ==
383
- /boot (21.5MB used) : SYNC to sda1 (58.4MB size)
384
- / (6.0GB used) : SYNC to sda2 (3.9GB size)
385
- ---------------------------------------------------------------------------
386
- Run setup script : no
387
- Verbose mode : no
388
- -----------------------:
389
- ** FATAL ** : Partition 2: source used > destination space.
390
- -----------------------:
391
-
392
- Aborting!
393
- Use -F to override used > space fail.
394
-
395
- ```
396
- So even if rpi-clone thinks that the sync won't work because of lack of
397
- space, there is a -F option which will allow the clone to proceed
398
- anyway. Maybe not a good idea, but the interesting thing about
399
- this case is that the sync will actually succeed. That's
400
- because the root used space includes an almost 2GB file system based
401
- swap file (/var/swap) that will be excluded from the sync. I haven't
402
- yet switched to using the hard disk swap partition.
403
- This is just a FYI.
404
-
405
- #### USB disk clone to large USB disk
412
+ #### 11) USB disk clone to large USB disk
406
413
If you have an extra backup hard drive, you can clone to it and back up
407
414
all of your Pi hard drive partitions. For this example I'm
408
415
plugging in a drive I happen to use for backing up my desktop,
409
416
so the partition types won't match and rpi-clone will want to do an
410
417
initialize. The part to note is that rpi-clone will tell you the
411
418
steps it will take when doing an image clone of several partitions.
412
- It will even make a swap partition on the destination. So, I'll also
413
- note that this example gives a clue if you want to try using rpi-clone
414
- on a desktop.
419
+ It will even make a swap partition on the destination if it is
420
+ an initialize clone. I'll also note that this example gives a clue
421
+ how rpi-clone would work if run on a Linux desktop.
415
422
```
416
423
pi@rpi0: ~ $ sudo rpi-clone sda
417
424
0 commit comments