I'm trying to use the following command:

dd if=/dev/urandom of=/dev/sg11 bs=16K count=1

But when executing it, I get the following error:

dd: writing `/dev/sg11': Function not implemented

When I try with dd if=/dev/urandom of=/dev/sg11 bs=16K count=1 conv=fsync, then I get a cannot allocate memory error, which becomes a Function not implemented error when I up the bs size.

What causes this issue and how can I fix it?

UPDATE: Sometimes it will tell me cannot allocate memory, and then it will again tell me that function not implemented for the same bs value.

  • Note that bs and count together just specify how much data to copy. The real data comes from if, which you specify as /dev/urandom -- that is, random data. – a CVn Jul 22 '13 at 21:37
  • @MichaelKjörling I was aware of that from the man pages :P I was using different values of bs in order to see if it was a sector/block write size issue, which it ended up not being. – ardent Jul 22 '13 at 21:46

/dev/sgxx is a SCSI-generic device, which allows sending and receiving of raw SCSI commands. When you write to the device, you are expected to start the write with a SCSI header, which defines the operation you wish to do.

Writing random data to an sg device is really a bad idea. You'll be sending random SCSI commands, which might not even exist (hence function not implemented) and furthermore giving a random byte length for the operation, which is highly likely to result in cannot allocate memory. (If you're really unlucky, the random command might do something.)

Depending on what device you actually have connected to /dev/sg11, you might want to investigate the sg3_utils package, or some more specific SCSI device driver like st (tape drives).

One of the useful utility commands which comes with the sg utils is sg_map, which can let you know what the primary device corresponding to an sg device. On non-ancient Linux systems, you can also install lsscsi which provides a nice listing of SCSI devices, again with both the /dev/sg device and the primary device.

sg3_utils also includes sg_dd which is a version of dd which understands the low-level SCSI protocol. (But only use it if you know what you're doing!)

  • Right. I got that clarified with a coworker. I had to grep and awk with sg_map to get the block device I could actually write to. I guess you can edit your answer to incorporate that and I will accept, or I'll post that solution myself! – ardent Jul 22 '13 at 19:48
  • @ardentsonata: done, I think. – rici Jul 22 '13 at 20:00
  • 1
    This is worth an upvote just for "if you're really unlucky, the random command might do something", IMO. – a CVn Jul 22 '13 at 20:19
  • @MichaelKjörling, I agree with that sentiment. – ardent Jul 22 '13 at 21:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.