Compare commits
32 Commits
adamgoose/
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
07f536e9d9 | ||
|
|
da45b9f5de | ||
|
|
3c5d373022 | ||
|
|
7ac40602cd | ||
|
|
ed0732f5c8 | ||
|
|
8b22bea69d | ||
|
|
033cb61192 | ||
|
|
c5660ff476 | ||
|
|
82b833c7a4 | ||
|
|
fe7a646261 | ||
|
|
31e571f7e1 | ||
|
|
0f0e299e46 | ||
|
|
24f1d5f3a3 | ||
|
|
896fd9fee4 | ||
|
|
08da1feceb | ||
|
|
2a5d17fd16 | ||
|
|
41b70a47b3 | ||
|
|
dd5e4d63cf | ||
|
|
5882f69aef | ||
|
|
46c7e0fdd1 | ||
|
|
b2e494e8ac | ||
|
|
2359c3959d | ||
|
|
bffda282e0 | ||
|
|
7087dae68d | ||
|
|
2b4bacd958 | ||
|
|
927ec680d2 | ||
|
|
1597f6b7ce | ||
|
|
17849312cf | ||
|
|
7697e2cc24 | ||
|
|
d00c0d179e | ||
|
|
013d65b61e | ||
|
|
2e7ea43d1e |
29
LICENSE
Normal file
29
LICENSE
Normal file
@@ -0,0 +1,29 @@
|
||||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2018-2019, Bill Wilson
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
* Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
771
README.md
771
README.md
@@ -1,89 +1,712 @@
|
||||
## rpi-clone
|
||||
Latest version: 2.0.22
|
||||
|
||||
rpi-clone is a shell script that will back up (clone using dd and rsync)
|
||||
a running Raspberry Pi file system to a destination SD card (via a USB card
|
||||
reader) or USB disk 'sdN' plugged into a Pi USB port
|
||||
Version 2 is a complete rewrite with improved capability over
|
||||
the original. See the examples below.
|
||||
|
||||
I use it to maintain backups of several Pi SD cards I have and the destination
|
||||
backup SD cards/USB disks can be a different size (smaller or larger) than
|
||||
the booted SD card or USB disk. rpi-clone works on Raspberry Pi distributions
|
||||
which have a VFAT boot partition 1 and a Linux root partition 2. Tested on
|
||||
Raspbian but should work on other distributions which have this same two
|
||||
partition structure. rpi-clone does not work with NOOBS.
|
||||
rpi-clone is a shell script that is for cloning a running
|
||||
Raspberry Pi booted source disk (SD card or USB disk) to a destination
|
||||
disk which will be bootable. Destination disks are SD cards in the SD
|
||||
card slot or a USB card reader, USB flash disks, or USB hard drives.
|
||||
|
||||
rpi-clone can clone the running system to a new SD card/USB disk or can
|
||||
incrementally rsync to existing backup Raspberry Pi disks. During the clone
|
||||
to new disks, rpi-clone gives you the opportunity to give a label name to the
|
||||
partition 2 so you can keep track of which disks have been backed up.
|
||||
Just stick a correspondingly named sticky label on each disk you have
|
||||
and you can look up the last clone date for that backup in the rpi-clone log
|
||||
file /var/log/rpi-clone. My convention is to name 8GB SD cards:
|
||||
SD-RPI-8A, SD-RPI-8B, ...
|
||||
and similarly, 4GB cards:
|
||||
SD-RPI-4A, ...
|
||||
I also use rpi-clone on my Debian desktop, but there are too many
|
||||
variables in how an /etc/fstab can be set up and a desktop bootloader like
|
||||
grub can be configured for this to be an officially supported way of
|
||||
using rpi-clone. See On other OS below.
|
||||
|
||||
If the destination disk has an existing partition 1 and partition 2
|
||||
matching the running partition types, rpi-clone assumes (unless using the
|
||||
-f option) that the destination is an existing backup with the partitions
|
||||
properly sized and set up for a Raspberry Pi. All that is needed
|
||||
is to mount the partitions and rsync them to the running system.
|
||||
|
||||
If these partitions are not found (or -f), then rpi-clone will ask
|
||||
if it is OK to initialize the destination disk partitions.
|
||||
This is done by a partial 'dd' from the running booted device /dev/mmcblk0
|
||||
(or /dev/sd? for a USB boot) to the destination disk /dev/sdN followed by a
|
||||
fdisk resize and mkfs.ext4 of /dev/sdN partition 2. This creates a completed
|
||||
partition 1 containing all boot files and an empty but properly sized
|
||||
partition 2 rootfs. The destination partitions are then mounted on /mnt/clone
|
||||
and rsynced to the running system.
|
||||
#### Clone by initialization
|
||||
An initialization clone starts by imaging the source disk partition
|
||||
table to the destination disk This is is a convenience that gets
|
||||
the destination disk partitioned so you can avoid manual partitioning.
|
||||
Partitions are then cloned by making destination file systems matching
|
||||
the source file system types followed by file system syncs to the
|
||||
destinations. Initialization clones are used when the source file system
|
||||
types or number of partitions do not match the destination. An initialization
|
||||
clone can also be forced by command line option. An alternative to
|
||||
imaging the source partition table is to manually create partitions on
|
||||
a destination disk with file systems made to match the types in the
|
||||
source partitions. See example 7 below.
|
||||
|
||||
You should avoid running other disk writing programs when running rpi-clone,
|
||||
but I find rpi-clone works fine when I run it from a terminal window.
|
||||
However I usually do quit my browser first because a browser can be
|
||||
writing many temporary files.
|
||||
#### Clone by syncing
|
||||
If the source and destination disk partition file system types match,
|
||||
the clone does not start over with a partition table image and making of
|
||||
filesytems, but instead mounts destination partitions corresponding to the
|
||||
source and syncs the file systems. After a first clone of a disk, this
|
||||
operation is an incremental sync which copies only the files that have
|
||||
changed in the source disk and is much faster than an initilization clone.
|
||||
|
||||
rpi-clone must be run as root and you must have the rsync program installed.
|
||||
|
||||
rpi-clone will not cross filesystem boundaries by default - this is normally
|
||||
desirable. If you wish to include your mounted drive(s) in the clone,
|
||||
use the -c switch. But use this option with caution since any disk mounted
|
||||
under /mnt or /media will be included in the clone.
|
||||
|
||||
After rpi-clone is finished with the clone it pauses and asks for confirmation
|
||||
before unmounting the cloned to SD card/USB disk. This is so you can go look at
|
||||
the clone results or make any custom final adjustments if needed. For example,
|
||||
I have a couple of Raspberry Pis and I use one as a master. When I clone for
|
||||
the benefit of the second Pi, I do a "cd /mnt/clone/etc" and fix the files
|
||||
needed to customize for the second Pi (well, actually I do that with a
|
||||
script that takes my desired Pi hostname as an argument). Either way, you
|
||||
typically might need to change at least these files:
|
||||
|
||||
/etc/hostname # I have one of rpi0, rpi0, ...
|
||||
/etc/hosts # The localhost line should probably be changed
|
||||
/etc/network/interfaces # If you need to set up a static IP or alias
|
||||
|
||||
If you cd into the /mnt/clone/tree to make some of these customizations
|
||||
or just to look around, don't forget to cd out of the /mnt/clone tree
|
||||
before telling rpi-clone to unmount.
|
||||
|
||||
rpi-clone is on github, to get it and install it to /usr/local/sbin:
|
||||
Go to https://github.com/billw2/rpi-clone and download the zip file:
|
||||
|
||||
$ unzip rpi-clone-master.zip
|
||||
$ cd rpi-clone-master
|
||||
$ cp rpi-clone /usr/local/sbin
|
||||
|
||||
or, use git to clone the repository:
|
||||
## Install
|
||||
rpi-clone is on github and is downloaded by cloning the repository.
|
||||
It is a standalone script and the install is a simple copy to a
|
||||
bin directory. When run it checks its program dependencies and offers to
|
||||
install needed packages. But currently rpi-clone knows how to install
|
||||
only Debian packages with apt-get.
|
||||
|
||||
#### On a Raspberry Pi:
|
||||
```
|
||||
$ git clone https://github.com/billw2/rpi-clone.git
|
||||
$ cd rpi-clone
|
||||
$ cp rpi-clone /usr/local/sbin
|
||||
$ sudo cp rpi-clone rpi-clone-setup /usr/local/sbin
|
||||
```
|
||||
Make sure /usr/local/sbin is in your $PATH and then run
|
||||
rpi-clone or rpi-clone-setup with no args to print usage.
|
||||
|
||||
For a French translation of rpi-clone by Mehdi HAMIDA, go to:
|
||||
https://github.com/idem2lyon/rpi-clone
|
||||
rpi-clone-setup is for setting the hostname in /etc/hostname and /etc/hosts
|
||||
files. It is run automatically by rpi-clone if -s args are given,
|
||||
but before your first clone using a -s option, test run rpi-clone-setup with:
|
||||
```
|
||||
$ sudo rpi-clone-setup -t testhostname
|
||||
```
|
||||
And check the files under /tmp/clone-test to be sure the files have been
|
||||
edited correctly. If you need additional customizations to a clone,
|
||||
add them to the rpi-clone-setup script.
|
||||
|
||||
GTR2Fan on the Pi forums has instructions for putting rpi-clone into
|
||||
the menu of the desktop GUI:
|
||||
https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=137693&p=914109#p914109
|
||||
#### On other OS:
|
||||
To install on another OS, rpi-clone may be renamed to suit. For example,
|
||||
on my Debian desktop I rename:
|
||||
```
|
||||
$ git clone https://github.com/billw2/rpi-clone.git
|
||||
$ cd rpi-clone
|
||||
$ sudo cp rpi-clone /usr/local/sbin/sys-clone
|
||||
$ sudo cp rpi-clone-setup /usr/local/sbin/sys-clone-setup
|
||||
```
|
||||
On SD card systems other than Raspberry Pi, rpi-clone may work
|
||||
because an initialize clone images the sectors through the start
|
||||
of partition 1 to capture the partition table and possible boot loader blocks.
|
||||
However, unlike the Pi, a bootloader install may need to be run in
|
||||
the setup script.
|
||||
As of version 2.0.21 this may be a new requirement for some systems
|
||||
because rpi-clone no longer images past the end of the first partition.
|
||||
|
||||
rpi-clone does not directly support a traditional desktop OS because there
|
||||
are different possible bootloaders and while device names or PARTUUID
|
||||
are handled for /etc/fstab, file system UUIDs are not handled.
|
||||
However, it works for me and I use rpi-clone renamed as sys-clone on
|
||||
my Debian desktop because I use PARTUUID in my fstab and I use the grub
|
||||
bootloader (rpi-clone will run grub-install if it detects it installed
|
||||
and there is a /boot/grub directory). Using PARTUUID makes fstab
|
||||
editing simple because only a single number identifies the entire disk.
|
||||
I do have possible ambiguity in my grub menu setup because I only use
|
||||
device names in my menu entries while the fstab uses PARTUUID.
|
||||
But what actually happens is that with a root=/dev/sda2 in my grub menu
|
||||
default boot line, a USB disk will boot as sda if I have the disk plugged
|
||||
in when booting, which is what I want. Device names in fstab are a bad
|
||||
idea when doing this because the USB disk root partition could boot and then
|
||||
mount my internal drive partitions instead of the USB partitions. But
|
||||
I use PARTUUID so there will not be cross mounting. And I have a couple
|
||||
of extra grub menu entries with other root variations just in case.
|
||||
|
||||
|
||||
## Usage
|
||||
To get a usage screen showing available options,
|
||||
run rpi-clone without any arguments:
|
||||
```
|
||||
pi@rpi0: $ sudo rpi-clone
|
||||
No destination disk given.
|
||||
|
||||
usage: sys-clone sdN {-v|--verbose} {-f|--force-initialize} {-f2}
|
||||
{-u|--unattended} {-U|--Unattended} {-q|--quiet}
|
||||
{-s|--setup host} {-e|--edit-fstab sdX } {-m|--mountdir dir }
|
||||
{-L|--label-partitions label} {-l|--leave-sd-usb-boot}
|
||||
{-a|--all-sync} {-F|--Force-sync} {-x} {-V|--version}
|
||||
{--convert-fstab-to-partuuid}
|
||||
{--exclude=PATTERN} {--exclude-from=FILE}
|
||||
|
||||
-v - verbose rsync, list all files as they are copied.
|
||||
-f - force initialize the destination disk by imaging the booted disk
|
||||
partition structure. File systems are then synced or imaged.
|
||||
-f2 - force initialize only the first 2 partitions to the destination.
|
||||
So a multi partition USB boot can initialize clone back to
|
||||
a 2 partition SD card.
|
||||
-p size - resize destination partition 1 to 'size' bytes. For two partition
|
||||
initialize (when first clone to blank disk or using -f2 or -f).
|
||||
Use 'sizeM' for MiB size units. eg -p 256M equals -p 268435456
|
||||
-u - unattended clone if not initializing. No confirmations asked,
|
||||
but abort if disk needs initializing or on error.
|
||||
-U - unattended even if initializing. No confirmations asked,
|
||||
but abort only on errors.
|
||||
-q - quiet mode, no output unless errors or initializing. Implies -u.
|
||||
-s host - add 'host' to args passed to script rpi-clone-setup and run it
|
||||
after cloning but before unmounting partitions. For setting
|
||||
clone disk hostname, but args can be what the script expects.
|
||||
You can give multiple -s arg options.
|
||||
-e sdX - edit destination fstab to change booted device names to new
|
||||
device 'sdX'. This is Only for fstabs that use device names.
|
||||
Used for setting up a USB bootable disk.
|
||||
-m dir - Add dir to a custom list of mounted directories to sync. Then
|
||||
the custom list will be synced instead of the default of all
|
||||
mounted directories. The root directory is always synced.
|
||||
Not for when initializing.
|
||||
-L lbl - label for ext type partitions. If 'lbl' ends with '#', replace
|
||||
the '#' with a partition number and label all ext partitions.
|
||||
Otherwise apply label to root partition only.
|
||||
-l - leave SD card to USB boot alone when cloning to SD card mmcblk0
|
||||
from a USB boot. This preserves a SD card to USB boot setup
|
||||
by leaving the SD card cmdline.txt using the USB root. When
|
||||
cloning to USB from SD card this option sets up the SD card
|
||||
cmdline.txt to boot to the USB disk.
|
||||
-a - Sync all partitions if types compatible, not just mounted ones.
|
||||
-F - force file system sync or image for some errors. eg:
|
||||
If source used > destination space error, do the sync anyway.
|
||||
If a source partition mount error, skip it and do other syncs.
|
||||
-x - use set -x for very verbose bash shell script debugging
|
||||
-V - print rpi-clone version.
|
||||
```
|
||||
+ See examples below for usage of these command line options.
|
||||
+ rpi-clone version 1 briefly had a -s option that is replaced with a
|
||||
-s option that has different meaning.
|
||||
+ **--convert-fstab-to-partuuid** converts the booted fstab from using device
|
||||
names to PARTUUID. This is a helper if you wish to convert to PARTUUID as
|
||||
is standard in recent Raspbian distributions. After running, PARTUUID
|
||||
usage will propagate to subsequent clones. This changes the booted fstab
|
||||
and cmdline.txt, so have a backup first.
|
||||
+ FUSE mounts (ssh mounts) should be unmounted before cloning or else the
|
||||
directory mounted on will not stat and the directory will not be made on the
|
||||
clone. You will get a readlink stat error from rsync because root can't access
|
||||
a users FUSE mount - only the user can.
|
||||
+ The examples below show a /boot partition smaller than recommended for the
|
||||
recent Rasbian Buster release. rpi-clone version 2.0.21 adds the -p option so
|
||||
the /boot partition can be resized at the same time the root partition is
|
||||
resized to the end of the disk. If you upgraded Stretch to Buster and are
|
||||
running with a small /boot, then for the clone to have a resized /boot, run:
|
||||
```
|
||||
$ rpi-clone -f -p 256M sda
|
||||
```
|
||||
|
||||
|
||||
## rpi-clone Example Runs
|
||||
#### 0) Examples review - a quick guide to what the examples cover in detail.
|
||||
1. Typical two partition clones - SD card or USB disk to USB disk:
|
||||
```
|
||||
$ rpi-clone sda
|
||||
```
|
||||
2. USB boot - clone back to SD card slot:
|
||||
```
|
||||
$ rpi-clone mmcblk0
|
||||
```
|
||||
3. Clone to USB disk intended for use as a standalone Pi3 bootable
|
||||
disk. No special rpi-clone args are required.
|
||||
4. SD card to USB disk clone to create a SD card to USB boot setup:
|
||||
```
|
||||
If fstab uses PARTUUID:
|
||||
$ rpi-clone -l sda
|
||||
If fstab uses device names:
|
||||
$ rpi-clone -l sda -e sda
|
||||
```
|
||||
5. USB boot clone back to SD card slot that preserves SD card to USB boot setup:
|
||||
```
|
||||
$ rpi-clone -l mmcblk0
|
||||
```
|
||||
6. Attempted clone to a disk that is too small.
|
||||
7. Manually partition a disk with three partitions so it can
|
||||
be cloned to from a two partition boot.
|
||||
8. Clone from three partition disk to smaller disk large enough
|
||||
to hold the source three partitions.
|
||||
```
|
||||
$ rpi-clone sdb
|
||||
```
|
||||
9. Clone from three partition disk to smaller disk (sdN or mmcblk0)
|
||||
not large enough to hold the source three partitions.
|
||||
A first initialize clone forces a clone of only the first two partitions:
|
||||
```
|
||||
$ rpi-clone sdb -f2
|
||||
```
|
||||
10. Subsequent sync clones from three partition disk to two partition
|
||||
disk (sdN or mmcblk0):
|
||||
```
|
||||
If the source third partition is not mounted:
|
||||
$ rpi-clone sdb
|
||||
If the source third partition is mounted, select partitions to clone:
|
||||
$ rpi-clone sdb -m /boot
|
||||
```
|
||||
**Note** - if a larger USB disk is manually partitioned to create more than
|
||||
three partitions as in example 7, a smaller disk can be initialize
|
||||
cloned to only if it is large enough to hold at least part of the last
|
||||
source partition.
|
||||
If it is not, then the clone will have to be to a two partition -f2
|
||||
clone or a clone to a manually partitioned destination. So, for a
|
||||
multi partition disk, select partition number and sizes with a eye
|
||||
towards how you will be cloning back to smaller disks.
|
||||
11. Desktop demo
|
||||
|
||||
|
||||
#### 1) First clone to a new SD card in USB card reader
|
||||
In this example a new SD card in a USB card reader has been plugged in
|
||||
that I want to clone to, but it could also be to a USB disk or from a
|
||||
USB disk back to the SD card slot.
|
||||
In this case, the disk showed up as sdb because I have another USB
|
||||
disk sda plugged in. Look in /proc/partitions to see where yours is.
|
||||
The destination disk does not have partition types matching the booted disk.
|
||||
+ The clone will be an initialize because of partition types mismatch.
|
||||
+ The destination last partition will be resized down in this case because
|
||||
the destination disk is smaller than the booted disk.
|
||||
+ rpi-clone will ask for a destination root label which I will give
|
||||
so I can keep track of my clones.
|
||||
+ If PARTUUID is used in fstab and cmdline.txt, those files will be edited
|
||||
to use the PARTUUID of the destination SD card. The SD card will
|
||||
bootable when plugged in to the SD card slot.
|
||||
+ If fstab and cmdline.txt use device names (mmcblk0), then rpi-clone
|
||||
does need to edit the fstab and the card will be bootable when plugged
|
||||
into a SD card slot.
|
||||
```
|
||||
pi@rpi0: $ sudo rpi-clone sdb
|
||||
|
||||
Booted disk: mmcblk0 16.0GB Destination disk: sdb 8.0GB
|
||||
---------------------------------------------------------------------------
|
||||
Part Size FS Label Part Size FS Label
|
||||
1 /boot 58.4MB fat16 -- 1 8.0GB fat32 --
|
||||
2 root 16.0GB ext4 SD-RPI-s1
|
||||
---------------------------------------------------------------------------
|
||||
== Initialize: IMAGE mmcblk0 partition table to sdb - FS types mismatch ==
|
||||
1 /boot (22.5MB used) : IMAGE to sdb1 FSCK
|
||||
2 root (6.0GB used) : RESIZE(8.0GB) MKFS SYNC to sdb2
|
||||
---------------------------------------------------------------------------
|
||||
Run setup script : no
|
||||
Verbose mode : no
|
||||
-----------------------:
|
||||
** WARNING ** : All destination disk sdb data will be overwritten!
|
||||
: The partition structure will be imaged from mmcblk0.
|
||||
-----------------------:
|
||||
|
||||
Initialize and clone to the destination disk sdb? (yes/no): yes
|
||||
Optional destination rootfs /dev/sdb2 label (16 chars max): SD-RPI-8a
|
||||
...
|
||||
```
|
||||
|
||||
#### 2) Subsequent clone to the same SD card in USB card reader as example 1
|
||||
This time the destination partition type will match the source booted
|
||||
types, and I'll add a rpi-clone-setup script -s arg to set a
|
||||
different destination disk hostname.
|
||||
|
||||
+ The clone will be a pure sync where only modified files will be copied.
|
||||
+ The setup script will set the hostnames in the destination disk files
|
||||
/etc/hostname and /etc/hosts to what I give with -s, in this case rpi2.
|
||||
```
|
||||
pi@rpi0: $ sudo rpi-clone sdb -s rpi2
|
||||
|
||||
Booted disk: mmcblk0 16.0GB Destination disk: sdb 8.0GB
|
||||
---------------------------------------------------------------------------
|
||||
Part Size FS Label Part Size FS Label
|
||||
1 /boot 58.4MB fat16 -- 1 58.4MB fat16 --
|
||||
2 root 16.0GB ext4 SD-RPI-s1 2 8.0GB ext4 SD-RPI-8a
|
||||
---------------------------------------------------------------------------
|
||||
== SYNC mmcblk0 file systems to sdb ==
|
||||
/boot (22.5MB used) : SYNC to sdb1 (58.4MB size)
|
||||
/ (6.0GB used) : SYNC to sdb2 (8.0GB size)
|
||||
---------------------------------------------------------------------------
|
||||
Run setup script : rpi-clone-setup rpi2
|
||||
Verbose mode : no
|
||||
-----------------------:
|
||||
|
||||
Ok to proceed with the clone? (yes/no):
|
||||
```
|
||||
|
||||
#### 3) Cloning a Pi3 when fstab uses PARTUUID
|
||||
If fstab and cmdline.txt use PARTUUID as is the case in recent
|
||||
Raspbian distributions, rpi-clone always edits**
|
||||
the destination fstab and cmdline.txt to use the PARTUUID of the
|
||||
destination disk. So the destination is always bootable. If it
|
||||
is a USB flash or hard drive it is automatically bootable on a Pi3
|
||||
as a USB disk so long as the Pi3 has been USB boot enabled with
|
||||
a program_usb_boot_mode=1 line in /boot/config.txt.
|
||||
|
||||
** There is one exception. When using the -l option, which is used for
|
||||
creating or preserving a special SD card to USB boot, the cmdline.txt
|
||||
on the SD card is not edited after a clone to the SD card, see
|
||||
examples 4 and 5.
|
||||
|
||||
#### 4) Creating a USB bootable disk for other than a USB enabled Pi3
|
||||
rpi-clone can be used to create a SD card to USB boot setup and preserve
|
||||
that setup when cloning from a USB boot back to the SD card slot.
|
||||
With the SD card booted and a target USB disk plugged in and assuming
|
||||
the USB disk shows up as sda, the initial clone command depends on
|
||||
fstab usage of device names or PARTUUID.
|
||||
|
||||
=> Before you do this, have a backup of your booted SD card made
|
||||
as in example 2 without the -l option because these steps will
|
||||
change the booted SD card cmdline.txt to a USB boot.
|
||||
|
||||
If fstab is using PARTUUID, run:
|
||||
```
|
||||
$ rpi-clone -l sda
|
||||
```
|
||||
Or if fstab is using device names, run:
|
||||
```
|
||||
$ rpi-clone -l -e sda sda
|
||||
```
|
||||
+ Destination disk "sda" will be synced or initialized if required (or add
|
||||
the -f option to force initialize).
|
||||
+ After files are synced the destination sda fstab and cmdline.txt will
|
||||
be edited to reference either device names or PARTUUID for the USB disk.
|
||||
For the fstab uses device names case, the "-e sda" means to edit the
|
||||
destination /etc/fstab to use "sda" for the root (will be sda1) and
|
||||
/boot (will be sda2) lines. Also, the destination disk /boot/cmdline.txt
|
||||
will be edited to use root=/dev/sda2. It is expected that when the USB disk
|
||||
is plugged in for booting to, it will be sda and this will be a cause
|
||||
of boot failure if it is not. So using PARTUUID is better because that
|
||||
will reliably boot.
|
||||
+ The -l option causes the SD card cmdline.txt to be backed up to
|
||||
cmdline.boot and the destination USB disk cmdline.txt to be copied
|
||||
to the SD card. Since the USB cmdline.txt was edited to reference
|
||||
the USB disk, the next Pi boot will start with the SD card
|
||||
/boot partition, but will redirect to using the USB root partition.
|
||||
Since the USB fstab was edited to reference the USB disk, the Pi will boot
|
||||
with the USB partition 1 mounted on /boot.
|
||||
The SD card /boot partition that initiated the boot process
|
||||
is no longer in use but can remain in place for subsequent
|
||||
SD card to USB boots. To make the SD card standalone bootable
|
||||
again, its cmdline.boot can be moved back to cmdline.txt.
|
||||
|
||||
+ If -l is not used, rpi-clone will not replace the currently booted SD card
|
||||
cmdline.txt and it will need to be edited by hand for the USB boot to work.
|
||||
|
||||
+ Also a caution note if fstab uses device names: check your
|
||||
/boot to be sure it is mounted with /dev/sda1 after booting to USB.
|
||||
I have a Pi where this fails even though syslog says it mounted.
|
||||
Just be sure to check when you first do this and before you try example 5.
|
||||
|
||||
Now when the Pi is booted from SD card to USB and the SD card is no longer
|
||||
in use, the SD card slot is available for cloning to.
|
||||
|
||||
#### 5) Cloning back to SD cards in the SD card slot from USB boots
|
||||
Whether the boot was a Pi3 straight to USB or a SD card to USB,
|
||||
the SD card is not in use so it is free to clone back to. This
|
||||
creates a standalone bootable SD card:
|
||||
```
|
||||
$ rpi-clone mmcblk0
|
||||
```
|
||||
However, for the case where the boot was SD card to USB,
|
||||
this destroys the ability of the SD card to boot to USB.
|
||||
To preserve that SD to USB boot setup, run:
|
||||
```
|
||||
$ rpi-clone -l mmcblk0
|
||||
```
|
||||
+ The SD card is cloned to as before. It now has the USB /boot/cmdline.txt.
|
||||
+ But the -l option prevents editing that cmdline.txt to reference the SD card.
|
||||
It is left alone so that it still references the USB root partition.
|
||||
So the clone has created USB disk to SD card backup while preserving
|
||||
the SD card to USB boot setup. On the SD card a backup cmdline.boot
|
||||
is created and edited to reference the SD card. That backup can be moved
|
||||
to be cmdline.txt to make the SD card standalone bootable should
|
||||
you ever want to do that.
|
||||
Or you could just clone to the SD card without using -l.
|
||||
+ Both above mmcblk0 clone commands apply whether using PARTUUID or
|
||||
device names. When using device names and cloning to SD cards,
|
||||
rpi-clone knows fstab device names need editing so "-e mmcblk0p" is assumed.
|
||||
Now the SD card can be left in permanently and periodically cloned to for
|
||||
backups and reboots to USB will work as you want. Or other SD
|
||||
cards can be inserted to create a set of backups.
|
||||
If making a clone for another Pi that will be SD card bootable, don't use -l.
|
||||
+ Warning: this works if the original SD card to USB boot setup has edited
|
||||
the USB /etc/fstab to reference USB partitions as is done by rpi-clone
|
||||
when creating a USB bootable disk with -l. If you have an existing
|
||||
SD card to USB boot setup where this was not done, then your USB boot
|
||||
likely has the SD card /boot partition mounted, the SD card is in use
|
||||
and using rpi-clone for a clone back to the SD card slot will not work.
|
||||
|
||||
|
||||
#### 6) Clone to smaller 4GB SD card
|
||||
I happen to have an old 4GB SD card and here's a try to clone to it:
|
||||
```
|
||||
root@rpi2: ~$ rpi-clone sda
|
||||
|
||||
Booted disk: mmcblk0 15.8GB Destination disk: sda 4.0GB
|
||||
---------------------------------------------------------------------------
|
||||
Part Size FS Label Part Size FS Label
|
||||
1 /boot 58.4MB fat16 -- 1 58.4MB fat16 --
|
||||
2 root 15.8GB ext4 SD-RPI-16N 2 3.9GB ext4 --
|
||||
---------------------------------------------------------------------------
|
||||
== SYNC mmcblk0 file systems to sda ==
|
||||
/boot (22.5MB used) : SYNC to sda1 (58.4MB size)
|
||||
/ (5.9GB used) : SYNC to sda2 (3.9GB size)
|
||||
---------------------------------------------------------------------------
|
||||
Run setup script : no
|
||||
Verbose mode : no
|
||||
-----------------------:
|
||||
** FATAL ** : Partition 2: source used > destination space.
|
||||
-----------------------:
|
||||
|
||||
Aborting!
|
||||
Use -F to override used > space fail.
|
||||
```
|
||||
So even if rpi-clone thinks that the sync won't work because of lack of
|
||||
space, there is a -F option which will allow the clone to proceed
|
||||
anyway. The interesting thing about this case is that while this might
|
||||
seem a bad idea, the sync will actually come close to succeeding. That's
|
||||
because the root used space includes a 1.8GB file system based
|
||||
swap file (/var/swap) that will be excluded from the sync. If this
|
||||
clone is forced with -F, the card may boot, but there could be some missing
|
||||
files if the rsync runs out of space and fails to complete and some things
|
||||
would not work.
|
||||
This is just a FYI.
|
||||
|
||||
|
||||
#### 7) Clone SD card to USB disk with extra partitions
|
||||
If you have space with a larger USB disk, you can manually partition it
|
||||
with extra partitions and clone to it. If partition types and file systems
|
||||
are made to match the booted SD card, then rpi-clone will sync files and
|
||||
not try to initialize so the extra destination partitions will not be
|
||||
touched.
|
||||
|
||||
The requirement to make this work is getting the first two partition types
|
||||
and file systems right, but the sizes may be different. gparted will make
|
||||
filesystems automatically but cfdisk or fdisk will not and if
|
||||
file systems aren't made, rpi-clone will fail to mount the partitions.
|
||||
|
||||
For this example I wanted to partition a 64GB flash disk into 3 partitions
|
||||
so I could have a large third partition for data.
|
||||
I made the second root partition 16GB so I could clone this to a
|
||||
32GB disk and still have a data partition.
|
||||
|
||||
If using cfdisk or fdisk to make the partitions and then making the file
|
||||
systems, the work would be:
|
||||
```
|
||||
Partition Type Size Make File System
|
||||
1: type c W95 FAT32 (LBA) 100MiB mkfs -t vfat -F 32 /dev/sda1
|
||||
2: type 83 Linux 16GiB mkfs.ext4 /dev/sda2
|
||||
3: type 83 Linux rest of disk mkfs.ext4 /dev/sda3
|
||||
```
|
||||
But what I did was use gparted so the file systems were made for me.
|
||||
Also, in anticipation of initialize cloning back to SD cards,
|
||||
I set the first partition start to be 8192 (by setting "Free space preceding"
|
||||
to 4MiB) to match Raspbian distribution SD card images.
|
||||
Also I made partition sizes in multiples of 4MiB for SD card compatibility.
|
||||
|
||||
Now I cloned to the 64GB disk. It synced only my two booted partitions
|
||||
instead of initializing, and it left the third partition alone:
|
||||
```
|
||||
pi@rpi2: ~$ sudo rpi-clone sda
|
||||
|
||||
Booted disk: mmcblk0 15.8GB Destination disk: sda 64.2GB
|
||||
---------------------------------------------------------------------------
|
||||
Part Size FS Label Part Size FS Label
|
||||
1 /boot 58.4MB fat16 -- 1 104.4MB fat32 --
|
||||
2 root 15.8GB ext4 SD-RPI-16N 2 16.8GB ext4 Samsung 64GB A
|
||||
3 47.3GB ext4 --
|
||||
---------------------------------------------------------------------------
|
||||
== SYNC mmcblk0 file systems to sda ==
|
||||
/boot (22.5MB used) : SYNC to sda1 (104.4MB size)
|
||||
/ (5.9GB used) : SYNC to sda2 (16.8GB size)
|
||||
---------------------------------------------------------------------------
|
||||
Run setup script : no
|
||||
Verbose mode : no
|
||||
-----------------------:
|
||||
|
||||
Ok to proceed with the clone? (yes/no):
|
||||
```
|
||||
This was a boot enabled Pi3, so I simply powered down, pulled the SD
|
||||
card, and rebooted into the three partition USB disk.
|
||||
|
||||
|
||||
#### 8) Clone 64GB USB disk with extra partitions to smaller 32GB USB disk
|
||||
With the USB disk made in example 7 booted and the third partition mounted,
|
||||
this is a clone to a smaller 32GB USB disk that is still large enough
|
||||
to hold three partitions. The disk is not manually formatted so it will
|
||||
be an initialize clone. The space used in the 64GB source third partition
|
||||
fits into the size of the destination 32GB disk third partition,
|
||||
so there is no problem:
|
||||
```
|
||||
pi@rpi2: ~$ sudo rpi-clone sdb
|
||||
|
||||
Booted disk: sda 64.2GB Destination disk: sdb 31.5GB
|
||||
---------------------------------------------------------------------------
|
||||
Part Size FS Label Part Size FS Label
|
||||
1 /boot 104.4MB fat32 -- 1 31.5GB fat32 --
|
||||
2 root 16.8GB ext4 Samsung 64GB A
|
||||
3 /home/pi/media 47.3GB ext4 --
|
||||
---------------------------------------------------------------------------
|
||||
== Initialize: IMAGE sda partition table to sdb - FS types mismatch ==
|
||||
1 /boot (21.5MB used) : IMAGE to sdb1 FSCK
|
||||
2 root (5.9GB used) : MKFS SYNC to sdb2
|
||||
3 /home/pi/media (54.3MB used) : RESIZE(14.6GB) MKFS SYNC to sdb3
|
||||
---------------------------------------------------------------------------
|
||||
Run setup script : no
|
||||
Verbose mode : no
|
||||
-----------------------:
|
||||
** WARNING ** : All destination disk sdb data will be overwritten!
|
||||
: The partition structure will be imaged from sda.
|
||||
-----------------------:
|
||||
|
||||
Initialize and clone to the destination disk sdb? (yes/no):
|
||||
```
|
||||
Note that if I had partitioned the 64GB disk with more than three
|
||||
partitions it would have been more difficult to clone down to the
|
||||
32GB card. If there had been 4 partitions, then a smaller disk has
|
||||
to be large enough to image the sizes of the first three source partitions.
|
||||
If the disk is too small for that, then an initialize clone would be
|
||||
limited to a two partition clone as the next example shows. The other
|
||||
alternative would be a manual partition. The take away is that you need
|
||||
to consider how you would be cloning to smaller disks when you partition
|
||||
a larger disk for a Pi.
|
||||
|
||||
#### 9) Clone 64GB USB disk with extra partitions to new 16GB SD card
|
||||
With a USB boot, the SD card slot is available for use, so I plugged in
|
||||
a 16GB SD card to clone to:
|
||||
```
|
||||
pi@rpi2: ~$ sudo rpi-clone mmcblk0
|
||||
|
||||
Booted disk: sda 64.2GB Destination disk: mmcblk0 15.8GB
|
||||
---------------------------------------------------------------------------
|
||||
Part Size FS Label Part Size FS Label
|
||||
1 /boot 104.4MB fat32 -- 1 15.8GB fat32 --
|
||||
2 root 16.8GB ext4 Samsung 64GB A
|
||||
3 /home/pi/media 47.3GB ext4 --
|
||||
---------------------------------------------------------------------------
|
||||
Initialize required : partition - types mismatch.
|
||||
: The minimum destination disk size is 16.9GB
|
||||
: The destination disk is too small.
|
||||
: You could try a two partition -f2 clone.
|
||||
-----------------------:
|
||||
```
|
||||
This failed because there is a type mismatch that requires an initialize
|
||||
and additionally the SD card does not have the space for three partitions
|
||||
given the size of the source disk second partition. The solution is to
|
||||
tell rpi-clone to clone only the first two partitions and accept that
|
||||
this backup cannot back up the data partition. The -f2 option is just
|
||||
for going back to a two partition disk from a multi partitioned disk:
|
||||
```
|
||||
pi@rpi2: ~$ sudo rpi-clone mmcblk0 -f2
|
||||
|
||||
Booted disk: sda 64.2GB Destination disk: mmcblk0 15.8GB
|
||||
---------------------------------------------------------------------------
|
||||
Part Size FS Label Part Size FS Label
|
||||
1 /boot 104.4MB fat32 -- 1 15.8GB fat32 --
|
||||
2 root 16.8GB ext4 Samsung 64GB A
|
||||
3 /home/pi/media 47.3GB ext4 --
|
||||
---------------------------------------------------------------------------
|
||||
== Initialize: IMAGE sda partition table to mmcblk0 - forced by option ==
|
||||
1 /boot (21.5MB used) : IMAGE to mmcblk0p1 FSCK
|
||||
2 root (5.9GB used) : RESIZE(15.7GB) MKFS SYNC to mmcblk0p2
|
||||
---------------------------------------------------------------------------
|
||||
-f2 : force initialize to first two partitions only
|
||||
Run setup script : no
|
||||
Verbose mode : no
|
||||
-----------------------:
|
||||
** WARNING ** : All destination disk mmcblk0 data will be overwritten!
|
||||
: The partition structure will be imaged from sda.
|
||||
-----------------------:
|
||||
|
||||
Initialize and clone to the destination disk mmcblk0? (yes/no):
|
||||
```
|
||||
I'm using PARTUUID in /etc/fstab, but if I weren't, this clone would also
|
||||
automatically edit mmcblk0p names into the destination disk fstab.
|
||||
|
||||
|
||||
#### 10) Sync Clone 64GB USB disk with extra partitions to 16GB SD card
|
||||
With an initialize clone to the SD card done in example 8, I expect
|
||||
subsequent clones to be sync clones. But I run the rpi-clone command and
|
||||
I get an error requiring another initialize. This time the
|
||||
error is because rpi-clone wants to clone the mounted third partition and
|
||||
there is no destination third partition:
|
||||
```
|
||||
pi@rpi2: ~$ sudo rpi-clone mmcblk0
|
||||
|
||||
Booted disk: sda 64.2GB Destination disk: mmcblk0 15.8GB
|
||||
---------------------------------------------------------------------------
|
||||
Part Size FS Label Part Size FS Label
|
||||
1 /boot 104.4MB fat32 -- 1 104.4MB fat32 --
|
||||
2 root 16.8GB ext4 Samsung 64GB A 2 15.7GB ext4 SD-16c
|
||||
3 /home/pi/media 47.3GB ext4 --
|
||||
---------------------------------------------------------------------------
|
||||
Initialize required : partition 3 /home/pi/media - destination missing.
|
||||
: Unmount source partitions or use -m
|
||||
-----------------------:
|
||||
```
|
||||
But I want to sync and not do another long -f2 initialize,
|
||||
so there are two choices.
|
||||
If I unmount the third partition, the clone will sync. If I don't want
|
||||
to do that, I can tell rpi-clone to sync clone only the /boot partition
|
||||
(the root partition is included by default):
|
||||
```
|
||||
pi@rpi2: ~$ sudo rpi-clone mmcblk0 -m /boot
|
||||
|
||||
Booted disk: sda 64.2GB Destination disk: mmcblk0 15.8GB
|
||||
---------------------------------------------------------------------------
|
||||
Part Size FS Label Part Size FS Label
|
||||
1 /boot 104.4MB fat32 -- 1 104.4MB fat32 --
|
||||
2 root 16.8GB ext4 Samsung 64GB A 2 15.7GB ext4 SD-16c
|
||||
3 /home/pi/media 47.3GB ext4 --
|
||||
---------------------------------------------------------------------------
|
||||
== SYNC sda file systems to mmcblk0 ==
|
||||
/boot (21.5MB used) : SYNC to mmcblk0p1 (104.4MB size)
|
||||
/ (5.9GB used) : SYNC to mmcblk0p2 (15.7GB size)
|
||||
---------------------------------------------------------------------------
|
||||
Run setup script : no
|
||||
Verbose mode : no
|
||||
-----------------------:
|
||||
|
||||
Ok to proceed with the clone? (yes/no):
|
||||
```
|
||||
|
||||
#### 11) Clones from my Debian desktop
|
||||
Here are a couple of runs to show how rpi-clone looks handling more complex
|
||||
partitioning on my desktop. I have three primary partitions and extra
|
||||
extended partitions. I don't have a separate /boot partition but have
|
||||
a small first partition in case I want to change that.
|
||||
It probably won't work if there is a primary partition
|
||||
after an extended partition.
|
||||
```
|
||||
~$ sudo sys-clone sdb
|
||||
/usr/sbin/grub-install
|
||||
|
||||
Booted disk: sda 275.1GB Destination disk: sdb 320.1GB
|
||||
---------------------------------------------------------------------------
|
||||
Part Size FS Label Part Size FS Label
|
||||
1 1.0GB ext4 SSD-275-G6-p1 1 320.1GB -- --
|
||||
2 root 52.4GB ext4 SSD-275-G6-p2
|
||||
3 12.6GB swap --
|
||||
4 209.0GB EXT --
|
||||
5 /home 62.9GB ext4 SSD-275-G6-p5
|
||||
6 /mnt/sda 146.1GB ext4 SSD-275-G6-p6
|
||||
---------------------------------------------------------------------------
|
||||
== Initialize: IMAGE sda partition table to sdb - FS types mismatch ==
|
||||
1 : IMAGE to sdb1
|
||||
2 root (15.3GB used) : MKFS SYNC to sdb2
|
||||
3 : MKSWAP
|
||||
5 /home (12.9GB used) : MKFS SYNC to sdb5
|
||||
6 /mnt/sda (73.1GB used) : RESIZE(191.1GB) MKFS SYNC to sdb6
|
||||
---------------------------------------------------------------------------
|
||||
Run setup script : no
|
||||
Run grub : grub-install --root-directory=/mnt/clone /dev/sdb
|
||||
Verbose mode : no
|
||||
-----------------------:
|
||||
** WARNING ** : All destination disk sdb data will be overwritten!
|
||||
: The partition structure will be imaged from sda.
|
||||
-----------------------:
|
||||
|
||||
Initialize and clone to the destination disk sdb? (yes/no):
|
||||
```
|
||||
And a subsequent sync to the same disk after I have manually labeled all
|
||||
the partitions:
|
||||
```
|
||||
~$ sudo sys-clone sdb
|
||||
/usr/sbin/grub-install
|
||||
|
||||
Booted disk: sda 275.1GB Destination disk: sdb 320.1GB
|
||||
---------------------------------------------------------------------------
|
||||
Part Size FS Label Part Size FS Label
|
||||
1 1.0GB ext4 SSD-275-G6-p1 1 1.0GB ext4 Maxone-320A-p1
|
||||
2 root 52.4GB ext4 SSD-275-G6-p2 2 52.4GB ext4 Maxone-320A-p2
|
||||
3 12.6GB swap -- 3 12.6GB swap --
|
||||
4 209.0GB EXT -- 4 254.0GB EXT --
|
||||
5 /home 62.9GB ext4 SSD-275-G6-p5 5 62.9GB ext4 Maxone-320A-p5
|
||||
6 /mnt/sda 146.1GB ext4 SSD-275-G6-p6 6 191.1GB ext4 Maxone-320A-p6
|
||||
---------------------------------------------------------------------------
|
||||
== SYNC sda file systems to sdb ==
|
||||
/ (15.3GB used) : SYNC to sdb2 (52.4GB size)
|
||||
/home (12.9GB used) : SYNC to sdb5 (62.9GB size)
|
||||
/mnt/sda (73.1GB used) : SYNC to sdb6 (191.1GB size)
|
||||
---------------------------------------------------------------------------
|
||||
Run setup script : no
|
||||
Run grub : grub-install --root-directory=/mnt/clone /dev/sdb
|
||||
Verbose mode : no
|
||||
-----------------------:
|
||||
|
||||
Ok to proceed with the clone? (yes/no):
|
||||
```
|
||||
|
||||
|
||||
## Author
|
||||
Bill Wilson
|
||||
billw--at--gkrellm.net
|
||||
|
||||
144
rpi-clone-setup
Executable file
144
rpi-clone-setup
Executable file
@@ -0,0 +1,144 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Usage: rpi-clone-setup {-t|--test} hostname
|
||||
# eg: sudo rpi-clone-setup bozo
|
||||
#
|
||||
# This script is automatically run by rpi-clone (when it is given -s options)
|
||||
# to setup an alternate hostname. A cloned file system mounted on /mnt/clone
|
||||
# is expected unless testing with the -t option.
|
||||
#
|
||||
# Or, this script can be run by hand at the end of a clone when rpi-clone
|
||||
# pauses with the cloned file systems still mounted on /mnt/clone.
|
||||
#
|
||||
# Or, run this script by hand with -t to process files in test directories
|
||||
# under /tmp/clone-test. Run -t and look at the files to see if the files
|
||||
# have been edited OK.
|
||||
# eg: sudo rpi-clone-setup -t bozo
|
||||
#
|
||||
# This is a starter script that handles only /etc/hosts and /etc/hostname.
|
||||
# Make sure the script works correctly for your /etc/hosts file.
|
||||
#
|
||||
# If adding a customization for another file:
|
||||
# Add the file to file_list.
|
||||
# If needed, add a mkdir -p line to the "if ((testing))" part.
|
||||
# Add the scripting necessary to customize the file.
|
||||
# Test new scripting by running: rpi-clone-setup -t newhostname
|
||||
#
|
||||
|
||||
file_list="etc/hostname etc/hosts"
|
||||
|
||||
clone=/mnt/clone
|
||||
clone_test=/tmp/clone-test
|
||||
|
||||
PGM=`basename $0`
|
||||
|
||||
if [ `id -u` != 0 ]
|
||||
then
|
||||
echo "You must be root to run $PGM"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
function usage
|
||||
{
|
||||
echo "Usage: $PGM hostname {-t|--test}"
|
||||
echo " Eg: $PGM rpi1"
|
||||
echo " Modify files appropriate to set up for a new host."
|
||||
echo " Files handled are:"
|
||||
for file in $file_list
|
||||
do
|
||||
echo " $file"
|
||||
done
|
||||
echo ""
|
||||
echo "If testing (-t flag) files are copied and processed to $clone_test"
|
||||
echo ""
|
||||
exit 0
|
||||
}
|
||||
|
||||
testing=0
|
||||
while [ "$1" ]
|
||||
do
|
||||
case "$1" in
|
||||
-t|--test)
|
||||
testing=1
|
||||
;;
|
||||
*)
|
||||
if [ "$newhost" != "" ]
|
||||
then
|
||||
echo "Bad args"
|
||||
usage
|
||||
fi
|
||||
newhost=$1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [ "$newhost" = "" ]
|
||||
then
|
||||
echo -e "You must specify a target hostname\n"
|
||||
usage
|
||||
fi
|
||||
|
||||
echo -e "\t$newhost\t- target hostname"
|
||||
|
||||
if ((!testing)) && [ ! -d /mnt/clone/etc ]
|
||||
then
|
||||
echo "A destination clone file system is not mounted on /mnt/clone"
|
||||
echo "Aborting!"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if ((testing))
|
||||
then
|
||||
cd /tmp
|
||||
rm -rf $clone_test
|
||||
clone=$clone_test
|
||||
|
||||
mkdir -p $clone/etc
|
||||
|
||||
echo "**********************************************"
|
||||
echo "Testing setup: copying files to $clone"
|
||||
for file in $file_list
|
||||
do
|
||||
echo " cp /$file $clone/$file"
|
||||
cp /$file $clone/$file
|
||||
done
|
||||
echo "This test run will modify those files."
|
||||
echo "**********************************************"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
|
||||
##
|
||||
# Set /etc/hostname
|
||||
#
|
||||
cd $clone/etc
|
||||
echo $newhost > hostname
|
||||
#
|
||||
# Read it back to verify.
|
||||
#
|
||||
echo "$clone/etc/hostname - set new hostname: "
|
||||
LINE=`cat hostname`
|
||||
echo -e "$LINE\n"
|
||||
|
||||
|
||||
##
|
||||
# Edit /etc/hosts - edit the sed command if editing fails for your /etc/hosts.
|
||||
#
|
||||
cd $clone/etc
|
||||
sed -i s/"$HOSTNAME"/"$newhost"/ hosts
|
||||
#
|
||||
# Read it back to verify.
|
||||
#
|
||||
echo "$clone/etc/hosts - set new hostname \"$newhost\" in lines: "
|
||||
LINE=`grep $newhost hosts`
|
||||
echo -e "$LINE\n"
|
||||
|
||||
|
||||
##
|
||||
# Add more customizations if needed.
|
||||
#
|
||||
|
||||
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user