@@ -5,8 +5,8 @@ the original. See the examples below.
5
5
6
6
rpi-clone is a shell script that is for cloning a running
7
7
Raspberry Pi booted source disk (SD card or USB disk) to a destination
8
- disk which will be bootable. Destination disks are SD cards in a
9
- USB card reader, USB flash disks, or USB hard drives.
8
+ disk which will be bootable. Destination disks are SD cards in the SD
9
+ card slot or a USB card reader, USB flash disks, or USB hard drives.
10
10
11
11
rpi-clone may work in SD card booted devices other than a
12
12
Raspberry Pi because when initializing a disk, rpi-clone images a
@@ -100,16 +100,16 @@ issues are handled in a setup script, then rpi-clone should work fine
100
100
creating clone backup disks for a desktop.
101
101
102
102
## Usage
103
- See the examples below. To get a usage screen showing available options,
103
+ To get a usage screen showing available options,
104
104
run rpi-clone without any arguments:
105
105
```
106
106
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
110
{-u|--unattended} {-U|--Unattended} {-q|--quiet}
111
- {-s|--setup} {-e|--edit-fstab name }
112
- {-m|--mountdir dir }
111
+ {-s|--setup} {-e|--edit-fstab sdX }
112
+ {-m|--mountdir dir } {-l|--leave-sd-usb-boot}
113
113
{-a|--all-sync} {-F|--Force-sync} {-x} {-V|--version}
114
114
115
115
-v - verbose rsync, list all files as they are copied.
@@ -126,22 +126,21 @@ usage: rpi-clone sdN {-v|--verbose} {-f|--force-initialize}
126
126
device 'sdX'. This is Only for fstabs that use device names.
127
127
-m dir - Add dir to a custom list of mounted directories to sync. The
128
128
root directory is always synced. NA when initializing.
129
+ -l - leave SD card to USB boot alone when cloning to SD card mmcblk0
130
+ from a USB boot. This preserves a SD card to USB boot setup.
129
131
-a - Sync all partitions if types compatible, not just mounted ones.
130
132
-F - force file system sync even if errors.
131
133
If source used > destination space error, do the sync anyway.
132
134
If a source partition mount error, skip it and do other syncs.
133
135
-x - use set -x for very verbose bash shell script debugging
134
136
-V - print rpi-clone version.
135
137
```
136
- + If /etc/fstab uses device names:
137
- + SD card to bootable USB flash or hard disk clones: use "-e sdX"
138
- to set up the destination fstab and cmdline.txt.
139
- + USB disk to SD card slot (mmcblk0) clones: "-e mmcblk0p" is assumed.
138
+ + See examples below for command line options usage.
140
139
+ rpi-clone version 1 briefly had a -s option that is replaced with a
141
140
-s option that has different meaning.
142
141
143
142
## rpi-clone Example Runs
144
- #### 1) First clone to a new SD card
143
+ #### 1) First clone to a new SD card in USB card reader
145
144
In this example a new SD card in a USB card reader has been plugged in
146
145
that I want to clone to. It shows up as sdb because I have another USB
147
146
disk sda plugged in. Look in /proc/partitions to see where yours is.
@@ -182,7 +181,7 @@ Optional destination rootfs /dev/sdb2 label (16 chars max): SD-RPI-8a
182
181
...
183
182
```
184
183
185
- #### 2) Subsequent clone to the same SD card as example 1
184
+ #### 2) Subsequent clone to the same SD card in USB card reader as example 1
186
185
This time the destination partition type will match the source booted
187
186
types, and I'll add a rpi-clone-setup script -s arg to set a
188
187
different destination disk hostname.
@@ -210,54 +209,113 @@ Verbose mode : no
210
209
Ok to proceed with the clone? (yes/no):
211
210
```
212
211
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
212
+ #### 3) Cloning a Pi3 when fstab uses PARTUUID
213
+ If fstab and cmdline.txt use PARTUUID as is the case in recent
214
+ Raspbian distributions, rpi-clone always edits**
255
215
the destination fstab and cmdline.txt to use the PARTUUID of the
256
216
destination disk. So the destination is always bootable. If it
257
217
is a USB flash or hard drive it is automatically bootable on a Pi3
258
218
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.
219
+ a program_usb_boot_mode=1 line in /boot/config.txt.
220
+
221
+ ** There is one exception. When using the -l option, which is used for
222
+ creating or preserving a special SD card to USB boot, the cmdline.txt
223
+ on the SD card is not edited after a clone to the SD card, see
224
+ examples 4 and 5.
225
+
226
+ #### 4) Creating a USB bootable disk for other than a USB enabled Pi3
227
+ + Warning Note: I have to consider this example experimental because
228
+ after doing it on a Pi using device names, /dev/sda1 was not mounted
229
+ on /boot after the boot completed but syslog said it did mount.
230
+ And after booting a "mount /boot" command worked so the fstab was right.
231
+ So far I don't know where the problem is.
232
+ In any case, if you do this example, check /boot after
233
+ the USB boot to make sure it was mounted. This should not affect
234
+ example 5 which works, but don't do example 5 until you are sure the
235
+ USB boot has /dev/sda1 mounted on /boot.
236
+
237
+ rpi-clone can be used to create a SD card to USB boot setup and preserve
238
+ that setup when cloning from a USB boot back to the SD card slot.
239
+ With the SD card booted and a target USB disk plugged in and assuming
240
+ the USB disk shows up as sda, the initial clone command depends on
241
+ fstab usage of device names or PARTUUID.
242
+
243
+ => Before you do this, have a backup of your booted SD card made
244
+ as in example 2 without the -l option because these steps will
245
+ change the booted SD card cmdline.txt to a USB boot.
246
+
247
+ If fstab is using PARTUUID, run:
248
+ ```
249
+ $ rpi-clone -l sda
250
+ ```
251
+ Or if fstab is using device names, run:
252
+ ```
253
+ $ rpi-clone -l -e sda sda
254
+ ```
255
+ + Destination disk "sda" will be synced or initialized if required (or add
256
+ the -f option to force initialize).
257
+ + After files are synced the destination sda fstab and cmdline.txt will
258
+ be edited to reference either device names or PARTUUID for the USB disk.
259
+ For the fstab uses device names case, the "-e sda" means to edit the
260
+ destination /etc/fstab to use "sda" for the root (will be sda1) and
261
+ /boot (will be sda2) lines. Also, the destination disk /boot/cmdline.txt
262
+ will be edited to use root=/dev/sda2. It is expected that when the USB disk
263
+ is plugged in for booting to, it will be sda and this will be a cause
264
+ of boot failure if it is not. So using PARTUUID is better because that
265
+ will reliably boot.
266
+ + The -l option causes the SD card cmdline.txt to be backed up to
267
+ cmdline.boot and the destination USB disk cmdline.txt to be copied
268
+ to the SD card. Since the USB cmdline.txt was edited to reference
269
+ the USB disk, the next Pi boot will start with the SD card
270
+ /boot partition, but will redirect to using the USB root partition.
271
+ Since the USB fstab was edited to reference the USB disk, the Pi will boot
272
+ with the USB partition 1 mounted on /boot.
273
+ The SD card /boot partition that initiated the boot process
274
+ is no longer in use but can remain in place for subsequent
275
+ SD card to USB boots. To make the SD card standalone bootable
276
+ again, its cmdline.boot can be moved back to cmdline.txt.
277
+
278
+ + If -l is not used, rpi-clone will not replace the currently booted SD card
279
+ cmdline.txt and it will need to be edited by hand for the USB boot to work.
280
+
281
+ Now when the Pi is booted from SD card to USB and the SD card is no longer
282
+ in use, the SD card slot is available for cloning to.
283
+
284
+ #### 5) Cloning back to SD cards in the SD card slot from USB boots
285
+ Whether the boot was a Pi3 straight to USB or a SD card to USB,
286
+ the SD card is not in use so it is free** to clone back to. This
287
+ creates a standalone bootable SD card:
288
+ ```
289
+ $ rpi-clone mmcblk0
290
+ ```
291
+ However, for the case where the boot was SD card to USB,
292
+ this destroys the ability of the SD card to boot to USB.
293
+ To preserve that SD to USB boot setup, run:
294
+ ```
295
+ $ rpi-clone -l mmcblk0
296
+ ```
297
+ + The SD card is cloned to as before. It now has the USB /boot/cmdline.txt.
298
+ + But the -l option prevents editing that cmdline.txt to reference the SD card.
299
+ It is left alone so that it still references the USB root partition.
300
+ So the clone has created USB disk to SD card backup while preserving
301
+ the SD card to USB boot setup. On the SD card a backup cmdline.boot
302
+ is created and edited to reference the SD card. That backup can be moved
303
+ to be cmdline.txt to make the SD card standalone bootable should
304
+ you ever want to do that.
305
+ Or you could just clone to the SD card without using -l.
306
+ + Both above mmcblk0 clone commands apply whether using PARTUUID or
307
+ device names. When using device names and cloning to SD cards,
308
+ rpi-clone knows fstab device names need editing so "-e mmcblk0p" is assumed.
309
+ Now the SD card can be left in permanently and periodically cloned to for
310
+ backups and reboots to USB will work as you want. Or other SD
311
+ cards can be inserted to create a set of backups.
312
+ If making a clone for another Pi that will be SD card bootable, don't use -l.
313
+ + ** Warning: this works if the original SD card to USB boot setup has edited
314
+ the USB /etc/fstab to reference USB partitions as is done by rpi-clone
315
+ when creating a USB bootable disk with -l. If you have an existing
316
+ SD card to USB boot setup where this was not done, then your USB boot
317
+ likely has the SD card /boot partition mounted, the SD card is in use
318
+ and using rpi-clone for a clone back to the SD card slot will not work.
261
319
262
320
263
321
#### 6) Creating a Pi3 bootable USB hard drive with extra partitions
0 commit comments