SG_SANITIZE(8)
π SG_SANITIZE(8) π
okay bestie, this is the sg_sanitize(8) page from SG3_UTILS π and it's all about wiping a disk properly π§Ήβ¨
β¨ NAME β¨
sg_sanitize β remove all user data from disk with the SCSI SANITIZE command π
β¨ SYNOPSIS β¨
sg_sanitize [--ause] [--block] [--count=OC] [--crypto] [--dry-run]
[--desc] [--early] [--fail] [--help] [--invert] [--ipl=LEN]
[--overwrite] [--pattern=PF] [--quick] [--test=TE] [--timeout=SECS]
[--verbose] [--version] [--wait] [--zero] [--znr] DEVICE
β¨ DESCRIPTION β¨
okay so this utility invokes the SCSI SANITIZE command π«Ά It was first introduced in the SBC-3 revision 27 draft. The whole point of sanitize is to change the info in the cache and on the medium of a logical unit (like a disk) so that recovering user data is not possible π If that user data can't be erased, or is in the middle of being erased, the sanitize operation blocks access to it. no cap, that's iconic.
Once a SCSI SANITIZE command has successfully started, user data from that disk is no longer available π Even if the disk gets power cycled, the sanitize operation keeps going after power comes back until it's complete. it's giving persistent π₯
This utility needs one of the --block, --crypto, --fail or --overwrite options. With --block, --crypto or --overwrite, the user gets 15 seconds to reconsider whether they really want to erase everything on a disk π unless --quick is given, in which case the sanitize starts immediately. The disk's INQUIRY response strings get printed out just in case you gave the wrong DEVICE, bestie π«£
If --early is given, this utility exits soon after starting the SANITIZE command with the IMMED bit set. You can keep an eye on progress with sg_requests --num=9999 --progress, which sends a REQUEST SENSE command every 30 seconds β¨ Otherwise, if --wait is given, the utility waits until the SANITIZE command completes (or fails), and that can be many hours π₯²
If --wait is not given, the SANITIZE command is started with the IMMED bit set. If neither --early nor --wait is given, this utility sends a REQUEST SENSE command every 60 seconds until there are no more progress indications, and then it exits silently π€« If --verbose is also given, the exit gets marked by a short message saying the sanitize seems to have succeeded π
β¨ OPTIONS β¨
Arguments to long options are mandatory for short options as well. The options are arranged in alphabetical order based on the long option name π
-A,--auseβ sets the AUSE bit in the cdb. AUSE stands for "allow unrestricted sanitize exit" π¦ The default is to leave the AUSE bit cleared.-B,--blockβ performs a "block erase" sanitize operation π§±-c,--count=OCβOCis the "overwrite count" for the "overwrite" sanitize operation. It can be anywhere from 1 to 31, and 1 is the default π’-C,--cryptoβ performs a "cryptographic erase" sanitize operation π This one is often super quick, because it just overwrites an internal cryptographic key with a new value. Those keys aren't accessible to users, and they encrypt all data written and decrypt all data read from the media. The main reason for doing it that way is to make the operation fast β‘ This operation can not be reversed. π-d,--descβ sets the DESC field in the REQUEST SENSE command used for polling. By default this field is set to zero πΈ A REQUEST SENSE polling loop runs after the SANITIZE command is issued (as long as neither--earlynor--waitwas given) to check on progress, because this can take some time β³-D,--dry-runβ parses the command line and does all the prep, but skips the actual SANITIZE command π§ͺ-e,--earlyβ by default, this utility polls the disk every 60 seconds to fetch the progress indication until the sanitize is finished π°οΈ When you give this option, the utility exits "early" as soon as the SANITIZE command with the IMMED bit set to 1 has been acknowledged πββοΈ This option and--waitcannot both be given. π ββοΈ-F,--failβ performs an "exit failure mode" sanitize operation π¨ This typically requires the preceding SANITIZE command to have set the AUSE bit π-h,--helpβ prints the usage information, then exits π-i,--ipl=LENβ sets the initialization pattern length toLENbytes β¨ By default it's the length of the pattern file (PF), or 4 if--zerois given. This only matters when--overwriteis also given. It's the number of bytes from thePFfile used as the initialization pattern (if--zeroisn't given). The minimum is 1 byte, and the maximum is the logical block size of theDEVICE(and it must not exceed 65535). IfLENis bigger than thePFfile, the pattern gets padded with zeros π§Έ-I,--invertβ sets the INVERT bit in the overwrite service action parameter list π This only affects the "overwrite" sanitize operation. The default is a clear INVERT bit. When INVERT is set, the initialization pattern is inverted between consecutive overwrite passes πͺ-O,--overwriteβ performs an "overwrite" sanitize operation ποΈ When you give this option, you need either--pattern=PFor--zeroπ-p,--pattern=PFβPFis the filename of a file containing the initialization pattern needed by an "overwrite" sanitize operation π The length of this file is used as the pattern length unless--ipl=LENis given. The pattern length must be from 1 up to the logical block size of theDEVICEπ―-Q,--quickβ the default (when this option isn't given) is to give the user 15 seconds to reconsider doing a sanitize on theDEVICE. When you give--quick, that 15 second warning period gets skipped ποΈ-T,--test=TEβ sets the TEST field in the overwrite service action parameter list π§ͺ This only affects the "overwrite" sanitize operation. The default is to put 0 in that field 0οΈβ£-t,--timeout=SECSβSECSis the number of seconds used for the timeout on the SANITIZE command β²οΈ-v,--verboseβ increases the level of verbosity (i.e. debug output) π-V,--versionβ prints the version string, then exits π·οΈ-w,--waitβ the default (i.e. without this option and without--early) is to start the SANITIZE command with the IMMED bit set, then poll for progress with the REQUEST SENSE command until the sanitize is complete (or has failed) π When you give this option (and not--early), the SANITIZE command is started with the IMMED bit clear. For a large disk this might take hours π΄ [A cryptographic erase operation could potentially be very quick.] π-z,--zeroβ with an "overwrite" sanitize operation, this makes the initialization pattern zero (4 zeros are used as the initialization pattern) 0οΈβ£ Can't be used with--pattern=PFπ ββοΈ If you give this option twice (e.g.'-zz'), then0xffis used as the initialization byte π-Z,--znrβ sets the ZNR bit (zoned no reset) in the cdb π Introduced in the SBC-4 revision 7 draft π
β¨ EXAMPLES β¨
okay so these examples use Linux device names π§ for other supported Operating Systems, check out the sg3_utils(8) man page for the right device names π
as a precaution π‘οΈ if you call this utility with no options, it just prints a usage message and that's it. nothing happens, bestie π
sg_sanitize /dev/sdm
to do a "block erase" sanitize you NEED the --block option π₯ you get a 15 second window to reconsider (very generous of it π₯Ί). then the SCSI SANITIZE command starts with the IMMED bit set, and this utility keeps polling for progress with REQUEST SENSE until the sanitize is finished π
sg_sanitize --block /dev/sdm
want to start a "block erase" sanitize and bounce back from this utility once it has started (but not finished yet)? use --early π¦
sg_sanitize --block --early /dev/sdm
if you don't need that 15 second reconsideration time, add --quick β‘
sg_sanitize --block --quick --early /dev/sdm
to do an "overwrite" sanitize you can hand it a pattern file π
sg_sanitize --overwrite --pattern=rand.img /dev/sdm
if "rand.img" is 512 bytes (a typical logical block size π) and you only want the first 17 bytes, used over and over, in the "overwrite" sanitize, add --ipl=17 π§
sg_sanitize --overwrite --pattern=rand.img --ipl=17 /dev/sdm
and to overwrite with zeros π€ use:
sg_sanitize --overwrite --zero /dev/sdm
β¨ EXIT STATUS β¨
the exit status of sg_sanitize is 0 when it works π otherwise check the sg3_utils(8) man page for the other codes π
unless you gave the --wait option, the exit status might not tell you whether the sanitize actually succeeded or not π¬
the Unix vibe is "no news is good news" π° but that can be a lil unnerving after something like sanitize, especially if it finishes super fast (before the first progress poll is even sent) π giving --verbose once should add enough extra output to calm those nerves π«Ά
β¨ AUTHORS β¨
written by Douglas Gilbert π
β¨ REPORTING BUGS β¨
report bugs to <dgilbert at interlog dot com> π¬
β¨ COPYRIGHT β¨
Copyright Β© 2011-2020 Douglas Gilbert πΈ this software is distributed under a BSD-2-Clause license π there is NO warranty, not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE π
β¨ SEE ALSO β¨
sg_requests(8), sg_format(8) π
bestie, that's the whole page π it's from sg3_utils version 1.46, dated December 2020 π stay iconic and sanitize responsibly π§β¨
π¦ where this page comes from
- alpine 3.24: sg3_utils-doc 1.48-r0 Β· BSD-2-Clause AND GPL-2.0-or-later
- arch rolling: sg3_utils 1.49-1 Β· GPL-2.0-or-later AND BSD-2-Clause
- centos-stream 10: sg3_utils 1.48-11.el10 Β· GPL-2.0-or-later AND BSD-2-Clause
- debian trixie: sg3-utils 1.48-3~deb13u1
- fedora 43: sg3_utils 1.48-10.fc43 Β· GPL-2.0-or-later AND BSD-2-Clause
- fedora 43: sg3_utils 1.48-6.fc43 Β· GPL-2.0-or-later AND BSD-2-Clause
- fedora 44: sg3_utils 1.48-10.fc44 Β· GPL-2.0-or-later AND BSD-2-Clause
- fedora 44: sg3_utils 1.48-8.fc44 Β· GPL-2.0-or-later AND BSD-2-Clause
- nixos 26.05: sg3_utils 1.48
- nixpkgs unstable: sg3_utils 1.49
- ubuntu questing: sg3-utils 1.48-2ubuntu1
- ubuntu resolute: sg3-utils 1.48-3ubuntu3
- ubuntu resolute: sg3-utils 1.48-3ubuntu3.2
- ubuntu stonking: sg3-utils 1.48-3ubuntu5
- π girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms