LinuxQuestions.org
Review your favorite Linux distribution.
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 02-08-2011, 08:38 AM   #1
clifford227
Member
 
Registered: Dec 2009
Distribution: Slackware 14
Posts: 282

Rep: Reputation: 64
'dd' help needed


hi,

would the following command wipe an entire drive clean (partition table included)?

Code:
dd if=/dev/urandom of=/dev/sda bs=512
I was wondering what the 'bs' part means? Would it be better to omit that?
 
Old 02-08-2011, 08:46 AM   #2
fordeck
Member
 
Registered: Oct 2006
Location: Utah
Posts: 520

Rep: Reputation: 61
Yes it would over write /dev/sda with random data. The 'bs=512' just tells the command to write 512 bytes at a time and is not needed.

Quote:
Originally Posted by clifford227 View Post
hi,

would the following command wipe an entire drive clean (partition table included)?

Code:
dd if=/dev/urandom of=/dev/sda bs=512
I was wondering what the 'bs' part means? Would it be better to omit that?
You can get more information by reading the man page for 'dd'

Regards,

Fordeck
 
1 members found this post helpful.
Old 02-08-2011, 08:54 AM   #3
lugoteehalt
Senior Member
 
Registered: Sep 2003
Location: UK
Distribution: Debian
Posts: 1,215
Blog Entries: 2

Rep: Reputation: 49
Quote:
Originally Posted by clifford227 View Post
I was wondering what the 'bs' part means? Would it be better to omit that?
bs=512 is the default:
Code:
info coreutils 'dd invocation'
So if omitted it would not make any difference. It simply instructs dd how big a chunk of data to remove or place each go. Incidentally the size of the MBR is 512.
 
1 members found this post helpful.
Old 02-08-2011, 09:01 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,832

Rep: Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820
And will be unbelievably slow - use a (much) larger bs. The manpage gives a way of finding out the progress.
 
1 members found this post helpful.
Old 02-08-2011, 09:02 AM   #5
vinodvb
LQ Newbie
 
Registered: Dec 2010
Location: Bangalore
Distribution: RHEL
Posts: 25

Rep: Reputation: 6
Quote:
Originally Posted by clifford227 View Post
hi,

would the following command wipe an entire drive clean (partition table included)?

Code:
dd if=/dev/urandom of=/dev/sda bs=512
I was wondering what the 'bs' part means? Would it be better to omit that?
The dd command syntax will be:
Code:
dd if=inputfile of=outputfile bs=byte-size count=blocks
The 'bs' and 'count' options together will give us the output file size of the dd command.

And regarding the 'bs' part, as mentioned earlier it is used along with 'count' to specify the output file size.
Code:
Example : 
bs=512 count=1 --> This gives us a 512 byte size file.
bs=1M count=1 --> Results in a 1MB file (1,048,576 bytes)
bs=1MB count=1 --> Resutls in a 1MB file (1,000,000 bytes)
bs=1G count=1 --> Results in a 1GB file (1,073,741,824 bytes)
bs=1GB count=1 --> results in a 1GB file (1,000,000,000 bytes)
In short, 'bs' will be multiplied 'count' number of times to decide the output file size.

NOTE: dd command to backup the MBR
Code:
dd if=/dev/sda of=/tmp/mbr.out bs=512 count=1
Regards

Last edited by vinodvb; 02-08-2011 at 09:27 AM. Reason: Correction
 
1 members found this post helpful.
Old 02-08-2011, 09:18 AM   #6
clifford227
Member
 
Registered: Dec 2009
Distribution: Slackware 14
Posts: 282

Original Poster
Rep: Reputation: 64
Quote:
Originally Posted by vinodvb View Post
The dd command syntax will be:
Code:
dd if=inputfile of=outputfile bs=byte-size count=blocks
Quote:
So the above command should include the 'count' option, and when included will actually wipe out the MBR (master boot record) and not the entire drive.
Sorry just make this clear for me, you mean that by including the count option, the above command would wipe only the MBR, but not the rest of the device?

Last edited by clifford227; 02-08-2011 at 09:21 AM.
 
Old 02-08-2011, 09:25 AM   #7
vinodvb
LQ Newbie
 
Registered: Dec 2010
Location: Bangalore
Distribution: RHEL
Posts: 25

Rep: Reputation: 6
Quote:
Originally Posted by clifford227 View Post
Code:
dd if=inputfile of=outputfile bs=byte-size count=blocks


Sorry just make this clear for me, you mean that by including the count option, the above command would wipe the MBR, but not the rest of the device?
Sorry for the confusion. If the bs and count options are mentioned, then the output size will be limited to as specified by bs and count. If not the entire drive will be written with random data.

In short, the first 512 bytes contain the MBR and if I limit the output file size to 512 bytes, then only the MBR will be overwritten. If I don't limit the output file size, then the entire drive will be overwritten including the MBR.
 
1 members found this post helpful.
Old 02-08-2011, 09:30 AM   #8
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Quote:
Originally Posted by clifford227 View Post
Code:
dd if=inputfile of=outputfile bs=byte-size count=blocks


Sorry just make this clear for me, you mean that by including the count option, the above command would wipe only the MBR, but not the rest of the device?
More correctly speaking, bs=512 count=1 will overwrite the first 512 bytes of the file specified by of='...'. If that file is a device node tied to a block device then it will write the first 512 bytes in that device with random bytes. If the device is partitioned using a MBR scheme then that matches the MBR. But the device could also hold meaningless stuff or be partitioned using EFI or some other thing, not necessarily an MBR scheme.
 
1 members found this post helpful.
Old 02-08-2011, 09:38 AM   #9
clifford227
Member
 
Registered: Dec 2009
Distribution: Slackware 14
Posts: 282

Original Poster
Rep: Reputation: 64
So the count option limits the portion of the device that will be overwritten?

If I only include the 'bs' option, then the entire drive will be overwritten? (please excuse me, I've got a very tiny brain).
 
Old 02-08-2011, 09:41 AM   #10
vinodvb
LQ Newbie
 
Registered: Dec 2010
Location: Bangalore
Distribution: RHEL
Posts: 25

Rep: Reputation: 6
Quote:
Originally Posted by clifford227 View Post
So the count option limits the portion of the device that will be overwritten?

If I only include the 'bs' option, then the entire drive will be overwritten? (please excuse me, I've got a very tiny brain).
Yup, you got it right
 
1 members found this post helpful.
Old 02-08-2011, 09:48 AM   #11
clifford227
Member
 
Registered: Dec 2009
Distribution: Slackware 14
Posts: 282

Original Poster
Rep: Reputation: 64
Fantastic, thanks for your help and patience guys

Last edited by clifford227; 02-08-2011 at 09:50 AM.
 
Old 02-08-2011, 01:06 PM   #12
Stephen Morgan
Member
 
Registered: Feb 2011
Location: England
Distribution: Slackware
Posts: 163

Rep: Reputation: 17
While we're on the subject, wouldn't /dev/zero work just as well as /dev/urandom, and probably be quicker?
 
Old 02-08-2011, 05:42 PM   #13
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
Quote:
Originally Posted by Stephen Morgan View Post
While we're on the subject, wouldn't /dev/zero work just as well as /dev/urandom, and probably be quicker?
Yes. It's just that people who are afraid that the NSA will waste their time to rescue porn from their hard drives prefer to use /dev/urandom to make it harder to recover all the porn from the drive. If you don't feel that kind of paranoia, just use /dev/zero.
 
Old 02-08-2011, 10:24 PM   #14
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: Slackware®
Posts: 12,541
Blog Entries: 23

Rep: Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943Reputation: 1943
Hi,

Look at 'Learn The DD Command Revised' if you want to learn by examples.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Need some more help with 'dd' mbzn Linux - Newbie 3 12-28-2009 01:08 PM
A question concerning the 'dd'-command Nyx Linux - Newbie 9 02-04-2007 09:03 AM
Encrypting an Existing FS with 'dd' ta0kira Linux - Security 2 01-24-2006 02:35 PM
the art of 'dd' and harddrives bardinjw Linux - General 5 05-26-2005 09:08 AM
problem about 'dd' jackandking Linux - Software 2 04-10-2005 10:35 AM


All times are GMT -5. The time now is 12:45 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration