Raspberry Piのバックアップというと、WindowsだとWin32 Disk Imager、Macだとコマンドラインのddを使うのが定番のようです。がどちらも実用となるとなかなか難しいと思いました。Win32 Disk Imagerはコピー先のSDのサイズが少しでも小さいと”Not enough space on disk”という警告が表示され、コピーを実行できません。MacのDDはそういったエラーは出ないものの、何度試して見ても、SDはどこかが壊れているようで、起動自体ができませんでした。またイメージは圧縮しないとサイズがばかでかいです。
そこで困っていたときに見つけたのがこちら。
https://github.com/billw2/rpi-clone
正確には「SDカードのコピーツール」ではなく、システムバックアップツールです。Win32 Disk Imager やddはRaspberry Pi以外のマシン上でPiから抜いたSDをコピーするものでした。rpi-cloneはRaspberry PiのUSBポートに指されているSDカードリーサーにPiのシステムをコピーしていくというものです。
pi@raspberrypi:~ $ ./rpi-clone Error: Error opening /dev/mmcblk0: Permission denied Error: Error opening /dev/mmcblk0: Permission denied rpi-clone needs to be run as root. pi@raspberrypi:~ $ sudo ./rpi-clone usage: rpi-clone sdN {-f|--force-initialize} {-v|--verbose} {-x} Example: rpi-clone sda -v - list all files as they are copied. -f - force initialize the destination partitions -x - use set -x for very verbose bash shell script debugging Clone (rsync) a running Raspberry Pi file system to a destination SD card 'sdN' plugged into a Pi USB port (via a USB card reader). rpi-clone can clone the running system to a new SD card or can incrementally rsync to existing backup Raspberry Pi SD cards. If the destination SD card has an existing fat16 partition 1 and a ext4 partition 2, rpi-clone assumes (unless using the -f option) that the SD card 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 SD card partitions. This is done by a partial 'dd' from the running booted device /dev/mmcblk0 to the destination SD card /dev/sdN followed by a fdisk resize and mkfs.ext4 of /dev/sdN partition 2. This creates a completed fat16 partition 1 containing all boot files and an empty but properly sized partition 2 rootfs. The SD card partitions are then mounted and rsynced to the running system. The SD card destination partitions will be mounted on /mnt/clone. A log will be written to /var/log/rpi-clone.log. It's better to avoid running other disk writing programs when running rpi-clone. Version 1.4
システム権限に触れるようなのでsudoで実行します。
pi@raspberrypi:~ $ ls /dev/sda /dev/sda pi@raspberrypi:~ $ ls /dev/sdb /dev/sdb pi@raspberrypi:~ $ sudo ./rpi-clone sda -f Destination disk 'sda' does not exist. Plug the destination SD card into a card reader connected to a USB port. If it does not show up as 'sda', then do a 'cat /proc/partitions' to see where it might be.
私が使ったSDアダプタはバッファローの2口のもので指すだけで認識してくれました。Micro SDのポートはsdbだったようです。
pi@raspberrypi:~ $ sudo ./rpi-clone sdb -f Forcing a partition initialization of destination disk sdb The existing destination disk 'sdb' partitions are: Disk /dev/sdb: 7948MB Partition Table: unknown *** All data on destination disk sdb will be overwritten! *** Do you want to initialize the destination disk /dev/sdb? (yes/no): yes Imaging the partition structure, copying 75 megabytes... 75+0 records in 75+0 records out 78643200 bytes (79 MB) copied, 16.4525 s, 4.8 MB/s Running fsck on /dev/sdb1... Sizing partition 2 (root partition) to use all SD card space... mke2fs 1.42.12 (29-Aug-2014) /dev/sdb2 contains a ext4 file system last mounted on / on Thu Apr 28 22:17:02 2016 Creating filesystem with 1924096 4k blocks and 481440 inodes Filesystem UUID: e4d5505b-363e-4d25-ad24-2d830b417ecc Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done /dev/sdb is initialized and resized. Its partitions are: Disk /dev/sdb: 7948MB Partition Table: msdos Number Start End Size Type File system Flags 1 4.19MB 67.1MB 62.9MB primary fat16 lba 2 67.1MB 7948MB 7881MB primary ext4 Your booted /dev/mmcblk0p2 rootfs existing label: You may enter a label for the destination rootfs /dev/sdb2: ======== Clone Summary ======== Clone mode : rsync all files to sdb root file system Clone destination disk : sdb Clone destination rootfs : /dev/sdb2 (no label) on /mnt/clone Clone destination bootfs : /dev/sdb1 on /mnt/clone/boot Verbose mode : off =============================== Final check, is it Ok to proceed with the clone (yes/no)?: yes => Mounting /dev/sdb2 (no label) on /mnt/clone => Mounting /dev/sdb1 on /mnt/clone/boot =============================== Starting the filesystem rsync to sdb (This may take several minutes)... *** Done with clone to /dev/sdb *** Started: 22:27:33 Finished: 22:33:58 Hit Enter when ready to unmount the /dev/sdb partitions... unmounting /mnt/clone/boot unmounting /mnt/clone ===============================
途中の「You may enter a label for the destination rootfs /dev/sdb2: 」の部分が何を聞かれているのか意味が分かりませんでしたが、mayと言われているぐらいなので、とりあえず何も入力せずに進めました。
実行時間が表示されていますが、約5分ですから、ddを使う場合と比べると数分の1から10分の1ぐらいでしょうか。
焼き上がったSDをPiに挿して起動してみると、全く同じシステムが起動。元のSDより微妙にサイズの小さいSDでしたが、ちゃんと成功しています。
pi-clonerオススメです。





納得したらすぐにシェア!