09/24/96, 4FAX# 4508 Determining Tape Block Size and Format SPECIAL NOTICES Information in this document is correct to the best of our knowledge at the time of this writing. Please send feedback by fax to "AIXServ Information" at (512) 823-4009. Please use this information with care. IBM will not be responsible for damages of any kind resulting from its use. The use of this information is the sole responsibility of the customer and depends on the customer's ability to eval- uate and integrate this information into the customer's operational environment. ABOUT THIS DOCUMENT The AIX Operating System supports tape devices with various block sizes. Tapes written at one particular physical block size may not be readable unless the tape device is reconfigured for that same block size. This document describes how to determine the correct physical block size and how to determine the tape format (such as tar or backup/restore) in all versions of AIX. BLOCK SIZE DETERMINATION You can find the tape block size by configuring the device to accept a very large block, performing a single read, and determining the size of the read block, as in the following steps: 1. Begin by configuring the device for variable block size data: chdev -a block_size=0 -l where is the device, such as rmt0 or rmt1. 2. Next, read a single block from the device and write the block to disk. This will allow you to see exactly how large the block is and what data is contained on the tape. dd if=/dev/ of=/tmp/block bs=128k count=1 3. The data from the tape block will be in the file /tmp/block. You can determine the block size by looking at the byte count with wc -c /tmp/block The size in bytes is the size of the physical blocks on the tape, assuming the tape was written with a single physical block size. 4. You can then use this size in the chdev command given above to configure the tape drive for the loaded tape. Determining Tape Block Size and Format 1 09/24/96, 4FAX# 4508 | Please Note: If you only need to determine the blocksize of | the archive and want to avoid creating the temporary file, | you can issue the following command: | dd if=/dv/ bs=128k count=1 | wc -c FORMAT DETERMINATION The "file" command can be used on the block of data that was read from the tape in the previous section (the /tmp/block file) to determine the format type of data on the tape. file /tmp/block The file command attempts to match header information in the file against known header types described in the /etc/magic file. After a change to the /etc/magic file (described below), the file command will recognize tar, cpio, and backup/restore formats. However, on AIX versions previous to 4.1 and later, the file command will not recognize format types that do not have header information, such as dd and back-by-inode. For example, if you used dd to put a compressed file on a tape and then followed the procedures in this document, the format would be recognized as compressed. Updating the /etc/magic file (not necessary for AIX 4.1 and later) To update the /etc/magic file so that tar and backup/restore formats can be recognized by the file command, do the fol- lowing: 1. Become the root user. 2. Make a backup copy of the /etc/magic file by running cp /etc/magic /etc/magic.backup 3. Add the following two lines to the bottom of the /etc/magic file. Note that each line must start in the first column. 257 string 0x7573746172 tar format file 0 long 0x09006bea backup/restore by name format file SHELL SCRIPT TO AUTOMATE BLOCK SIZE DETERMINATION This shell script provides a means of performing the block- size determination steps automatically. Determining Tape Block Size and Format 2 09/24/96, 4FAX# 4508 #!/bin/ksh # # lstape -- List a tape's block size # if [ $# -ne 1 ] ; then /usr/bin/echo 'usage: lstape device' exit 1 fi # # Check the name and put it in a standard format # if [[ "$1" = /dev/* ]]; then TAPE=${1##/dev/} else TAPE=$1 fi # # Set the block size to variable # /usr/sbin/chdev -l ${TAPE} -a block_size=0 >/dev/null if [ $? -ne 0 ]; then exit 1 fi # # Read a single block and write to /tmp # /usr/bin/dd if=/dev/${TAPE} bs=128k of=/tmp/lst$$ count=1 if [ $? -ne 0 ]; then /usr/bin/rm -f /tmp/lst$$ exit 1 fi # # Get the block size of the resultant file # /usr/bin/wc -c /tmp/lst$$ | read SIZE FILE /usr/bin/echo "$TAPE: ${SIZE} bytes per block." if [ -x /usr/bin/file ] ; then /usr/bin/file /tmp/lst$$ | sed -e "s!/tmp/lst$$!/dev/${TAPE}!" fi # # Set tape drive to correct physical block size # /usr/sbin/chdev -l ${TAPE} -a block_size=${SIZE} >/dev/null /usr/bin/rm -f /tmp/lst$$ exit 0 Determining Tape Block Size and Format 3 09/24/96, 4FAX# 4508 READER'S COMMENTS Please fax this form to (512) 823-4009, attention "AIXServ Informa- tion". You may also e-mail comments to: elizabet@austin.ibm.com. These comments should include the same customer information requested below. Use this form to tell us what you think about this document. If you have found errors in it, or if you want to express your opinion about it (such as organization, subject matter, appearance) or make sug- gestions for improvement, this is the form to use. If you need technical assistance, contact your local branch office, point of sale, or 1-800-CALL-AIX (for information about support offer- ings). These services may be billable. Faxes on a variety of sub- jects may be ordered free of charge from 1-800-IBM-4FAX. Outside the U.S. call 415-855-4329 using a fax machine phone. When you send comments to IBM, you grant IBM a nonexclusive right to use or distribute your comments in any way it believes appropriate without incurring any obligation to you. NOTE: If you have a problem report or item number, supplying that number may help us determine why a procedure did or did not work in your specific situation. Problem Report or Item #: Branch Office or Customer #: Be sure to print your name and fax number below if you would like a reply: Name: Fax Number: ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ ______________________________________________________________________ END OF DOCUMENT (tape.blksize.bak, 4FAX# 4508) Determining Tape Block Size and Format 4