PiCake3000
Posts: 6
Joined: Mon Nov 09, 2015 12:38 am

Cloning pi sd card to a smaller one 16gb to 4gb

Sat Feb 27, 2016 10:02 am

Hello!
I used my first pi sd card with 16gb for a small project which I want to put aside now. The wheezy os and files are below 4gb. File manger says 11.3 free from 14.6gb. I want to clone (or mirror?) everything on a smaller sd card 1:1 with 4gb which I already have. There are articles which say that this is possible for example with Windows Win32 Disk Imager. How to downsize partition to fit on smaller 4gb sd cards? Do I have to do that on my pi before I backup?

Thanks

User avatar
GTR2Fan
Posts: 1601
Joined: Sun Feb 23, 2014 9:20 pm
Location: South East UK

Re: Cloning pi sd card to a smaller one 16gb to 4gb

Sat Feb 27, 2016 10:34 am

Note: Only suitable for use with plain non-NOOBS installed Raspbian.

You can use this script on a Pi to clone your current Raspbian OS SD card to any USB-connected card large enough to hold its current total occupied file space...

https://github.com/billw2/rpi-clone

Download the script, then use...

Code: Select all

sudo chmod +x rpi-clone
... to make the file executable.

Example usage...

Code: Select all

sudo ./rpi-clone sda -f -v
... where sda is the card's mount point, -f initialises a card that hasn't been previously used for cloning, and -v gives verbose reporting of the files being transferred. This exact line will always be correct if the card you want to write to is the only USB-connected writeable storage media.

You will be prompted to answer a few simple questions at the beginning of the cloning process to ensure that you're not accidentally overwriting the wrong media, then the cloning process carries on unattended until the process is complete. At the very end, you'll be asked if you want to unmount the card or leave it mounted for further inspection. Unless you plan on making any manual changes to the clone, just choose to unmount it. That's the process finished.

It's best to leave the Pi idle while the script is running to avoid as many writes to the filesystem as possible during the cloning process.

If you want to expand the clone to use all available space when copying the clone to a larger card, use the 'Expand Filesystem' option in raspi-config before doing anything else.


Optional GUI Goodness...

If you'd like to be able to launch rpi-clone from a shortcut via Menu/Accessories in the Raspbian desktop GUI, follow the instructions below.

Open a terminal and move the rpi-clone script to the usr/bin folder by typing the following from its current location...

Code: Select all

sudo mv rpi-clone /usr/bin
Now create a .desktop file at the appropriate location by typing...

Code: Select all

cd /usr/share/raspi-ui-overrides/applications
sudo nano rpi-clone.desktop
...then enter the following...

Code: Select all

[Desktop Entry]
Name=RPI-Clone
Comment=Clones the OS SD card to a USB-connected SD card of greater capacity than the total occupied file space
Icon=/usr/share/pixmaps/rpi-clone.jpg
Exec= lxterminal -e 'sudo /usr/bin/rpi-clone sda -f -v'
Type=Application
Terminal=false
Categories=Utility
Note: The "Comment=" line should all be on one line.

Now use Ctrl-X, Y, then Enter to quit the editor.

This still leaves you without a nice icon, but you're welcome to download mine from here...

https://drive.google.com/file/d/0B6DGwr ... sp=sharing

Now move the icon to the appropriate folder by typing the following from its current location...

Code: Select all

sudo mv rpi-clone.jpg /usr/share/pixmaps
That's it. Job done. Now look in Menu/Accessories and rpi-clone should be there ready for launch at the click of a mouse button whenever you need it.

Thanks and full credit go to Bill Wilson for creating and maintaining the marvellous rpi-clone script.
Pi2B Mini-PC/Media Centre: ARM=1GHz (+3), Core=500MHz, v3d=500MHz, h264=333MHz, RAM=DDR2-1200 (+6/+4/+4+schmoo). Sandisk Ultra HC-I 32GB microSD card on '50=100' OCed slot (42MB/s read) running Raspbian/KODI16, Seagate 3.5" 1.5TB HDD mass storage.

bobarry
Posts: 4
Joined: Fri Jul 15, 2016 8:08 pm

Re: Cloning pi sd card to a smaller one 16gb to 4gb

Sat Jul 23, 2016 11:30 pm

Cool idea but can't get it working.
Terminal screen blinks and that's it.
Checked it out, have no idea.
Menu item & icon are fine

Bo Barry

hwdornbush
Posts: 21
Joined: Fri Jan 20, 2017 7:08 pm

Re: Cloning pi sd card to a smaller one 16gb to 4gb

Fri Jan 20, 2017 7:15 pm

I just downloaded and started the Pixel release of Raspbian, as the instructions said to not try the script with a NOOBS version which I had. To my surprise, it includes an accessory, SD Card Copier, which does what this script does. I was able to start Pixel on a 32GB card, expand the filesystem, then copy it to a 16GB card and reboot using that card. Works perfectly.

I plan to now use HDD Raw Copy Tool to make a compressed backup of the card for saving. This utility seems to provide what Win32DiskImager does but also compresses the image.

peterlite
Posts: 720
Joined: Sun Apr 17, 2016 4:00 am

Re: Cloning pi sd card to a smaller one 16gb to 4gb

Sat Jan 21, 2017 12:01 am

You can boot a live Linux system to make changes. I suggest Linux Mint. You could also use Raspbian with USB microSD card adapters.

Gparted will shrink the Ext4 partition. There are posts about shrinking the Ext4 partition then making an image then cutting the image at 4 GB because the image is empty after the last partition.

You could also use Raspbian to make the change via plug in USB microSD card adapters. You can use the latest Raspbian to backup the microSD card to another card of the same size then use Gparted to shrink the backup then copy to another card.

Bosse_B
Posts: 776
Joined: Thu Jan 30, 2014 9:53 am

Re: Cloning pi sd card to a smaller one 16gb to 4gb

Sun Feb 12, 2017 8:30 pm

GTR2Fan wrote:Note: Only suitable for use with plain non-NOOBS installed Raspbian.

You can use this script on a Pi to clone your current Raspbian OS SD card to any USB-connected card large enough to hold its current total occupied file space...

https://github.com/billw2/rpi-clone

Download the script, then use...
I want to use this script on OSMC like I have on Raspbian in order to make a clone of the disk before I try to do a distribution upgrade..
Is this possible at all?
I already found that parted is not installed on OSMC and the rpi-clone script uses parted in several places....
So now I am worried that there may be other system commands that will not work either and might screw up the whole process...
Bo Berglund
Sweden

Return to “Advanced users”