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 usingBPTblocks (or fewer if you're near the end of the copy). Default is128for block sizes less than 2048 bytes, otherwise the default is32. So withbs=512the 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 andbptdefaults to 32, which again means 64 KiB transfers. consistent queen πbs=BSβ whereBSmust be the block size of the physical device. heads up: this is different fromdd(1), which letsBSbe an integral multiple. Default is512, 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 isBS * BPTbytes. 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β copyCOUNTblocks fromIFILEtoOFILE. Default is the minimum (ofIFILEandOFILE) 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. Ifskip=SKIPorseek=SEEKare 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 andCOUNTisn't given then the size of the partition is used rather than the size of the whole device. IfCOUNTisn'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. onOFILE). Only allowed when the read-side (i.e.IFILE) is a sg device. When1there 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 is0. The same action asdio=1is also available withoflag=dio. zero copy is such main character energy π₯ibs=BSβ if given, must be the same as theBSgiven to thebs=option. no mixing and matching bestie πif=IFILEβ read fromIFILEinstead of stdin. IfIFILEis-then stdin is read. Starts reading at the beginning ofIFILEunlessSKIPis given.iflag=FLAGSβ whereFLAGSis a comma separated list of one or more flags outlined below. These flags are associated withIFILEand are ignored whenIFILEis stdin.obs=BSβ if given, must be the same as theBSgiven to thebs=option. twins fr fr π«Άof=OFILEβ write toOFILEinstead of stdout. IfOFILEis-then writes go to stdout. IfOFILEis/dev/nullthen no actual writes are performed. IfOFILEis.(period) then it's treated the same way as/dev/null(it's just a shorthand notation). IfOFILEexists then it is _not_ truncated; it gets overwritten from the start ofOFILEunlessoflag=appendorSEEKis given. read that again, she does not delete your data by surprise πoflag=FLAGSβ whereFLAGSis a comma separated list of one or more flags outlined below. These flags are associated withOFILEand are ignored whenOFILEis/dev/null,.(period), or stdout.seek=SEEKβ start writingSEEKbs-sized blocks from the start ofOFILE. Default is block 0 (i.e. start of file).skip=SKIPβ start readingSKIPbs-sized blocks from the start ofIFILE. Default is block 0 (i.e. start of file).sync=0 | 1β when1, does a SYNCHRONIZE CACHE command onOFILEat the end of the transfer. Only active whenOFILEis a sg device file name. flush it, queen πtime=0 | 1β when1, times the transfer and does throughput calculation, outputting the results (to stderr) at completion. When0(default) she doesn't perform timing.verbose=VERBβ asVERBgoes 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 of1reports extra information that is not repetitive. A value2reports cdbs and responses for SCSI commands that are not repetitive (i.e. other than READ and WRITE). Error processing is not considered repetitive. Values of3and4yield output for all SCSI commands (and Unixread()andwrite()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 openingIFILEorOFILEto 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 toOFILEor stdout. The long option variant may be abbreviated to--nc. The explicit way to instruct this utility to read onlyIFILEis to use--of=/dev/nullin the invocation. This option may be viewed as extra safety in case--of=/dev/nullis 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 thetime=1option is set implicitly. she's keeping you updated, she cares π-v,--verboseβ when used once, this is equivalent toverbose=1. When used twice (e.g.-vv) this is equivalent toverbose=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 theO_APPENDflag to be added to the open ofOFILE. For normal files this leads to data appended to the end of any existing data. Cannot be used together with theseek=SEEKoption as they conflict. The default action of this utility is to overwrite any existing data from the beginning of the file or, ifSEEKis given, starting at blockSEEK. 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 withoflag(i.e.oflag=dio). Its action is described in thedio=1option description above. just scroll up bestie β¬οΈdirectβ causes theO_DIRECTflag to be added to the open ofIFILEand/orOFILE. 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 theO_SYNCflag to be added to the open ofIFILEand/orOFILE. The "d" is prepended to lower confusion with thesync=0|1option, 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 theO_EXCLflag to be added to the open ofIFILEand/orOFILE. 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. When3, fua is set on bothIFILEandOFILE; when2, fua is set onIFILE; when1, fua is set onOFILE; when0(default), fua is cleared on both. See thefuaflag 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 thesg_ddutility (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,SIGQUITandSIGPIPEoutput the number of remaining blocks to be transferred and the records in + out counts; then they have their default action.SIGUSR1causes 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 πΈ
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_ddis in thesg3_utilspackage. Threads era π§΅β¨ - The
lmbenchpackage containslmddwhich 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
- arch rolling: sg3_utils 1.49-1 Β· GPL-2.0-or-later AND BSD-2-Clause
- nixpkgs unstable: sg3_utils 1.49
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms