Skip to content

Instantly share code, notes, and snippets.

@paulreece42
Last active November 3, 2025 15:40
Show Gist options
  • Select an option

  • Save paulreece42/ef5afebe64a935e3dcafef4eaa75bce4 to your computer and use it in GitHub Desktop.

Select an option

Save paulreece42/ef5afebe64a935e3dcafef4eaa75bce4 to your computer and use it in GitHub Desktop.
Notes for working with LTO tape

So, "Why Tape!?"

Or: "I thought tape was dead?"

Me too, before I started using it just recently, in the Year of our Lord, 2025, and absolutely fell in love with it

Consider the following:

  • As of today (2025-05-25), a petabyte of LTO-8 tape costs about as much as the tape drive to read/write it (~$6k USD), and can last "up to" 30 years
    • even at a conservative 15-year life, this gives a storage cost like $0.03 per TB/month. S3 is $22 per TB/month, last I checked
  • decent read/write speeds, over a gigabit easily
  • LTO tape reads and verifies as it is writing data and also contains error correction mechanisms
  • cold/offline storage has its drawbacks, but also its advantages:
    • cannot be randomware-d, being offline (especially with convenient, physical, read-only toggle switches, on the tapes themselves)
    • also if it is truly offline, hackers can't read it
    • greedy companies trying to train their AI on your data also can't read it!
  • still in use by national labs and CERN, in the hundreds of petabytes range (and presumably many other large businesses, just: those ones are public, and thus easily Google-able)
Just my personal, quick and dirty notes
A tape LIBRARY or changer contains one or more tape DRIVES and they are addressed/used independently of one another (mostly)
`mt` command is for tape drive(s)
`mtx` command is for tape library/changer
The library has the robot arm for moving tapes around, and slots for storage. The drives are... well, the drives. Like a VCR, for data. I guess then the library is like the Blockbuster. But for data.
Danger: tape is easy to accidentally overwrite! Especailly if you simply access the /dev/st0 auto-rewinding device, instead of the /dev/nst0 non-auto-rewinding device!
It will rewind your tape, and other stuff already writing to it... can keep writing to it, not realizing it's been rewound!
Poof, flagrant tape error, data over = very yes!
Tapes contain very useful physical switches to make them read-only... use them! Just slide it over, and the tape will become read-only, like the floppy disks in the old days had
I often do this when keeping tapes in the library. This way, even if someone wanted to maliciously destroy data, they could not, without going down and physically sliding over the read-only switches on the tapes
Tape libraries additionally have I/O bays, usually a small module of x tapes, that slides out. This is how you take tapes into and out of the library, and how libraries move tapes to other libraries (within the same rack, up and down)
Tape is sensitive to temp/humidity changes, and should be left to acclimate to the environment it's in before use
(Several hours if say, it was frozen. Don't freeze your tapes! Keep them climate controlled, 64-74F, 20%-50% RH)
Tape should be stored vertically, long-term, for archival. Pulled every 3-5 years and verified or re-tensioned.
Useful commmands:
`lsscsi -g`
`mtx status` - get status of tape library
`mtx -f /dev/sg1 status`
# load and unload slot 27 to/from drive 0
# NOTE: drive order in mtx may not match SCSI order! Check with sg_logs below and
# match by tape label
mtx -f /dev/sg1 load 27 0
mtx -f /dev/sg1 unload 27 0
`sg_logs -p 0x17 /dev/sg2`
mtx -f /dev/sg1 eepos 0 transfer 29 27
tapestat --human 1
mt -f /dev/nst1 status # status of tape drive (not library, that's mtx)
mt -f /dev/nst1 rewind # rewind to beginning
mt -f /dev/nst1 fsf 1 # move forward 1 file
mt -f /dev/nst1 eod # end of data
mt -f /dev/nst0 rewoffl # rewind offline
tapeinfo -f /dev/sg1
LTFS exists, and should be used, it rocks so far in my experience. I think there's an IBM version, a HPE version, and a open source version that are all slightly different maybe? (need to investigate further)
https://github.com/LinearTapeFileSystem/ltfs
Also download and use "IBM Tape Diagnostic Tool" for IBM drives
#!/bin/bash
#
# Super purpose-built for some tapes written in a very unusual way;
# this will be useless to you, as it is written
#
DRIVEBAY=1
DRIVEDEV=/dev/nst0
CHANGER=/dev/sg1
while :; do
# load first exp tape
NEXTEXP=`mtx -f ${CHANGER} status | grep -P 'Storage Element [0-9]{1,2}:Full' | grep EXP | awk -F ":" '{print $1}' | awk '{print $NF}' | head -1`
echo "loading slot ${NEXTEXP} into drive ${DRIVEBAY}..."
mtx -f /dev/sg1 load ${NEXTEXP} ${DRIVEBAY}
if [ $? -ne 0 ] ; then
break;
exit 2;
fi
echo "ok"
sleep 10
cd /scratch/foo
#tar -xOf /dev/st0 | for i in {1..35} ; do tar -xv --zstd --skip-old-files ; sleep 10 ; done; # doesn't work
tar -xf ${DRIVEDEV} --to-command="tar -xv --zstd --skip-old-files"
mt -f ${DRIVEDEV} offline
sleep 10
mt -f ${DRIVEDEV} eject
sleep 10
EXPORT=`mtx -f ${CHANGER} status | grep 'IMPORT/EXPORT:Empty' | head -1 | awk '{print $3}'`
echo "sending drive ${DRIVEBAY} to slot ${EXPORT}..."
mtx -f ${CHANGER} unload ${EXPORT} ${DRIVEBAY}
if [ $? -ne 0 ] ; then
break;
exit 2;
fi
echo "tape sent to bay ${EXPORT}"
echo "tape sent to bay ${EXPORT}" | mail -s "tape sent to bay ${EXPORT}" myemail@domain.com
sleep 300
done
Tape drives are generally at least one version backwards compatible. Older tape drives were 2 versions backwards compatible. Charts
can be found of this, on Google, for example sometimes it could read 2 or more versions backwards but not write, etc
LTO-7 M8 tapes are a thing, Google it. Basically a LTO-7 tape, formatted as LTO-8?
Found a lot of complaints on Reddit about LTO-9. It reads to me like they may have fit the tolerances too tight.
Unlike older LTO tape, LTO-9 needs to be initialized before use, and seems extremely sensitive (moreso than usual)
to humidity and temperature changes
LTO-9 also has an archival mode, where it stores the tape with less tension
Some of these advanced commands like "archival mode" are only possible with the drive manufacturer's tools, such as:
IBM Tape Diagnostic Tool (Google it, links change)
Dell stopped offering LTO tapes/products in the North American market at End of April, 2025. Leaving just Magstor, IBM, HPE, and Quantum
Magstor are a very helpful small business, based in Columbus, Ohio! They can support Dell's stuff, after Dell has abandoned it,
it seems (at least, while used parts last, but supporting old tape seems to be their "thing" which I think is just awesome)
#!/bin/bash
#
# Take all the tapes from IMPORT/EXPORT and put them in
# empty bays
#
# Used with a Dell ML3 library, YMMV
#
CHANGER=/dev/sg1
mtx -f ${CHANGER} status
for i in `mtx -f ${CHANGER} status | grep IMPORT/EXPORT:Full | awk '{print $3}'` ; do
FREEBAY=`mtx -f ${CHANGER} status | grep -P 'Storage Element [0-9]{1,2}:Empty' | head -1 | awk -F ":" '{print $1}' | awk '{print $NF}'`
echo -n "${i} -> ${FREEBAY}"...
mtx -f ${CHANGER} eepos 0 transfer ${i} ${FREEBAY}
echo "done"
sleep 2
done
mtx -f ${CHANGER} status
#!/bin/bash
#
# usage: /usr/local/bin/tapefull.sh
#
# Gets what % of the tape has been written
# using low-level SCSI commands to measure the internal
# RFID/NFC of the tape
#
TAPE_DRIVES=`lsscsi -g | grep tape | awk '{print $NF}'`
CHANGER=`lsscsi -g | grep -i mediumx | awk '{print $NF}' | tail -1`
for DRIVE in $TAPE_DRIVES; do
echo ""
echo "${DRIVE} "
lsscsi -g | grep ${DRIVE}
stenc -f ${DRIVE} --detail | grep '^Drive Encryption'
sg_logs -p 0x17 ${DRIVE} > /tmp/$$.buf
cat /tmp/$$.buf | grep "Volume barcode"
cat /tmp/$$.buf | grep "Volume serial number"
cat /tmp/$$.buf | grep Total | grep capacity | awk '{print $NF}' | tr '\n' ' ' | awk '{print $2 " MB out of " $1 " MB "}'
cat /tmp/$$.buf | grep Total | grep capacity | awk '{print $NF}' | tr '\n' ' ' | awk '{printf "%.2f%% full\n\n", $2 / $1 * 100}'
cat /tmp/$$.buf | grep -P '(Last mount megabytes read|Total used native capacity)' | awk '{print $NF}' | tr '\n' ' ' | awk '{printf "%.2f%% read this mount\n", $1 / $2 * 100}'
rm -f /tmp/$$.buf
done
# Just hard-coding this for now
echo ""
echo "---"
mtx -f $CHANGER status
@paulreece42
Copy link
Author

This is basically just a dump of all my purpose-built, quick and dirty scripts related to tape drives/libraries

Should be used with caution etc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment