{
    "mode": "man",
    "parameter": "sg_dd",
    "section": "8",
    "url": "https://www.chedong.com/phpMan.php/man/sg_dd/8/json",
    "generated": "2026-06-15T18:51:52Z",
    "synopsis": "sgdd [bs=BS] [conv=CONV] [count=COUNT] [ibs=BS] [if=IFILE] [iflag=FLAGS] [obs=BS] [of=OFILE]\n[oflag=FLAGS] [seek=SEEK] [skip=SKIP] [--help] [--verbose] [--version]\n[blksgio={0|1}]  [bpt=BPT]  [cdbsz={6|10|12|16}]  [cdl=CDL]  [coe={0|1|2|3}]  [coelimit=CL]\n[dio={0|1}]  [odir={0|1}]  [of2=OFILE2]  [retries=RETR]  [sync={0|1}] [time={0|1}[,TO]] [ver‐\nbose=VERB] [--dry-run] [--progress] [--verify]",
    "sections": {
        "NAME": {
            "content": "sgdd - copy data to and from files and devices, especially SCSI devices\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "sgdd [bs=BS] [conv=CONV] [count=COUNT] [ibs=BS] [if=IFILE] [iflag=FLAGS] [obs=BS] [of=OFILE]\n[oflag=FLAGS] [seek=SEEK] [skip=SKIP] [--help] [--verbose] [--version]\n\n[blksgio={0|1}]  [bpt=BPT]  [cdbsz={6|10|12|16}]  [cdl=CDL]  [coe={0|1|2|3}]  [coelimit=CL]\n[dio={0|1}]  [odir={0|1}]  [of2=OFILE2]  [retries=RETR]  [sync={0|1}] [time={0|1}[,TO]] [ver‐\nbose=VERB] [--dry-run] [--progress] [--verify]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Copy data to and from any files. Specialized for \"files\" that are Linux SCSI generic (sg) de‐\nvices, raw devices or other devices that support the SGIO ioctl (which are only found in the\nlk 2.6 series). Similar syntax and semantics to dd(1) command.\n\nThe first group in the synopsis above are \"standard\" Unix dd(1) operands.  The  second  group\nare extra options added by this utility.  Both groups are defined below.\n\nWhen  the --verify option is given, then the read side is the same but the on the write side,\nthe WRITE SCSI command is replaced by the VERIFY SCSI command. If any VERIFY commands  yields\na  sense  key of MISCOMPARE then the verify operation will stop. The --verify option can only\nbe used when OFILE is either a sg device or a block device with oflag=sgio also  given.  When\nthe  --verify option is used, this utility works in a similar fashion to the Unix cmp(1) com‐\nmand.\n\nThis utility is only supported on Linux whereas most other utilities in the sg3utils package\nhave  been  ported to other operating systems. A utility called \"ddpt\" has similar syntax and\nfunctionality to sgdd. ddpt drops some Linux  specific  features  while  adding  some  other\ngeneric features. This allows ddpt to be ported to other operating systems.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "blksgio={0|1}\nwhen  set  to  0,  block  devices  (e.g. /dev/sda) are treated like normal files (i.e.\nread(2) and write(2) are used for IO). When set to 1, block devices are assumed to ac‐\ncept  the  SGIO ioctl and SCSI commands are issued for IO. This is only supported for\n2.6 series kernels. Note that ATAPI devices (e.g. cd/dvd players) use the SCSI command\nset but ATA disks do not (unless there is a protocol conversion as often occurs in the\nUSB mass storage class). If the input or output device is  a  block  device  partition\n(e.g.  /dev/sda3)  then setting this option causes the partition information to be ig‐\nnored (since access is directly to the underlying  device).  Default  is  0.  See  the\n'sgio' flag.\n\nbpt=BPT\neach  IO  transaction  will  be  made using BPT blocks (or less if near the end of the\ncopy). Default is 128 for logical block sizes less that 2048 bytes, otherwise the  de‐\nfault is 32. So for bs=512 the reads and writes will each convey 64 KiB of data by de‐\nfault (less if near the end of the  transfer  or  memory  restrictions).  When  cd/dvd\ndrives  are  accessed, the logical block size is typically 2048 bytes and bpt defaults\nto 32 which again implies 64 KiB transfers. The block layer when the blksgio=1 option\nis  used  has  relatively  low  upper limits for transfer sizes (compared to sg device\nnodes, see /sys/block/<devname>/queue/maxsectorskb ).\n\nbs=BS  where BS must be the logical block size of the physical device (if either the input or\noutput  files are accessed via SCSI commands). Note that this differs from dd(1) which\npermits BS to be an integral multiple. Default is 512 which  is  usually  correct  for\ndisks  but incorrect for cdroms (which normally have 2048 byte blocks). For this util‐\nity the maximum size of each individual IO operation is BS * BPT bytes.\n\ncdbsz={6|10|12|16}\nsize of SCSI READ and/or WRITE commands issued on sg device names  (or  block  devices\nwhen  'iflag=sgio'  and/or  'oflag=sgio'  is  given).  Default is 10 byte SCSI command\nblocks (unless calculations indicate that a 4 byte block number may be exceeded or BPT\nis greater than 16 bits (65535), in which case it defaults to 16 byte SCSI commands).\n\ncdl=CDL\nallows  setting of command duration limits. CDL is either a single value or two values\nseparated by a comma. If one value is given, it applies to both IFILE  and  OFILE  (if\nthey  are  pass-through  devices). If two values are given, the first applies to IFILE\nwhile the second applies to OFILE. The value may be from 0 to 7 where 0 is the default\nand  means there are no command duration limits. Command duration limits are only sup‐\nported by 16 byte READ and WRITE commands (plus  READ(32),  WRITE(32)  and  the  WRITE\nSCATTERED  command,  bit  thay  are used by this utility). If the cdbsz operand is not\ngiven and would have a value less than 16, then if CDL is greater than 0, the cdbsz is\nincreased to 16.\nCommand  duration  limits  can be accesses and changed in the Command duration limit A\nand B mode pages, plus the Command duration limit T2A and T2B mode pages.  The  sdparm\nutility may be used to access and change these mode pages.\n\ncoe={0|1|2|3}\nset  to  1 or more for continue on error ('coe'). Only applies to errors on sg devices\nor block devices with the 'sgio' flag set. Thus errors on other files will stop sgdd.\nDefault is 0 which implies stop on any error. See the 'coe' flag for more information.\n\ncoelimit=CL\nwhere CL is the maximum number of consecutive bad blocks stepped over (due to \"coe>0\")\non reads before the copy terminates. This only applies when IFILE is accessed via  the\nSGIO  ioctl.  The default is 0 which is interpreted as no limit. This option is meant\nto stop the copy soon after unrecorded media is detected while  still  offering  \"con‐\ntinue on error\" capability.\n\nconv=sparse\nsee the CONVERSIONS section below.\n\ncount=COUNT\ncopy  COUNT  blocks  from  IFILE to OFILE. Default is the minimum (of IFILE and OFILE)\nnumber of blocks that sg devices report from SCSI READ CAPACITY commands or that block\ndevices  (or  their partitions) report. Normal files are not probed for their size. If\nskip=SKIP or seek=SEEK are given and the count is derived (i.e.  not explicitly given)\nthen the derived count is scaled back so that the copy will not overrun the device. If\nthe file name is a block device partition and COUNT is not given then the size of  the\npartition  rather than the size of the whole device is used. If COUNT is not given (or\ncount=-1) and cannot be derived then an error message is  issued  and  no  copy  takes\nplace.\n\ndio={0|1}\ndefault  is  0 which selects indirect (buffered) IO on sg devices. Value of 1 attempts\ndirect IO which, if not available, falls back to indirect IO and notes this at comple‐\ntion.  If  direct IO is selected and /proc/scsi/sg/allowdio has the value of 0 then a\nwarning is issued (and indirect  IO  is  performed).   For  finer  grain  control  use\n'iflag=dio' or 'oflag=dio'.\n\nibs=BS if given must be the same as BS given to 'bs=' option.\n\nif=IFILE\nread  from  IFILE instead of stdin. If IFILE is '-' then stdin is read. Starts reading\nat the beginning of IFILE unless SKIP is given.\n\niflag=FLAGS\nwhere FLAGS is a comma separated list of one or  more  flags  outlined  below.   These\nflags are associated with IFILE and are ignored when IFILE is stdin.\n\nobs=BS if given must be the same as BS given to 'bs=' option.\n\nodir={0|1}\nwhen  set to one opens block devices (e.g. /dev/sda) with the ODIRECT flag. User mem‐\nory buffers are aligned to the page size when set. The default is 0 (i.e. the ODIRECT\nflag  is  not used). Has no effect on sg, normal or raw files. If blksgio is also set\nthen both are honoured: block devices are opened with the ODIRECT flag and SCSI  com‐\nmands are issued via the SGIO ioctl.\n\nof=OFILE\nwrite  to OFILE instead of stdout. If OFILE is '-' then writes to stdout.  If OFILE is\n/dev/null then no actual writes are performed.  If OFILE is '.' (period)  then  it  is\ntreated the same way as /dev/null (this is a shorthand notation). If OFILE exists then\nit is not truncated; it is overwritten from the start of OFILE unless 'oflag=append'\nor SEEK is given.\n\nof2=OFILE2\nwrite  output  to  OFILE2. The default action is not to do this additional write (i.e.\nwhen this option is not given). OFILE2 is assumed to be a normal file or a fifo  (i.e.\na  named  pipe). OFILE2 is opened for writing, created if necessary, and closed at the\nend of the transfer. If OFILE2 is a fifo (named pipe) then some other  command  should\nbe consuming that data (e.g. 'md5sum OFILE2'), otherwise this utility will block.\n\noflag=FLAGS\nwhere  FLAGS  is  a  comma  separated list of one or more flags outlined below.  These\nflags are associated with OFILE and are ignored when OFILE is /dev/null, '.' (period),\nor stdout.\n\nretries=RETR\nsometimes retries at the host are useful, for example when there is a transport error.\nWhen RETR is greater than zero then SCSI READs and WRITEs are retried on  error,  RETR\ntimes. Default value is zero.\n\nseek=SEEK\nstart  writing SEEK bs-sized blocks from the start of OFILE.  Default is block 0 (i.e.\nstart of file).\n\nskip=SKIP\nstart reading SKIP bs-sized blocks from the start of IFILE.  Default is block 0  (i.e.\nstart of file).\n\nsync={0|1}\nwhen  1,  does SYNCHRONIZE CACHE command on OFILE at the end of the transfer. Only ac‐\ntive when OFILE is a sg device file name or a block device and 'blksgio=1' is given.\n\ntime={0|1}[,TO]\nwhen 1, times transfer and does throughput calculation,  outputting  the  results  (to\nstderr) at completion. When 0 (default) doesn't perform timing.\nIf  that  value  is followed by a comma, then TO is the command timeout in seconds for\nSCSI READ, WRITE or VERIFY commands issued by this utility.  The default  is  60  sec‐\nonds.\n\nverbose=VERB\nas VERB increases so does the amount of debug output sent to stderr.  Default value is\nzero which yields the minimum amount of debug output.  A value of 1 reports extra  in‐\nformation  that  is not repetitive. A value 2 reports cdbs and responses for SCSI com‐\nmands that are not repetitive (i.e. other that READ and WRITE).  Error  processing  is\nnot  considered  repetitive. Values of 3 and 4 yield output for all SCSI commands (and\nUnix read() and write() calls) so there can be a lot of output.  This only occurs  for\nscsi generic (sg) devices and block devices when the 'blksgio=1' option is set.\n",
            "subsections": [
                {
                    "name": "-d --dry-run",
                    "content": "does  all  the  command  line  parsing and preparation but bypasses the actual copy or\nread. That preparation may include opening IFILE or OFILE to determine their  lengths.\nThis  option  may be useful for testing the syntax of complex command line invocations\nin advance of executing them.\n",
                    "flag": "-d",
                    "long": "--dry-run"
                },
                {
                    "name": "-h --help",
                    "content": "outputs usage message and exits.\n",
                    "flag": "-h",
                    "long": "--help"
                },
                {
                    "name": "-p --progress",
                    "content": "this option causes a progress report to be output every two minutes until the copy  is\ncomplete. After the copy is complete a line with \"completed\" is printed to distinguish\nthe final report from the prior progress reports.  When used twice the progress report\nis every minute, when used three times the progress report is every 30 seconds.\n",
                    "flag": "-p",
                    "long": "--progress"
                },
                {
                    "name": "-v --verbose",
                    "content": "when  used once, this is equivalent to verbose=1. When used twice (e.g. \"-vv\") this is\nequivalent to verbose=2, etc.\n",
                    "flag": "-v",
                    "long": "--verbose"
                },
                {
                    "name": "-x --verify",
                    "content": "do a verify operation (like Unix command cmp(1)) rather than a copy.  Cannot  be  used\nwith  \"oflag=sparse\". of=OFILE must be given and OFILE must be an sg device or a block\ndevice with \"oflag=sgio\" also given. Uses the SCSI  VERIFY  command  with  the  BYTCHK\nfield set to 1. The VERIFY command is used instead of WRITE when this option is given.\nThere is no VERIFY(6) command. Stops on  the  first  miscompare  unless  oflag=coe  is\ngiven.\n",
                    "flag": "-x",
                    "long": "--verify"
                },
                {
                    "name": "-V --version",
                    "content": "outputs version number information and exits.\n",
                    "flag": "-V",
                    "long": "--version"
                }
            ]
        },
        "CONVERSIONS": {
            "content": "One  or  more conversions can be given to the \"conv=\" option. If more than one is given, they\nshould be comma separated. sgdd does not perform the traditional dd conversions (e.g.  ASCII\nto  EBCDIC).  Recently  added conversions overlap somewhat with the flags so some conversions\nare now supported by sgdd.\n\nnocreat\nthis conversion has the same effect as \"oflag=nocreat\", namely: OFILE must  exist,  it\nwill not be created.\n\nnoerror\nthis  conversion  is  very  close to \"iflag=coe\" and is treated as such. See the \"coe\"\nflag. Note that an error on OFILE will stop the copy.\n\nnotrunc\nthis conversion is accepted for compatibility with dd and ignored  since  the  default\naction of this utility is not to truncate OFILE.\n\nnull   has no affect, just a placeholder.\n\nsparse FreeBSD supports \"conv=sparse\" so the same syntax is supported in sgdd.  See \"sparse\"\nin the FLAGS sections for more information.\n\nsync   is ignored by sgdd. With dd it means supply zero fill (rather than skip) and is typi‐\ncally  used  like  this  \"conv=noerror,sync\" to have the same functionality as sgdd's\n\"iflag=coe\".\n",
            "subsections": []
        },
        "FLAGS": {
            "content": "Here is a list of flags and their meanings:\n\n00     this flag is only active with iflag= and when given replaces  if=IFILE.  If  both  are\ngiven  an  error  is  generated. The input will be a stream of zeros, similar to using\n\"if=/dev/zero\" alone (but a little quicker).\n\nappend causes the OAPPEND flag to be added to the open of OFILE. For regular files this will\nlead  to  data  appended to the end of any existing data. Cannot be used together with\nthe seek=SEEK option as they conflict. The default action of this utility is to  over‐\nwrite  any existing data from the beginning of the file or, if SEEK is given, starting\nat block SEEK. Note that attempting to 'append' to a device file (e.g.  a  disk)  will\nusually be ignored or may cause an error to be reported.\n\ncoe    continue  on  error. Only active for sg devices and block devices that have the 'sgio'\nflag set. 'iflag=coe oflag=coe' and 'coe=1' are equivalent. Use this flag twice  (e.g.\n'iflag=coe,coe')  to have the same action as the 'coe=2'.  A medium, hardware or blank\ncheck error while reading will re-read blocks prior to the bad block, then try to  re‐\ncover the bad block, supplying zeros if that fails, and finally re-read the blocks af‐\nter the bad block. A medium, hardware or blank check error while writing is noted  and\nignored. A miscompare sense key during a VERIFY command (i.e. --verify given) is noted\nand ignored when 'oflag=coe'. The recovery of the bad block when reading uses the SCSI\nREAD  LONG  command  if  'coe'  given twice or more (also with the command line option\n'coe=2'). Further, the READ LONG will set its CORRCT bit if 'coe' given  thrice.  SCSI\ndisks  may  automatically  try  and remap faulty sectors (see the AWRE and ARRE in the\nread write error recovery mode page (the sdparm utility can access and possibly change\nthese  attributes)). Errors occurring on other files types will stop sgdd. Error mes‐\nsages are sent to stderr. This flag is similar to  'conv=noerror,sync'  in  the  dd(1)\nutility. See note about READ LONG below.\n\ndio    request  the  sg device node associated with this flag does direct IO. If direct IO is\nnot available, falls back to indirect IO and notes this at completion.  If  direct  IO\nis  selected  and  /proc/scsi/sg/allowdio has the value of 0 then a warning is issued\n(and indirect IO is performed).\n\ndirect causes the ODIRECT flag to be added to the open of IFILE and/or OFILE. This flag  re‐\nquires  some memory alignment on IO. Hence user memory buffers are aligned to the page\nsize. Has no effect on sg, normal or raw files. If 'iflag=sgio' and/or 'oflag=sgio' is\nalso  set  then both are honoured: block devices are opened with the ODIRECT flag and\nSCSI commands are issued via the SGIO ioctl.\n\ndpo    set the DPO bit (disable page out) in SCSI READ and WRITE commands. Not supported  for\n6  byte cdb variants of READ and WRITE. Indicates that data is unlikely to be required\nto stay in device (e.g. disk) cache. May speed media copy and/or cause a media copy to\nhave less impact on other device users.\n\ndsync  causes  the  OSYNC  flag  to  be  added to the open of IFILE and/or OFILE. The 'd' is\nprepended to lower confusion with the 'sync=0|1' option which has another action (i.e.\na synchronisation to media at the end of the transfer).\n\nexcl   causes the OEXCL flag to be added to the open of IFILE and/or OFILE.\n\nff     this  flag  is  only  active with iflag= and when given replaces if=IFILE. If both are\ngiven an error is generated. The input will be a stream of 0xff  bytes  (or  all  bits\nset).\n\nflock  after  opening the associated file (i.e. IFILE and/or OFILE) an attempt is made to get\nan advisory exclusive lock with the flock()  system  call.  The  flock  arguments  are\n\"FLOCKEX  | FLOCKNB\" which will cause the lock to be taken if available else a \"tem‐\nporarily unavailable\" error is generated. An exit status of 90 is produced in the lat‐\nter case and no copy is done.\n\nfua    causes  the  FUA (force unit access) bit to be set in SCSI READ and/or WRITE commands.\nThis only has an effect with sg devices or block devices that  have  the  'sgio'  flag\nset.  The  6  byte variants of the SCSI READ and WRITE commands do not support the FUA\nbit.\n\nnocache\nuse posixfadvise() to advise corresponding file there is no need  to  fill  the  file\nbuffer with recently read or written blocks.\n\nnocreat\nthis  flag  is  only active in oflag=FLAGS. If present then OFILE will be opened if it\nexists. If OFILE doesn't exist then an error is generated. Without this flag a regular\n(empty)  file  named  OFILE  will be created (and then filled). For production quality\nscripts where OFILE is a device node (e.g. '/dev/sdc') this flag is  recommended.   It\nguards  against  the  remote possibility of 'dev/sdc' disappearing temporarily (e.g. a\nUSB memory key removed) resulting in a large regular file called '/dev/sdc' being cre‐\nated.\n\nnull   has no affect, just a placeholder.\n\nrandom this  flag  is  only  active with iflag= and when given replaces if=IFILE. If both are\ngiven an error is generated. The input will be a stream of pseudo  random  bytes.  The\nLinux getrandom(2) system call is used to create a seed and thereadter mrand48r(3) is\nused to generate a pseudo random sequence, 4 bytes at a time. The quality of the  ran‐\ndomness  can be viewed with the ent(1) utility. This is not a high quality random num‐\nber generator, it is built for speed, not quality. One  application  is  checking  the\ncorrectness of the copy and verify operations of this utility.\n\nsgio   causes  block  devices  to  be  accessed via the SGIO ioctl rather than standard UNIX\nread() and write() commands. When the SGIO ioctl is used the SCSI READ and WRITE com‐\nmands are used directly to move data. sg devices always use the SGIO ioctl. This flag\noffers finer grain control compared to the otherwise identical 'blksgio=1' option.\n\nsparse after each BS * BPT byte segment is read from the input, it is checked for  being  all\nzeros. If so, nothing is written to the output file unless this is the last segment of\nthe transfer. This flag is only active with the oflag option. It cannot be  used  when\nthe  output  is  not  seekable  (e.g.  stdout).  It  is  ignored if the output file is\n/dev/null .  Note that this utility does not remove the OFILE  prior  to  starting  to\nwrite  to it. Hence it may be advantageous to manually remove the OFILE if it is large\nprior to using oflag=sparse. The last segment is always written so regular files  will\nshow  the  same  length and so programs like md5sum and sha1sum will generate the same\nvalue regardless of whether oflag=sparse is given or not. This option may be used when\nthe  OFILE  is a raw device but is probably only useful if the device is known to con‐\ntain zeros (e.g. a SCSI disk after a FORMAT command).\n",
            "subsections": []
        },
        "RETIRED OPTIONS": {
            "content": "Here are some retired options that are still present:\n\nappend=0 | 1\nwhen set, equivalent to 'oflag=append'. When clear the action is to overwrite the  ex‐\nisting file (if it exists); this is the default.  See the 'append' flag.\n\nfua=0 | 1 | 2 | 3\nforce  unit access bit. When 3, fua is set on both IFILE and OFILE; when 2, fua is set\non IFILE;, when 1, fua is set on OFILE; when 0 (default), fua is cleared on both.  See\nthe 'fua' flag.\n",
            "subsections": []
        },
        "NOTES": {
            "content": "Block  devices  (e.g.  /dev/sda and /dev/hda) can be given for IFILE.  If neither '-iflag=di‐\nrect', 'iflag=sgio' nor 'blksgio=1' is given then normal block IO  involving  buffering  and\ncaching  is performed. If only '-iflag=direct' is given then the buffering and caching is by‐\npassed (this is applicable  to  both  SCSI  devices  and  ATA  disks).   If  'iflag=sgio'  or\n'blksgio=1' is given then the SGIO ioctl is used on the given file causing SCSI commands to\nbe sent to the device and that also bypasses most of the actions performed by the block layer\n(this  is only applicable to SCSI devices, not ATA disks). The same applies for block devices\ngiven for OFILE.\n\nVarious numeric arguments (e.g. SKIP) may include multiplicative  suffixes  or  be  given  in\nhexadecimal. See the \"NUMERIC ARGUMENTS\" section in the sg3utils(8) man page.\n\nThe COUNT, SKIP and SEEK arguments can take 64 bit values (i.e. very big numbers). Other val‐\nues are limited to what can fit in a signed 32 bit number.\n\nData usually gets to the user space in a 2 stage process: first the SCSI  adapter  DMAs  into\nkernel buffers and then the sg driver copies this data into user memory (write operations re‐\nverse this sequence).  This is called \"indirect IO\" and there is a  'dio'  option  to  select\n\"direct  IO\" which will DMA directly into user memory. Due to some issues \"direct IO\" is dis‐\nabled in the sg driver and needs a configuration change to activate  it.  This  is  typically\ndone with 'echo 1 > /proc/scsi/sg/allowdio'.\n\nAll  informative,  warning and error output is sent to stderr so that dd's output file can be\nstdout and remain unpolluted. If no options are given, then the usage message is  output  and\nnothing else happens.\n\nEven if READ LONG succeeds on a \"bad\" block when 'coe=2' (or 'coe=3') is given, the recovered\ndata may not be useful. There are no guarantees that the user data will appear \"as is\" in the\nfirst 512 bytes.\n\nA  raw  device must be bound to a block device prior to using sgdd.  See raw(8) for more in‐\nformation about binding raw devices. To be safe, the sg device mapping to SCSI block  devices\nshould be checked with 'cat /proc/scsi/scsi', or sgmap before use.\n\nDisk  partition information can often be found with fdisk(8) [the \"-ul\" argument is useful in\nthis respect].\n\nFor sg devices (and block devices when blksgio=1 is given) this utility issues SCSI READ and\nWRITE  (SBC)  commands  which  are  appropriate  for  disks and reading from CD/DVD/HD-DVD/BD\ndrives. Those commands are not formatted correctly for tape devices so sgdd  should  not  be\nused on tape devices. If the largest block address of the requested transfer exceeds a 32 bit\nblock number (i.e 0xffff) then a warning is issued and the sg device  is  accessed  via  SCSI\nREAD(16) and WRITE(16) commands.\n\nThe attributes of a block device (partition) are ignored when 'blksgio=1' is used. Hence the\nwhole device is read (rather than just the second partition) by this invocation:\n\nsgdd if=/dev/sdb2 blksgio=1 of=t bs=512\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "Looks quite similar in usage to dd:\n\nsgdd if=/dev/sg0 of=t bs=512 count=1MB\n\nThis will copy 1 million 512 byte blocks from the  device  associated  with  /dev/sg0  (which\nshould have 512 byte blocks) to a file called t.  Assuming /dev/sda and /dev/sg0 are the same\ndevice then the above is equivalent to:\n\ndd if=/dev/sda iflag=direct of=t bs=512 count=1000000\n\nalthough dd's speed may improve if bs was larger and count was suitably reduced. The  use  of\nthe  'iflag=direct' option bypasses the buffering and caching that is usually done on a block\ndevice.\n\nUsing a raw device to do something similar on a ATA disk:\n\nraw /dev/raw/raw1 /dev/hda\nsgdd if=/dev/raw/raw1 of=t bs=512 count=1MB\n\nTo copy a SCSI disk partition to an ATA disk partition:\n\nraw /dev/raw/raw2 /dev/hda3\nsgdd if=/dev/sg0 skip=10123456 of=/dev/raw/raw2 bs=512\n\nThis assumes a valid partition is found on the SCSI disk at  the  given  skip  block  address\n(past  the  5 GB point of that disk) and that the partition goes to the end of the SCSI disk.\nAn explicit count is probably a safer option. The partition is copied to /dev/hda3  which  is\nan  offset  into  the  ATA  disk /dev/hda . The exact number of blocks read from /dev/sg0 are\nwritten to /dev/hda (i.e. no padding).\n\nTo time a streaming read of the first 1 GB (2  30 bytes) on a disk this  utility  could  be\nused:\n\nsgdd if=/dev/sg0 of=/dev/null bs=512 count=2m time=1\n\nOn  completion this will output a line like: \"time to transfer data was 18.779506 secs, 57.18\nMB/sec\". The \"MB/sec\" in this case is 1,000,000 bytes per second.\n\nThe 'of2=' option can be used to copy data and take a md5sum of it without needing to re-read\nthe data:\n\nmkfifo fif\nmd5sum fif &\nsgdd if=/dev/sg3 iflag=coe of=sg3.img oflag=sparse of2=fif bs=512\n\nThis will image /dev/sg3 (e.g. an unmounted disk) and place the contents in the (sparse) file\nsg3.img . Without re-reading the data it will also perform a md5sum calculation on the image.\n",
            "subsections": []
        },
        "SIGNALS": {
            "content": "The signal handling has been borrowed from dd: SIGINT, SIGQUIT and SIGPIPE output the  number\nof  remaining  blocks to be transferred and the records in + out counts; then they have their\ndefault action.  SIGUSR1 causes the same information to be output  yet  the  copy  continues.\nAll output caused by signals is sent to stderr.\n",
            "subsections": []
        },
        "EXIT STATUS": {
            "content": "The exit status of sgdd is 0 when it is successful. Otherwise see the sg3utils(8) man page.\nSince this utility works at a higher level than individual commands, and there are 'coe'  and\n'retries' flags, individual SCSI command failures do not necessary cause the process to exit.\n\nAn  additional  exit  status  of  90  is  generated if the flock flag is given and some other\nprocess holds the advisory exclusive lock.\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "Written by Douglas Gilbert and Peter Allworth.\n",
            "subsections": []
        },
        "REPORTING BUGS": {
            "content": "Report bugs to <dgilbert at interlog dot com>.\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright © 2000-2021 Douglas Gilbert\nThis software is distributed under the GPL version 2. There is NO warranty; not even for MER‐\nCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "cmp(1)\n\nThere is a web page discussing sgdd at http://sg.danny.cz/sg/sgdd.html\n\nA  POSIX  threads  version of this utility called sgpdd is in the sg3utils package. Another\nversion from that package is called sgmdd and it uses memory mapped IO  to  speed  transfers\nfrom sg devices.\n\nThe  lmbench  package  contains  lmdd  which is also interesting. For moving data to and from\ntapes see dt which is found at http://www.scsifaq.org/RMillerTools/index.html\n\nTo change mode parameters that effect a SCSI device's caching  and  error  recovery  see  sd‐‐",
            "subsections": [
                {
                    "name": "parm(sdparm)",
                    "content": "To  verify  the  data  on  the  media or to verify it against some other copy of the data see\nsgverify(sg3utils)\n\nSee also raw(8), dd(1), ddrescue(GNU), ddpt\n\n\n\nsg3utils-1.46                               March 2021                                     SGDD(8)"
                }
            ]
        }
    },
    "summary": "sgdd - copy data to and from files and devices, especially SCSI devices",
    "flags": [
        {
            "flag": "-d",
            "long": "--dry-run",
            "arg": null,
            "description": "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."
        },
        {
            "flag": "-h",
            "long": "--help",
            "arg": null,
            "description": "outputs usage message and exits."
        },
        {
            "flag": "-p",
            "long": "--progress",
            "arg": null,
            "description": "this option 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."
        },
        {
            "flag": "-v",
            "long": "--verbose",
            "arg": null,
            "description": "when used once, this is equivalent to verbose=1. When used twice (e.g. \"-vv\") this is equivalent to verbose=2, etc."
        },
        {
            "flag": "-x",
            "long": "--verify",
            "arg": null,
            "description": "do a verify operation (like Unix command cmp(1)) rather than a copy. Cannot be used with \"oflag=sparse\". of=OFILE must be given and OFILE must be an sg device or a block device with \"oflag=sgio\" also given. Uses the SCSI VERIFY command with the BYTCHK field set to 1. The VERIFY command is used instead of WRITE when this option is given. There is no VERIFY(6) command. Stops on the first miscompare unless oflag=coe is given."
        },
        {
            "flag": "-V",
            "long": "--version",
            "arg": null,
            "description": "outputs version number information and exits."
        }
    ],
    "examples": [
        "Looks quite similar in usage to dd:",
        "sgdd if=/dev/sg0 of=t bs=512 count=1MB",
        "This will copy 1 million 512 byte blocks from the  device  associated  with  /dev/sg0  (which",
        "should have 512 byte blocks) to a file called t.  Assuming /dev/sda and /dev/sg0 are the same",
        "device then the above is equivalent to:",
        "dd if=/dev/sda iflag=direct of=t bs=512 count=1000000",
        "although dd's speed may improve if bs was larger and count was suitably reduced. The  use  of",
        "the  'iflag=direct' option bypasses the buffering and caching that is usually done on a block",
        "device.",
        "Using a raw device to do something similar on a ATA disk:",
        "raw /dev/raw/raw1 /dev/hda",
        "sgdd if=/dev/raw/raw1 of=t bs=512 count=1MB",
        "To copy a SCSI disk partition to an ATA disk partition:",
        "raw /dev/raw/raw2 /dev/hda3",
        "sgdd if=/dev/sg0 skip=10123456 of=/dev/raw/raw2 bs=512",
        "This assumes a valid partition is found on the SCSI disk at  the  given  skip  block  address",
        "(past  the  5 GB point of that disk) and that the partition goes to the end of the SCSI disk.",
        "An explicit count is probably a safer option. The partition is copied to /dev/hda3  which  is",
        "an  offset  into  the  ATA  disk /dev/hda . The exact number of blocks read from /dev/sg0 are",
        "written to /dev/hda (i.e. no padding).",
        "To time a streaming read of the first 1 GB (2  30 bytes) on a disk this  utility  could  be",
        "used:",
        "sgdd if=/dev/sg0 of=/dev/null bs=512 count=2m time=1",
        "On  completion this will output a line like: \"time to transfer data was 18.779506 secs, 57.18",
        "MB/sec\". The \"MB/sec\" in this case is 1,000,000 bytes per second.",
        "The 'of2=' option can be used to copy data and take a md5sum of it without needing to re-read",
        "the data:",
        "mkfifo fif",
        "md5sum fif &",
        "sgdd if=/dev/sg3 iflag=coe of=sg3.img oflag=sparse of2=fif bs=512",
        "This will image /dev/sg3 (e.g. an unmounted disk) and place the contents in the (sparse) file",
        "sg3.img . Without re-reading the data it will also perform a md5sum calculation on the image."
    ],
    "see_also": [
        {
            "name": "cmp",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/cmp/1/json"
        },
        {
            "name": "sgverify",
            "section": "sg3utils",
            "url": "https://www.chedong.com/phpMan.php/man/sgverify/sg3utils/json"
        },
        {
            "name": "raw",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/raw/8/json"
        },
        {
            "name": "dd",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/dd/1/json"
        },
        {
            "name": "ddrescue",
            "section": "GNU",
            "url": "https://www.chedong.com/phpMan.php/man/ddrescue/GNU/json"
        }
    ]
}