jfail
Posts: 7
Joined: Wed Mar 05, 2014 2:29 pm
Location: Mesa, Arizona U.S.A.

Clone a USB Stick

Thu May 01, 2014 1:26 pm

I am new to the Pi and Linux. I have been using a 32Gb SD card with Raspbian for a month or so with great results.

I kept reading about SD cards eventually starting to glitch etc. I ran into a tutorial by Jason on how to move the root to a USB stick and boot from a SD card at:

http://magnatecha.com/using-a-usb-drive ... pberry-pi/

I thought I would try it out so I purchased two 32 Gb USB sticks. Jasons' tutorial was great and I got one of the 32Gb sticks working great on a powered USB hub. The dd command in Linux worked fine, it created a EXT4 file on the USB Stick (I have absolutely no idea what a EXT4 partition is!).

I decided to setup an old 4GB SD card to use for booting and operating from the newly created USB stick so I could use the 32GB card for other purposes.

I put Raspbian on the new 4Gb SD card, modified fstab and cmdline.txt as per Jasons' tutorial and all is working just fine.

My problem is I want to make a carbon copy of the newly setup USB Stick to the second one as a backup stick in case anything went wrong and I don't know how to do it. It seems to me that if I use the dd command then sdaX versus sdaX would not be correct thus the 4Gb SD card would not "see" the correct USB stick being backed up to if I tried to use it.

Does any one know of a utility that would allow me to make a clone copy from the first USB stick to the second one in case of disaster? A Windows utility would be fine for simplicity's sake, I am probably not well versed enough in Linux to use any complicated or potentially destructive Linux commands to do it. I downloaded a couple of freebie utilities but they did not recognize the USB stick that I want to backup probably because of the EXT4 partition.

I want to be able to clone the first to the second stick on a near daily basis to be sure I do not lose any of my daily work.

Thanks for any guidance.

John

User avatar
DougieLawson
Posts: 39303
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Clone a USB Stick

Thu May 01, 2014 2:20 pm

jfail wrote: It seems to me that if I use the dd command then sdaX versus sdaX would not be correct thus the 4Gb SD card would not "see" the correct USB stick being backed up to if I tried to use it.
When you plug in a USB HDD or USB stick the device appears as /dev/sda (first one) and the partitions on it appear as /dev/sda1, /dev/sda2, ... /dev/sdaN (depending how many partitions are on the device). When you plug in the second it (usually) appears as /dev/sdb (partitions /dev/sdb1 to /dev/sdbN).

dd is a byte for byte exact copy

You'd want to use
dd if=/dev/sda of=/dev/sdb bs=10M
when that is complete (and it isn't quick) both devices will be identical. You may need to pull and re-insert /dev/sdb if the partition table has changed. Use of bs=##M gives it some extra buffer space to play in and reduces the time to run to completion.

If both USB devices are always mounted then look at running them as a RAID1 array using the Linux LVM. That WILL protect you from hardware failure, it doesn't ever protect you from end-user stupidity (destroying your data with an editor or a badly constructed rm command).
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Clone a USB Stick

Thu May 01, 2014 2:33 pm

If you use a high quality SD card like the Toshiba Exceria, then corruption of the card does no occur. I have one Rpi that gets turned on and off at least daily and it has been in operation for about a year without issues. I have had cheap SD cards fail but never an Exceria.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

jfail
Posts: 7
Joined: Wed Mar 05, 2014 2:29 pm
Location: Mesa, Arizona U.S.A.

Re: Clone a USB Stick

Thu May 01, 2014 2:33 pm

Thanks Doug. A very informative response. I thought the dd command would work but I was hesitant to try it due to my inexperience with it and did not want to make a serious mistake.

I will try it out this morning. One last question, will the dd command overwrite any previous backup on the second stick without me having to reformat or at least having to manually erase the previous backup on the second stick prior to using the dd command to clone the first one?

Thanks again, I see where you help lots of people here on the forum and I am sure all of us appreciate your help and guidance.

John

User avatar
rpdom
Posts: 17275
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Clone a USB Stick

Thu May 01, 2014 3:06 pm

Yes, dd will overwrite anything on the stick and make it an exact copy of the original.

The only thing you have to check is the sizes of the sticks. Sometimes 32GB on one stick is a little bigger or smaller than 32GB on another stick. If the second stick is larger then you have no problem (just a little wasted space). If it is smaller then the copy may not fit.

jfail
Posts: 7
Joined: Wed Mar 05, 2014 2:29 pm
Location: Mesa, Arizona U.S.A.

Re: Clone a USB Stick

Thu May 01, 2014 8:46 pm

My thanks to everyone for the guidance.

It worked perfectly although I was surprised how long it took (3 hours).

I had to make one adjustment to the suggested:

dd if=/dev/sda of=/dev/sdb bs=10M

My original stick (#1) did not show up as sdX device but the #2 (the one I am backing up to) did show up as sdb1 so I used:

dd if=/dev/root of=/dev/sdb1 bs=10M

Everything is working great and I feel better about having a backup. Thanks again to all.

User avatar
DougieLawson
Posts: 39303
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Clone a USB Stick

Thu May 01, 2014 9:11 pm

If you use /dev/sdb# (with a partition number) you have to be sure the partition table is correct (correct starting sector, correct number of sectors, same size as the /dev/root you're copying) before you start. In terms of data content copying partition #1 from one device to partition #1 is no problem. Copying partition #1 to partition #2 has the scope to screw things up (unless you go through and correct all references to #1).

If you use dd to copy the whole device all you have to be sure is that you're not trying to squash 8GB of data into a card that only has 7.5GB of available space (dd takes no prisoners). But you can ignore partition numbers as the partition table is the first thing to get copied.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Return to “Beginners”