SG_SANITIZE(8)

πŸ“¦
version 1.49 Β· 3 versions
, in alpine 3.24, arch rolling, centos-stream 10, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– 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 β€” OC is 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 --early nor --wait was 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 --wait cannot 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 to LEN bytes ✨ By default it's the length of the pattern file (PF), or 4 if --zero is given. This only matters when --overwrite is also given. It's the number of bytes from the PF file used as the initialization pattern (if --zero isn't given). The minimum is 1 byte, and the maximum is the logical block size of the DEVICE (and it must not exceed 65535). If LEN is bigger than the PF file, 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=PF or --zero πŸ“
  • -p, --pattern=PF β€” PF is 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=LEN is given. The pattern length must be from 1 up to the logical block size of the DEVICE 🎯
  • -Q, --quick β€” the default (when this option isn't given) is to give the user 15 seconds to reconsider doing a sanitize on the DEVICE. 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 β€” SECS is 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'), then 0xff is 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 Β© 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