LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-16-2006, 08:29 AM   #1
Melsync
Member
 
Registered: Sep 2005
Posts: 75

Rep: Reputation: 15
dd if=/dev/urandom of=/dev/hda2 bs=1M doesn't work


I'm following the instructions to setup a loop device but I fail to fill a partition with random data.
Code:
dd if=/dev/urandom of=/dev/hda2 bs=1M
as root doesn't do anything, the command line stops there and nothing is written to /dev/hda2.

/etc/fstab mounts the device at boot:
Code:
/dev/hda2               /mnt/styo               vfat    user,defaults,umask=000 0 0
/mnt/styo remains unchanged.
Why? Thank you.
 
Old 07-16-2006, 09:32 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Ubuntu/WSL
Posts: 9,785

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Use strace to find out what dd is (perhaps not) doing:
Code:
# strace dd if=/dev/urandom of=/dev/hda2 bs=1M
 
Old 07-16-2006, 11:51 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
How big is the partition that you are writing to? It may be that the command will take some time. Check and see that the disk access light starts flashing when you issue the command---that tells you that something is happening.
 
Old 07-16-2006, 12:20 PM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Also, make sure the disk is not mounted when you attempt this: that could cause a number of problems.
 
Old 07-16-2006, 05:35 PM   #5
Melsync
Member
 
Registered: Sep 2005
Posts: 75

Original Poster
Rep: Reputation: 15
/dev/hda2 is 60 GB big. I unmounted it. The command has been running for more than an hour now.
The output of strace dd if=/dev/urandom of=/dev/hda2 bs=1M is
Quote:
execve("/bin/dd", ["dd", "if=/dev/urandom", "of=/dev/hda2", "bs=1M"], [/* 24 vars */]) = 0
brk(0) = 0x9c27000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=144382, ...}) = 0
old_mmap(NULL, 144382, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7f07000
close(3) = 0
open("/lib/libc.so.6", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\212~\177"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0755, st_size=1485672, ...}) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f06000
old_mmap(0x417e3000, 1215452, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x417e3000
old_mmap(0x41906000, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x123000) = 0x41906000
old_mmap(0x4190a000, 7132, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x4190a000
close(3) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f05000
set_thread_area({entry_number:-1 -> 6, base_addr:0xb7f056c0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0
mprotect(0x41906000, 8192, PROT_READ) = 0
mprotect(0x4101a000, 4096, PROT_READ) = 0
munmap(0xb7f07000, 144382) = 0
brk(0) = 0x9c27000
brk(0x9c48000) = 0x9c48000
open("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=49618608, ...}) = 0
mmap2(NULL, 2097152, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7d05000
close(3) = 0
close(0) = 0
open("/dev/urandom", O_RDONLY|O_LARGEFILE) = 0
close(1) = 0
open("/dev/hda2", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 1
rt_sigaction(SIGINT, NULL, {SIG_DFL}, 8) = 0
rt_sigaction(SIGINT, {0x80495cd, [], 0}, NULL, 8) = 0
rt_sigaction(SIGQUIT, NULL, {SIG_DFL}, 8) = 0
rt_sigaction(SIGQUIT, {0x80495cd, [], 0}, NULL, 8) = 0
rt_sigaction(SIGPIPE, NULL, {SIG_DFL}, 8) = 0
rt_sigaction(SIGPIPE, {0x80495cd, [], 0}, NULL, 8) = 0
rt_sigaction(SIGUSR1, NULL, {SIG_DFL}, 8) = 0
rt_sigaction(SIGUSR1, {0x8049638, [], 0}, NULL, 8) = 0
mmap2(NULL, 1060864, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7c02000
read(0, "\2\347\336\2648\n#\353\355\346\277\331\266\360{v\206\304"..., 1048576) = 1048576
write(1, "\2\347\336\2648\n#\353\355\346\277\331\266\360{v\206\304"..., 1048576) = 1048576
read(0, "g\t\356\311\2144\272\266\204q+\347\240\267\272)w\333Nj"..., 1048576) = 1048576
write(1, "g\t\356\311\2144\272\266\204q+\347\240\267\272)w\333Nj"..., 1048576) = 1048576
and the disk led keeps on blinking. The processor is an Athlon 1100 MHz
 
Old 07-16-2006, 05:49 PM   #6
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 128Reputation: 128
60GB will take quite a while. That shows that 2MB have been copied to the disk. How far along was that strace ouput captured?
 
Old 07-16-2006, 06:51 PM   #7
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Ubuntu/WSL
Posts: 9,785

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
And by the way, why are you filling this partition with random data ?
 
Old 07-16-2006, 06:53 PM   #8
teckk
Senior Member
 
Registered: Oct 2004
Distribution: Arch
Posts: 4,037
Blog Entries: 4

Rep: Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371Reputation: 1371
http://www.linuxquestions.org/questi...hreadid=366442

Let me add that.
 
Old 07-16-2006, 06:56 PM   #9
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Quote:
Originally Posted by jlliagre
And by the way, why are you filling this partition with random data ?
I'd guess (and I'm sure the OP will correct me) that he's either trying to thoroughly wipe a drive before selling it/giving it away or he's preparing to setup some sort of cryptoloop setup that would work better with a partition full of random data.
 
Old 05-18-2014, 08:27 PM   #10
jrojsh
LQ Newbie
 
Registered: May 2014
Posts: 4

Rep: Reputation: 0
Question in the same vein as the op...

i managed to strace my dd while it was running, although id appreciate some help deciphering what its really doing here...5 hours running doing something i think...

Quote:
strace dd if=/dev/urandom of=/dev/sda bs=1M
execve("/bin/dd", ["dd", "if=/dev/urandom", "of=/dev/sda", "bs=1M"], [/* 47 vars */]) = 0
brk(0) = 0xbfb000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f61700cb000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=90307, ...}) = 0
mmap(NULL, 90307, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f61700b4000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\320\37\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1845024, ...}) = 0
mmap(NULL, 3953344, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f616fae5000
mprotect(0x7f616fca1000, 2093056, PROT_NONE) = 0
mmap(0x7f616fea0000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1bb000) = 0x7f616fea0000
mmap(0x7f616fea6000, 17088, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f616fea6000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f61700b3000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f61700b1000
arch_prctl(ARCH_SET_FS, 0x7f61700b1740) = 0
mprotect(0x7f616fea0000, 16384, PROT_READ) = 0
mprotect(0x60c000, 4096, PROT_READ) = 0
mprotect(0x7f61700cd000, 4096, PROT_READ) = 0
munmap(0x7f61700b4000, 90307) = 0
rt_sigaction(SIGUSR1, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGINT, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGUSR1, {0x403c90, [INT USR1], SA_RESTORER, 0x7f616fb1bff0}, NULL, 8) = 0
rt_sigaction(SIGINT, {0x403c80, [INT USR1], SA_RESTORER|SA_NODEFER|SA_RESETHAND, 0x7f616fb1bff0}, NULL, 8) = 0
brk(0) = 0xbfb000
brk(0xc1c000) = 0xc1c000
open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=2919792, ...}) = 0
mmap(NULL, 2919792, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f616f81c000
close(3) = 0
open("/dev/urandom", O_RDONLY) = 3
dup2(3, 0) = 0
close(3) = 0
lseek(0, 0, SEEK_CUR) = 0
open("/dev/sda", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 EACCES (Permission denied)
open("/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=2570, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f61700ca000
read(3, "# Locale name alias data base.\n#"..., 4096) = 2570
read(3, "", 4096) = 0
close(3) = 0
munmap(0x7f61700ca000, 4096) = 0
open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en_US.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en_US.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en_US/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en/LC_MESSAGES/coreutils.mo", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=619, ...}) = 0
mmap(NULL, 619, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f61700ca000
close(3) = 0
open("/usr/lib/charset.alias", O_RDONLY|O_NOFOLLOW) = -1 ENOENT (No such file or directory)
write(2, "dd: ", 4dd: ) = 4
write(2, "failed to open \342\200\230/dev/sda\342\200\231", 29failed to open ‘/dev/sda’) = 29
open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en_US.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en_US.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
write(2, ": Permission denied", 19: Permission denied) = 19
write(2, "\n", 1
) = 1
close(2) = 0
exit_group(1) = ?
+++ exited with 1 +++
jro@jro-System-Product-Name ~ $

Last edited by jrojsh; 05-18-2014 at 08:39 PM.
 
Old 05-18-2014, 09:01 PM   #11
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 7,231

Rep: Reputation: Disabled
/dev/urandom can be (and probably is) veeeery slow. You should use /dev/zero instead.
 
Old 05-18-2014, 09:13 PM   #12
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 20,342

Rep: Reputation: 3833Reputation: 3833Reputation: 3833Reputation: 3833Reputation: 3833Reputation: 3833Reputation: 3833Reputation: 3833Reputation: 3833Reputation: 3833Reputation: 3833
In the normal course of events, you'd hope that this was being done from a liveCD. /dev/sda is usually the boot device.
I have done this on laptops going back to leasing companies though.
Note this
Quote:
open("/dev/sda", O_WRONLY|O_CREAT|O_TRUNC, 0666to ) = -1 EACCES (Permission denied)
- that would have generated some output to the screen; the messages can be seen in the writes below. If you really, really want to do this to the entire disk, you must be root (or use sudo or such).

And yes, it's slow. A better option to check progress is to pass USR1 signal as the manpage suggests - that way you can get stats anytime, and (maybe) make an estimate of when it might be finished.
 
Old 05-18-2014, 11:39 PM   #13
replica9000
Senior Member
 
Registered: Jul 2006
Distribution: Debian Unstable
Posts: 1,065
Blog Entries: 2

Rep: Reputation: 227Reputation: 227Reputation: 227
This will give you a progress bar. See man pv for more info

Code:
pv -pbert -s 60G < /dev/urandom > /dev/sda2
or
Code:
cat /dev/urandom | pv -pbert -s 60G | dd of=/dev/sda2 bs=1M
 
1 members found this post helpful.
Old 05-19-2014, 12:32 PM   #14
jrojsh
LQ Newbie
 
Registered: May 2014
Posts: 4

Rep: Reputation: 0
Thumbs up thanks everyone!

Quote:
In the normal course of events, you'd hope that this was being done from a liveCD. /dev/sda is usually the boot device.
I have done this on laptops going back to leasing companies though.
im a noob but yes, im on live usb... when i updated the os from mint 16 to 17, the mbr became corrupted somehow. it wouldnt load anything, would not give me grub access even. i could have just dd the boot sector but im thinking about ugrading the hdd and giving this away... so i thought id give dd a try and kill 2 birds with one stone.
Quote:
This will give you a progress bar. See man pv for more info
exactly what i needed. sitting here not knowing what if anything was happening was frustrating at best!

Quote:
/dev/urandom can be (and probably is) veeeery slow. You should use /dev/zero instead.
urandom is slow but i thought it was more secure, am i wrong or is zero better?

Last edited by jrojsh; 05-19-2014 at 12:33 PM.
 
Old 05-19-2014, 02:38 PM   #15
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
Depends on how paranoid you are.

Using /dev/zero is sufficient for 99% of things - and it runs at the speed of the disk (might take 15-20 minutes for 60G, but could be less).
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
/dev/random and /dev/urandom pool(s)? kpeirce Linux - Software 2 01-31-2006 06:54 AM
merging /dev/hda2 and /dev/hda3 aggiridharan Linux - General 2 01-06-2006 01:31 AM
reading from /dev/urandom in c djgerbavore Programming 5 10-04-2005 12:54 PM
swap, /dev/hda2 by /dev/hands :) kaN5300 Slackware 2 09-13-2004 03:45 AM
/dev/urandom Moszer Slackware 3 09-09-2003 09:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:26 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
Open Source Consulting | Domain Registration