SGM_DD(8)

πŸ’… SGM_DD(8) β€” the sg3_utils glow-up

okay bestie, welcome to sgm_dd, straight out of sg3_utils and living in section 8 of your man pages πŸŽ€. Think of it as dd(1)'s cooler cousin who actually understands SCSI generic devices. She copies data to and from files and devices β€” especially SCSI devices β€” and she does it with memory mapped transfers on sg devices. Iconic behavior, honestly.


✨ SYNOPSIS ✨

sgm_dd [bs=BS] [count=COUNT] [ibs=BS] [if=IFILE] [iflag=FLAGS] [obs=BS]
[of=OFILE] [oflag=FLAGS] [seek=SEEK] [skip=SKIP] [--help] [--version]

[bpt=BPT] [cdbsz=6|10|12|16] [dio=0|1] [sync=0|1] [time=0|1]
[verbose=VERB] [--dry-run] [--nocopy] [--progress] [--verbose]

🌸 DESCRIPTION 🌸

She copies data to and from any files, but her whole personality is built for "files" that are Linux SCSI generic (sg) devices and raw devices. On sg devices she uses memory mapped transfers. The syntax and semantics are basically dd(1)'s, except she does not perform any conversions. No conversions, no drama, periodt πŸ’….

She'll only do memory mapped transfers when IFILE or OFILE are SCSI generic (sg) devices.

If both IFILE and OFILE are sg devices then the memory mapped transfers happen on IFILE. If you don't specify any other flags then indirect IO is performed on OFILE. Give her oflag=dio and she'll attempt direct IO on OFILE β€” and if direct IO isn't available, she falls back to indirect IO and reports that at the end of the copy. She's flexible like that 🫢.

The first group in the synopsis up there is the "standard" Unix dd(1) operands, the second group is the extra options this utility brings to the group chat. Both groups are defined below πŸ‘‡


πŸ¦‹ OPTIONS πŸ¦‹

  • bpt=BPT β€” every IO transaction gets made using BPT blocks (or fewer if you're near the end of the copy). Default is 128 for block sizes less than 2048 bytes, otherwise the default is 32. So with bs=512 the reads and writes each carry 64 KiB of data by default (less if you're near the end of the transfer or memory gets restrictive). When cd/dvd drives are being accessed the block size is typically 2048 bytes and bpt defaults to 32, which again means 64 KiB transfers. consistent queen πŸ‘‘
  • bs=BS β€” where BS must be the block size of the physical device. heads up: this is different from dd(1), which lets BS be an integral multiple. Default is 512, which is usually correct for disks but incorrect for cdroms (those normally have 2048 byte blocks). For this utility the maximum size of each individual IO operation is BS * BPT bytes. math is math πŸ’€
  • cdbsz=6 | 10 | 12 | 16 β€” the size of the SCSI READ and/or WRITE commands issued on sg device names. Default is 10 byte SCSI command blocks β€” unless the calculations indicate a 4 byte block number may be exceeded, in which case she defaults to 16 byte SCSI commands. she plans ahead, it's giving foresight ✨
  • count=COUNT β€” copy COUNT blocks from IFILE to OFILE. Default is the minimum (of IFILE and OFILE) number of blocks that sg devices report from SCSI READ CAPACITY commands, or that block devices (or their partitions) report. Normal files are not probed for their size. If skip=SKIP or seek=SEEK are given and the count is derived (i.e. not explicitly given) then the derived count gets scaled back so the copy won't overrun the device. If the file name is a block device partition and COUNT isn't given then the size of the partition is used rather than the size of the whole device. If COUNT isn't given and can't be derived then an error message is issued and no copy takes place. she said no vibes, no copy πŸ™ˆ
  • dio=0 | 1 β€” lets you select direct IO on the write-side (i.e. on OFILE). Only allowed when the read-side (i.e. IFILE) is a sg device. When 1 there may be a "zero copy" copy (i.e. mmap-ed transfer on the read into the user space and direct IO from there on the write, potentially two DMAs and no data copying from the CPU). Default is 0. The same action as dio=1 is also available with oflag=dio. zero copy is such main character energy πŸ”₯
  • ibs=BS β€” if given, must be the same as the BS given to the bs= option. no mixing and matching bestie πŸ’œ
  • if=IFILE β€” read from IFILE instead of stdin. If IFILE is - then stdin is read. Starts reading at the beginning of IFILE unless SKIP is given.
  • iflag=FLAGS β€” where FLAGS is a comma separated list of one or more flags outlined below. These flags are associated with IFILE and are ignored when IFILE is stdin.
  • obs=BS β€” if given, must be the same as the BS given to the bs= option. twins fr fr 🫢
  • of=OFILE β€” write to OFILE instead of stdout. If OFILE is - then writes go to stdout. If OFILE is /dev/null then no actual writes are performed. If OFILE is . (period) then it's treated the same way as /dev/null (it's just a shorthand notation). If OFILE exists then it is _not_ truncated; it gets overwritten from the start of OFILE unless oflag=append or SEEK is given. read that again, she does not delete your data by surprise 😭
  • oflag=FLAGS β€” where FLAGS is a comma separated list of one or more flags outlined below. These flags are associated with OFILE and are ignored when OFILE is /dev/null, . (period), or stdout.
  • seek=SEEK β€” start writing SEEK bs-sized blocks from the start of OFILE. Default is block 0 (i.e. start of file).
  • skip=SKIP β€” start reading SKIP bs-sized blocks from the start of IFILE. Default is block 0 (i.e. start of file).
  • sync=0 | 1 β€” when 1, does a SYNCHRONIZE CACHE command on OFILE at the end of the transfer. Only active when OFILE is a sg device file name. flush it, queen πŸ’…
  • time=0 | 1 β€” when 1, times the transfer and does throughput calculation, outputting the results (to stderr) at completion. When 0 (default) she doesn't perform timing.
  • verbose=VERB β€” as VERB goes up, so does the amount of debug output sent to stderr. Default value is zero which yields the minimum amount of debug output. A value of 1 reports extra information that is not repetitive. A value 2 reports cdbs and responses for SCSI commands that are not repetitive (i.e. other than READ and WRITE). Error processing is not considered repetitive. Values of 3 and 4 yield output for all SCSI commands (and Unix read() and write() calls) so there can be a lot of output. like, a LOT a lot πŸ’€
  • -d, --dry-run β€” does all the command line parsing and preparation but bypasses the actual copy or read. That preparation may include opening IFILE or OFILE to determine their lengths. This option may be useful for testing the syntax of complex command line invocations in advance of executing them. dress rehearsal, no commitment πŸŽ€
  • -h, --help β€” outputs usage message and exits. the classic.
  • -n, --nocopy β€” this option causes the utility to exit when it would otherwise attempt to write to OFILE or stdout. The long option variant may be abbreviated to --nc. The explicit way to instruct this utility to read only IFILE is to use --of=/dev/null in the invocation. This option may be viewed as extra safety in case --of=/dev/null is not given or is misspelt. she's your safety net bestie 🫢
  • -p, --progress β€” causes a progress report to be output every two minutes until the copy is complete. After the copy is complete a line with "completed" is printed to distinguish the final report from the prior progress reports. When used twice the progress report is every minute, when used three times the progress report is every 30 seconds. If this option is given then the time=1 option is set implicitly. she's keeping you updated, she cares πŸ’–
  • -v, --verbose β€” when used once, this is equivalent to verbose=1. When used twice (e.g. -vv) this is equivalent to verbose=2, etc. stack 'em 🌈
  • -V, --version β€” outputs version number information and exits.

🧚 FLAGS 🧚

here's the list of flags and what they mean, no cap:

  • append β€” causes the O_APPEND flag to be added to the open of OFILE. For normal files this leads to data appended to the end of any existing data. Cannot be used together with the seek=SEEK option as they conflict. The default action of this utility is to overwrite any existing data from the beginning of the file or, if SEEK is given, starting at block SEEK. Note that attempting to 'append' to a device file (e.g. a disk) will usually be ignored or may cause an error to be reported. so... maybe don't πŸ™ˆ
  • dio β€” only active with oflag (i.e. oflag=dio). Its action is described in the dio=1 option description above. just scroll up bestie ⬆️
  • direct β€” causes the O_DIRECT flag to be added to the open of IFILE and/or OFILE. This flag requires some memory alignment on IO. Hence user memory buffers are aligned to the page size. Has no effect on sg, normal or raw files.
  • dpo β€” sets the DPO bit (disable page out) in SCSI READ and WRITE commands. Not supported for 6 byte cdb variants of READ and WRITE. Indicates that data is unlikely to be required to stay in device (e.g. disk) cache. May speed media copy and/or cause a media copy to have less impact on other device users. considerate icon πŸ’…
  • dsync β€” causes the O_SYNC flag to be added to the open of IFILE and/or OFILE. The "d" is prepended to lower confusion with the sync=0|1 option, which has another action (i.e. a synchronisation to media at the end of the transfer). naming clarity, we love to see it ✨
  • excl β€” causes the O_EXCL flag to be added to the open of IFILE and/or OFILE. exclusive access only, she's not sharing πŸ‘‘
  • fua β€” causes the FUA (force unit access) bit to be set in SCSI READ and/or WRITE commands. This only has effect with sg devices. The 6 byte variants of the SCSI READ and WRITE commands do not support the FUA bit. Only active for sg device file names.
  • null β€” has no affect, just a placeholder. she's literally just vibing πŸ¦‹

⭐ RETIRED OPTIONS ⭐

some retired options that are still hanging around the group chat (they didn't leave, they just took a step back):

  • fua=0 | 1 | 2 | 3 β€” force unit access bit. When 3, fua is set on both IFILE and OFILE; when 2, fua is set on IFILE; when 1, fua is set on OFILE; when 0 (default), fua is cleared on both. See the fua flag above. legacy but still valid πŸ’œ

🫢 NOTES 🫢

Okay so before you even think about running sgm_dd, a raw device has to be bound to a block device first β€” that's just the rules, bestie. Peep raw(8) for the whole binding situation. And to be safe, you should check the sg device mapping to SCSI block devices with the lsscsi utility before use. Just do it, iykyk. ✨

Raw device partition information can often be found with fdisk(8) β€” and yes, the "-ul" argument is super useful in this respect. Noted. πŸ“

Various numeric arguments (e.g. SKIP) may include multiplicative suffixes or be given in hexadecimal. Go read the "NUMERIC ARGUMENTS" section in the sg3_utils(8) man page for the full tea. β˜•

The count, skip and seek parameters can take 64 bit values (i.e. very big numbers β€” like, huge). Other values are limited to what can fit in a signed 32 bit number.

Data usually gets to the user space in a 2 stage process: first the SCSI adapter DMAs into kernel buffers and then the sg driver copies this data into user memory (write operations reverse this sequence). With memory mapped transfers a kernel buffer reserved by sg is memory mapped (see the mmap(2) system call) into the user space. When this is done the second (redundant) copy from kernel buffers to user space is not needed. Hence the transfer is faster and requires less "grunt" from the CPU. Efficiency slay πŸ’…πŸ”₯

All informative, warning and error output is sent to stderr so that dd's output file can be stdout and remain unpolluted. Clean vibes only. And if no options are given, then the usage message is output and nothing else happens. That's it. That's the whole event. πŸ™ˆ

For sg devices this utility issues SCSI READ and WRITE (SBC) commands which are appropriate for disks and reading from CD/DVD/BD drives. Those commands are not formatted correctly for tape devices so sgm_dd should not be used on tape devices. Nope. Not the move. 🚫

Heads up bestie: this utility stops the copy if any error is encountered. For more advanced "copy on error" logic see the sg_dd utility (and its 'coe' flag). 😭

🌈 EXAMPLES 🌈

See the examples given in the man page for sg_dd(8). That's where the good stuff lives, go look πŸ‘€βœ¨


πŸŽ€ SIGNALS πŸŽ€

The signal handling has been borrowed from dd β€” iconic behavior, honestly:

  • SIGINT, SIGQUIT and SIGPIPE output the number of remaining blocks to be transferred and the records in + out counts; then they have their default action.
  • SIGUSR1 causes the same information to be output yet the copy continues. The main character doesn't stop for anything πŸ‘‘.

All output caused by signals is sent to stderr. Always stderr, never the vibe-polluting stdout. πŸ’–


⭐ EXIT STATUS ⭐

The exit status of sgm_dd is 0 when it is successful. Otherwise see the sg3_utils(8) man page.

Since this utility works at a higher level than individual commands, and there are 'coe' and 'retries' flags, individual SCSI command failures do not necessary cause the process to exit. Lowkey forgiving, ngl. πŸ¦‹


🧚 AUTHORS 🧚

Written by Douglas Gilbert and Peter Allworth. Legends, fr fr πŸ™Œ


πŸ’€ REPORTING BUGS πŸ’€

Report bugs to <dgilbert at interlog dot com>.


Copyright Β© 2000-2026 Douglas Gilbert

This software is distributed under the GPL version 2. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Read that again, bestie β€” no warranty, periodt. 😀


πŸ“ SEE ALSO πŸ“

  • The simplest variant of this utility is called sg_dd.
  • A POSIX threads version of this utility called sgp_dd is in the sg3_utils package. Threads era 🧡✨
  • The lmbench package contains lmdd which is also interesting.
  • dd(1), ddpt(ddpt), raw(8)

okay that's the whole page, you made it, so proud of you πŸ«ΆπŸ’–βœ¨ This lil beauty is sg3_utils-1.49, dated April 2026, and yes the page name is SGM_DD(8) β€” go forth and copy responsibly, bestie πŸŒΈπŸ’…πŸ”₯

πŸ“¦ where this page comes from