LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-09-2016, 08:10 AM   #1
PreguntoYo
Member
 
Registered: Jan 2012
Distribution: openSUSE, Gentoo, Slackware
Posts: 73

Rep: Reputation: 15
Cloning a USB with dd


Hello:

After upgrading to Windows 8.1 in a laptop (I'm forced to use Windows because it is the SO in my job), I was asked to plug in a USB stick (16 GB at least) where a re-install copy of the SO would be backup.

Now this same laptop is asking to upgrade to Windows 10 (which the sooner or later, will be the SO in my job, too), and I'd prefer that the ONLY copy that I have of my SO (AFAIK you can't download again your copy of Windows 8.1 from Microsoft) would be backup to a safer medium, like one HD of mine.

I used a reliable USB stick for my copy, but it has been stored in a drawer for more than a year. If the thing could fail, I better try to copy it once. Also, being a proprietary software, I bet something could fail if I later try to restore the USB image in another USB. I need to clone the USB, dd is the command I should use (I think).

Of course I've read http://www.linuxquestions.org/questi...ommand-362506/ but dd is also a risky command if used carelessly, and in order to dispel all uncertainty...:

Code:
dd if=/dev/sdb of=/home/preguntoyo/W8.1_USB_CLONE.dd bs=4096 conv=notrunc
Will this work?. I thought copying the FULL USB stick to a file image would be the best solution. But for the dd options, I'm a little lost;

Why people place a bs option?. Can't the job be done in a single read-to-memory write-to-hd fashion? (BTW: I don't have 16 GB RAM, I have 8 GB. Just wondering what if I had more RAM, or if the ram I have could help in this..).

And why bs=512,4096...?. My HD has 4k blocks, but 64 MB cache memory. Why not read and write in 64 MB chunks?. Or in the whatever sector size of the USB?.

Why the notrunc option?. Why would dd truncate the of?. How would this work anyway if the of would be of less size than the if?. dd checks if vs of size in any way?.

Would you place any else options?.

And yes, I've read the man page, and I have found it explanatory, but it seems aimed at a more... "technified" audience.
 
Old 01-09-2016, 08:32 AM   #2
gacanepa
Member
 
Registered: May 2012
Location: San Luis, Argentina
Distribution: Debian
Posts: 205

Rep: Reputation: 27
Please check the accepted answer in this thread. As you can see, you don't actually need to use the bs option.
That said, have you check OSFClone? It's a FOSS utility that can get the job done without hassle.
Hope it helps!
 
Old 01-09-2016, 02:39 PM   #3
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by PreguntoYo View Post
Code:
dd if=/dev/sdb of=/home/preguntoyo/W8.1_USB_CLONE.dd bs=4096 conv=notrunc
Will this work?
it would be best if sdb is not in use (no partition mounted) during this operation. obviously the of= must not be on sdb.
is sdb another external storage, or is it an internal hard drive?
 
Old 01-09-2016, 03:08 PM   #4
cold.caller
LQ Newbie
 
Registered: Jan 2016
Posts: 3

Rep: Reputation: Disabled
To insure a correct device to dd an image to, I would use dmesg and grep to get the actual block device.

First, plug in your USB stick and then type the code below in a terminal.

Code:
dmesg | grep 'logical blocks'
Here is my output.
Quote:
[ 0.000000] sd 0:0:0:0: [sda] 62533296 512-byte logical blocks: (32.0 GB/29.8 GiB)
[ 0.000000] sd 2:0:0:0: [sdb] 1953525168 512-byte logical blocks: (1.00 TB/931 GiB)
[ 0.000000] sd 6:0:0:0: [sdc] 15278080 512-byte logical blocks: (7.82 GB/7.28 GiB)
In the last line, my 8GB USB stick is identify as sdc by the logical block size of (7.82 GB/7.28 GiB)

-cheers

Last edited by cold.caller; 01-09-2016 at 03:11 PM.
 
Old 01-09-2016, 07:55 PM   #5
sgosnell
Senior Member
 
Registered: Jan 2008
Location: Baja Oklahoma
Distribution: Debian Stable and Unstable
Posts: 1,943

Rep: Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542
There are a number of ways to determine which drive is which, and any will work, but it's essential that you have the correct devices in the correct order. It's very easy to end up with both drives blank, or some such. The syntax in the OP is correct, assuming it uses the correct drives. The block size (bs=4096) is optional, and can be whatever size you like or omitted. If you want a 4MB block size, you can use 4M or 4MB, for example.
Quote:
N and BYTES may be followed by the following multiplicative suffixes:
c =1, w =2, b =512, kB =1000, K =1024, MB =1000*1000, M =1024*1024, xM =M
GB =1000*1000*1000, G =1024*1024*1024, and so on for T, P, E, Z, Y.
 
Old 01-10-2016, 12:37 PM   #6
WFV
Member
 
Registered: Apr 2012
Location: somehow, somewhere
Distribution: Arch
Posts: 197

Rep: Reputation: Disabled
Here are some examples: http://www.linuxquestions.org/questi...d.php?t=362506
default (if no bs is used) is 512, so if the drive has larger bs, it just speeds up the dd process some to use the correct bs but otherwise makes no real difference in the final product.

Code:
fdisk -l
to find out the actual bs (but again unnecessary as mentioned below, 1M or 4M is fine for usb iso and img).

Last edited by WFV; 01-10-2016 at 02:25 PM. Reason: block size
 
Old 01-10-2016, 01:32 PM   #7
cold.caller
LQ Newbie
 
Registered: Jan 2016
Posts: 3

Rep: Reputation: Disabled
I use a bs of 1M or 4M when I dd a hybrid iso to a usb stick and it has no issues. It boots fine and it runs well too.

Last edited by cold.caller; 01-10-2016 at 01:34 PM.
 
Old 01-12-2016, 09:29 AM   #8
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
The command appears valid, assuming /home is not on the USB device you are reading (rather unlikely) AND is big enough to hold everything on the USB device. I've done this several times to backup a Raspberry PI (32GB device), though I usually compress it afterwards as there are a lot of unused blocks in the file.

The bs option to dd is buffer size. The larger the buffer, the faster the transfer can go - with less contention on the various system busses involved (large reads tend to go at the maximum DMA size, and having a single large buffer means multiple DMA transfers can be done with less setup overhead). It works best when a multiple of the buffer size is the size of the device (you won't get warning messages about incomplete buffer transfers), but other than that, a 1MB buffer is usually plenty fast, and 4MB isn't that much faster. Without the bs specification I think the default is 4K (and quite slow).

The conv=notrunc is mostly a throwaway. I think it is only useful if you are replacing parts of a pre-existing file... or using an append operation.

Last edited by jpollard; 01-12-2016 at 09:33 AM.
 
Old 01-12-2016, 11:32 AM   #9
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by jpollard View Post
Without the bs specification I think the default is 4K (and quite slow).
The default dd block size is 512 bytes -- really slow.
Quote:
The conv=notrunc is mostly a throwaway. I think it is only useful if you are replacing parts of a pre-existing file... or using an append operation.
It's meaningful only when the destination is an existing ordinary file (meaningless for a device) and you don't want the operation to begin by throwing away the current content. That would be because you're modifying or appending to the current content, or perhaps because you want to keep the same disk blocks allocated to the file and you know the filesystem behavior will support that. (Some filesystems always use new space for writes.)
 
Old 01-13-2016, 12:42 PM   #10
PreguntoYo
Member
 
Registered: Jan 2012
Distribution: openSUSE, Gentoo, Slackware
Posts: 73

Original Poster
Rep: Reputation: 15
It worked

I plain cloned the USB with:
Code:
dd if=/dev/sdb of=/mnt/tmp/W8.1_USB_CLONE.dd bs=4K
Fortunately it was still in good shape and readable (it seems).

I simply choose the 4K size because it is the physical sector size of my hard disk. The process was a little slow, but I wasn't in a hurry.

BTW, I noticed that when Windows created this USB, the device was noticeable hot at the end of the process; this time when it was cloned with Linux it went only a barely hot. My guess is that Windows used the full bandwidth of the USB, but with Linux, as I only read from it sector by sector, the USB was submitted to a less stressful work and therefore heated less.

Thanks for the help!
 
Old 01-14-2016, 11:44 AM   #11
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by PreguntoYo View Post
The process was a little slow
may be because of the block size you provided.
there's usually no need to specify that, dd has some mechanism to adjust that automagically (or so i've been told).
 
  


Reply

Tags
dd



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a smarter way of cloning a USB stick other than dd? chicken76 Linux - Newbie 3 10-08-2012 09:59 AM
usb cloning ravedog Linux - Newbie 5 05-06-2010 03:47 PM
Cloning USB drives using C++ greenberet Programming 3 02-24-2010 04:11 AM
Cloning USB stick question Packrat1947 Linux - Newbie 7 12-05-2009 06:11 AM
Cloning HD using USB fraidycat Linux - General 8 02-22-2007 02:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration