返回列表 發帖

Raspberry Pi —— SD card backup/copy/clone

本帖最後由 角色 於 2019-2-11 00:17 編輯

早期的Raspberry Pi没有这个功能,现在到2018 Nov版本,Desktop版本已经有这个SD card copier功能。要实现这个功能,你需要一个Raspberry Pi,两个USB card readers,把要clone的卡,放入Reader 1,把要backup的卡放入Reader 2,然后Raspbian Desktop version,打开里面的SD Card Copier软件,按软件操作就可以。这个copier软件,不需要要求两个SD card同一个size,只要能放下original system的文件就可以,这个意思就是如有的16G SD card,文件只有3G,那么你用4G的SD card就可以。想起以前真的非常麻烦。

但是怎样把SD card backup到一个文件,然后从这个文件再restore到一张昕的SD card里?

安装script
  1. wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh
  2. chmod +x pishrink.sh
  3. sudo mv pishrink.sh /usr/local/bin
複製代碼
.

然后
  1. dd bs=4M if=/dev/sda of=/mnt/qnap/sd_card_images/2018_Nov/rpi_desktop.img status=progress
複製代碼
,因为的Raspberry Pi的SD card空间太少,我用nfs去我的NAS,方便收藏。
if = input file的路径,/dev/sda,我的sda,你们的时候,用df command看。
of = output file的路径,就是output file放哪里。

通过pishrink.sh把之前16G的image压缩到最小,大约是3.5G。
  1. pishrink.sh /mnt/qnap/sd_card_images/2018_Nov/rpi_desktop.img
複製代碼
.

zip the file rpi_desktop.img, 变成rpi_desktop.zip
  1. zip rpi_desktop.zip rpi_desktop.img
複製代碼
.

本帖最後由 角色 於 2019-2-8 20:23 編輯

如果backup SD card to a file for distribution。

【1】给出一个工具,能把img变小。【1】的产生基建于【2】,都是通过作者,只不过很多人,所以他做一个script【1】,把很多在【2】都自动化了。除了工具【1】,还有一个PiShrink【2】,PiShrink【2】比shrink【1】更加简单。在【4】里某个帖子提及到
  1. sudo dd bs=4M if=/dev/sdc of=/media/pi/ExtHDD3/sd_card_images/temp.img status=progress
  2. cd /media/pi/ExtHDD3/sd_card_images/
  3. sudo /home/pi/PiShrink/pishrink.sh temp.img my_raspbian_stretch.img
複製代碼
.
其实很多信息都能在【4】找到。上面的sdc要根据你的情况有所更改。在【5,6】还能找在不同系统的方法。

References:
【1】https://github.com/qrti/shrink
【2】http://www.aoakley.com/articles/2015-10-09-resizing-sd-images.php
【3】PiShrink https://github.com/Drewsif/PiShrink
【4】https://www.raspberrypi.org/forums/viewtopic.php?t=145712
【5】https://thepihut.com/blogs/raspb ... spberry-pis-sd-card
【6】https://www.osradar.com/backup-restore-your-raspberry-pi-system/

TOP

本帖最後由 角色 於 2019-2-10 13:29 編輯

上面压缩的指令非常好用!为什么我这样说呢?

我有一个Raspbian系统放在32的USB drive (但是所有文件只有大约3.5G),如果Raspberry Pi不插SD card,斋用USB drive是可以启动,我们目标是怎样放入一张4G的卡里?

我们有两个方法。

第一种方法就是用一张有Raspbian最新版的Desktop系统,里面有SD Card Copier,如果你知道文件size不超过4G的话,那么可以在Raspbian Desktop里直接Copy。

但是如果要把文件copy给千里以外的member,那么没有必要把Desktop Raspbian copy出来的SD card快递给member吧!是否有别的方法呢?

第二种方法就是我们可以利用上面的方法,就是通过上面dd command把SD card的文件拷到一个文件(first.img),然后把这个first.img,过关pishrink.sh这个script把比较大的first.img变下,成为second.img。例如文件first.img有32G大变成小的second.img,它的size只有3.5G,变小很多,但是大家也可以直接把second.img发给朋友。但是我们通过压缩技术,把second.img再压缩,成为second.zip,它的size大约1G,那么你就可以把1G发送给朋友。朋友可以Etcher(Windows和MacOS版本),把second.img直接放入4G,8G,16G的sd card都可以。

你的朋友做好的SD card,放入自己的Raspbian Pi系统,启动电源,系统会自动expand Raspbian到你的SD card size,你不需要再运行expand指令(通过raspi-config).

还有我也尝试直径把first.img压缩,变为大约1.5G的文件,但是通过上面Etcher软件,同样用4G的卡,Etcher马上提示插入的SD card memory size太小,放不下,估计要插入32G或者更加大的卡才能烧录。

TOP

做得用下面的方法更加方便使用
  1. wget https://raw.githubusercontent.com/Drewsif/PiShrink/master/pishrink.sh
  2. chmod +x pishrink.sh
  3. sudo mv pishrink.sh /usr/local/bin
複製代碼

TOP

本帖最後由 角色 於 2019-2-16 20:09 編輯

如果要restore from image file to sd card,那么记住要umount sd card device or mount point,然后用dd command就可以。

Copy file (shrinked  file) to a sd card
  1. dd bs=4M of=/dev/sda if=/mnt/rpi.img status=progress
複製代碼
,

where /dev/sda may be changed to other values such /dev/sdb if necessary and the location of input file path may be also changed to other string.

TOP

不错的软件。我用的方法都是单个OS的方法,需要SD card memory size不需要太大,而你的方法,因为要保存多个VMs,估计要SD card memory size大一点。如果经常测试不同的OS,用你提议的方法是非常方便。

不知道你的SD card memory size需要多呢? 16G? 32G?

TOP

返回列表