dsyleixa123
Posts: 1117
Joined: Mon Jun 11, 2018 11:22 am

how to clone a 32 GB SD card (non-GUI Stretch) to a 16GB SD?

Fri Sep 06, 2019 6:02 pm

how to clone a 32 GB SD card (non-GUI Stretch) to a 16GB SD?
All available partitions have to be cloned.
(I actually don't know how many partions the source SD has, it's a retropie SD.)

fruitoftheloom
Posts: 25156
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: how to clone a 32 GB SD card (non-GUI Stretch) to a 16GB SD?

Fri Sep 06, 2019 6:06 pm

dsyleixa123 wrote:
Fri Sep 06, 2019 6:02 pm
how to clone a 32 GB SD card (non-GUI Stretch) to a 16GB SD?
All available partitions have to be cloned.
(I actually don't know how many partions the source SD has, it's a retropie SD.)

https://github.com/billw2/rpi-clone
The information is out there....you just have to let it in.

dsyleixa123
Posts: 1117
Joined: Mon Jun 11, 2018 11:22 am

Re: how to clone a 32 GB SD card (non-GUI Stretch) to a 16GB SD?

Sat Sep 07, 2019 7:40 am

thank you, but I'm a beginner to Linux and I don't understand all the options and the names of either devices.
which would be the terminal command to copy 1:1 all current SD Stretch partitions partitions incl FAT and Boot and whatever (no matter how many actually exist, perhaps 2,3,4, or 5) to a fresh formatted, fresh inserted SD card in a USB card reader?

dsyleixa123
Posts: 1117
Joined: Mon Jun 11, 2018 11:22 am

Re: how to clone a 32 GB SD card (non-GUI Stretch) to a 16GB SD?

Sat Sep 07, 2019 4:52 pm

e.g. I tried

sudo rpi-clone sdb

but then I get the error "sdb not found in the partition table" plus a list of about a dozen weird names.

- no idea which would be the correct command instead.

fruitoftheloom
Posts: 25156
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: how to clone a 32 GB SD card (non-GUI Stretch) to a 16GB SD?

Sat Sep 07, 2019 4:56 pm

dsyleixa123 wrote:
Sat Sep 07, 2019 4:52 pm
e.g. I tried

sudo rpi-clone sdb

but then I get the error "sdb not found in the partition table" plus a list of about a dozen weird names.

- no idea which would be the correct command instead.

The developer supports his software:

https://github.com/billw2/rpi-clone/blo ... /README.md
The information is out there....you just have to let it in.

dsyleixa123
Posts: 1117
Joined: Mon Jun 11, 2018 11:22 am

Re: how to clone a 32 GB SD card (non-GUI Stretch) to a 16GB SD?

Sat Sep 07, 2019 5:12 pm

yes, I read the .md things, and what I took
sudo rpi-clone sdb
was actually what he himself suggested (CMIIW)!
8. Clone from three partition disk to smaller disk large enough to hold the source three partitions.

$ rpi-clone sdb
but tbh, I have no idea if my SD has 2,3,4,5, or any other partitions and how they are called (sources or targets).
I actually want to copy the SD as simple as the Stretch GUI copy tool (GUI desktop menu bar) does, but now having a non-GUI Stretch.

oksage
Posts: 18
Joined: Fri Dec 01, 2017 6:44 am

Re: how to clone a 32 GB SD card (non-GUI Stretch) to a 16GB SD?

Sat Sep 07, 2019 6:52 pm

So you need to do this from a command line because you don't have a gui? To list your partitions, use

Code: Select all

lsblk
or

Code: Select all

sudo fdisk -l
This will show you how many partitions.

One way of shrinking a clone is to copy the sd card to an image file and then shrink the file. You can do that by swapping the source and target from the command on this page:
https://www.raspberrypi.org/documentati ... s/linux.md
to get

Code: Select all

dd bs=4M if=/dev/sdX of=~/"$(date -I)"-raspbian.img conv=fsync
"$(date -I)" is a command-line substitution that puts the date (yyyy-mm-dd) in the image name.

Please note that block size set to 4M will work most of the time. If not, try 1M, although this will take considerably longer.
Also note that if you are not logged in as root you will need to prefix this with sudo.

One you have the image, you can shrink it. Adafruit has a script for doing this:
https://learn.adafruit.com/resizing-ras ... ing-images
You can use the script or look at the lines of the script to see the commands they used.

Or you can look at this page for a detailed guide:
https://raspberrypi.stackexchange.com/q ... er-sd-card

dsyleixa123
Posts: 1117
Joined: Mon Jun 11, 2018 11:22 am

Re: how to clone a 32 GB SD card (non-GUI Stretch) to a 16GB SD?

Sat Sep 07, 2019 6:55 pm

thanks, but that entire thing is far too complicated, I need a simple SD copy tool both for equal and also for variant SD sizes, like the GUI SD copy tool, suitable for all sizes and all partition numbers.

Which would be the correct rpi-clone command?

oksage
Posts: 18
Joined: Fri Dec 01, 2017 6:44 am

Re: how to clone a 32 GB SD card (non-GUI Stretch) to a 16GB SD?

Sat Sep 07, 2019 7:22 pm

dsyleixa123 wrote:
Sat Sep 07, 2019 6:55 pm
thanks, but that entire thing is far too complicated, I need a simple SD copy tool both for equal and also for variant SD sizes, like the GUI SD copy tool, suitable for all sizes and all partition numbers.

Which would be the correct rpi-clone command?
I've never used rpi-clone. If you do a quick search for it, you'll find instructions.
I found this page:
http://bobbyromeo.com/technology/backup ... i-sd-card/
where it says:
3. File based copy (live option)

A third and final option is using Rsync to perform a file based copy.

rsync is a widely-used utility to keep copies of a file on two computer systems the same. It is commonly found on Unix-like systems and functions as both a file synchronization and file transfer program

The good news here is that your don’t need to understand too much about the rsync command as many scripting geniuses out there have done the dirty work for us. I wholeheartedly suggest using a script called rpi-clone to make your backup. The script is run on a live Raspberry Pi system which sets it apart from the previous two methods I just described. You’ll once again need a USB Card reader, this time directly connected to your Raspberry Pi.
Advantages

Easy as Pi (sorry, that was lame…)
Can restore directly to an SD Card
Can restore to any size SD Card
Can provide incremental backups

Disadvantages

Runs on a Raspberry Pi live system
Problematic when running other disk writing programs or applications

Steps

To install, login to your Raspberry Pi via a terminal. 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:

git clone https://github.com/billw2/rpi-clone.git
cd rpi-clone
cp rpi-clone /usr/local/sbin

Next, put your new SD Card into the USB card reader and connect it to the Raspberry Pi. Determine the Linux device of the destination SD card (refer to method 1. for Linux), hint: it’s usually sda. Now issue the command as root and sit back and watch files fly by your terminal in awe…

sudo rpi-clone sda -v -x
But if you read the README at the rpi-clone github page, it describes how to do an initialization clone and there is info on cloning to smaller sdcards. It says
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.
So I'm not sure that rpi-clone is really meant for cloning to smaller sdcards. I'd try the adafruit script (mentioned above) or the complicated instructions at the stackexchange link.
Last edited by oksage on Sat Sep 07, 2019 7:33 pm, edited 1 time in total.

dsyleixa123
Posts: 1117
Joined: Mon Jun 11, 2018 11:22 am

Re: how to clone a 32 GB SD card (non-GUI Stretch) to a 16GB SD?

Sat Sep 07, 2019 7:30 pm

yes, as stated I've already installed rpi-clone.
nonetheless, the correct usage for my purposes is beyond me (as stated, too)
the parameter sdb is not accepted strangely.

(see above)
dsyleixa123 wrote:
Sat Sep 07, 2019 4:52 pm
e.g. I tried

sudo rpi-clone sdb

but then I get the error "sdb not found in the partition table" plus a list of about a dozen weird names.

- no idea which would be the correct command instead.

oksage
Posts: 18
Joined: Fri Dec 01, 2017 6:44 am

Re: how to clone a 32 GB SD card (non-GUI Stretch) to a 16GB SD?

Sat Sep 07, 2019 7:40 pm

So you've used lsblk to list the disk/partition names? And sdb is the device name of your pI?

dsyleixa123
Posts: 1117
Joined: Mon Jun 11, 2018 11:22 am

Re: how to clone a 32 GB SD card (non-GUI Stretch) to a 16GB SD?

Sat Sep 07, 2019 7:48 pm

yes, it shows 2 different SDs

sda
|-> sda1

and another weird one (assumably the boot SD) with unpronouncable and unmemorable names like
lhdkufh
|-> ikjh
|-> zfss

I now arbitrarily took sda as a parameter (opposite to what the author wrote)

Code: Select all

sudo rpi-clone sda
and it had worked, probably.
Strangely.
Surprisingly.


Non-GUI Linux is really an unbearable, outrageous and unconscionable agony for common PC users ( an outrageous sea of troubles, Skakespeare would probably say.... ) :evil:

oksage
Posts: 18
Joined: Fri Dec 01, 2017 6:44 am

Re: how to clone a 32 GB SD card (non-GUI Stretch) to a 16GB SD?

Sat Sep 07, 2019 7:57 pm

Looks like your storage device is sda, same as found here:
https://www.uberbuilder.com/using-rpi-clone/

That page also describes how to restore.
Cheers.

dsyleixa123
Posts: 1117
Joined: Mon Jun 11, 2018 11:22 am

Re: how to clone a 32 GB SD card (non-GUI Stretch) to a 16GB SD?

Sat Sep 07, 2019 8:12 pm

thanks!
yes, sda seemed to work to a 32GB SD (the intended 16GB SD is still in use at another Pi).
- but in the manual the author wrote sdb instead
- and I still don't know the exact parameters for either multiple partitions >=2 to smaller target SDs which is supposed to work out of the box.
Very weird and puzzling, tbh.

Return to “Beginners”