Skip to content

Reading random disk blocks with format

December 23, 2008

Occasionally it is useful to be able to read blocks from disks when there is no label on the disk. Since most applications won’t be able to open the device as you need to use O_NDELAY flag to the open system call.

Luckily it is possible to use format to read arbitrary disk blocks so you don’t have to resort to writing a special application. The trick is to use the read analysis option to format and then restrict the blocks that you want to read down to the the blocks that you are interested in. Then once read use the print buffer command to output the data:

# format  Searching for disks…done   AVAILABLE DISK SELECTIONS:        0. c0t0d0 <SUN9.0G cyl 4924 alt 2 hd 27 sec 133>           /pci@1f,4000/scsi@3/sd@0,0 Specify disk (enter its number): 0 selecting c0t0d0 [disk formatted] Warning: Current Disk has mounted partitions.   FORMAT MENU:         disk       – select a disk         type       – select (define) a disk type         partition  – select (define) a partition table         current    – describe the current disk         format     – format and analyze the disk         repair     – repair a defective sector         label      – write label to the disk         analyze    – surface analysis         defect     – defect list management         backup     – search for backup labels         verify     – read and display labels         save       – save new disk/partition definitions         inquiry    – show vendor, product and revision         volname    – set 8-character volume name         !<cmd>     – execute <cmd>, then return         quit format> ana   ANALYZE MENU:         read     – read only test   (doesn’t harm SunOS)         refresh  – read then write  (doesn’t harm data)         test     – pattern testing  (doesn’t harm data)         write    – write then read      (corrupts data)         compare  – write, read, compare (corrupts data)         purge    – write, read, write   (corrupts data)         verify   – write entire disk, then verify (corrupts data)         print    – display data buffer         setup    – set analysis parameters         config   – show analysis parameters         !<cmd>   – execute <cmd> , then return         quit analyze> set Analyze entire disk[yes]? no Enter starting block number[0, 0/0/0]: 0 Enter ending block number[0, 0/0/0]: 0 Loop continuously[no]?  Enter number of passes[2]: 1 Repair defective blocks[yes]?  Stop after first error[no]? yes Use random bit patterns[no]?  Enter number of blocks per transfer[1, 0/0/1]:  Verify media after formatting[yes]?  Enable extended messages[no]?  Restore defect list[yes]?  Restore disk label[yes]?   analyze> read Ready to analyze (won’t harm SunOS). This takes a long time,  but is interruptable with CTRL-C. Continue? y          pass 0    0/0/0    Total of 0 defective blocks repaired. analyze> print 0x53554e39  0x2e304720  0x63796c20  0x34393234  0x20616c74  0x20322068   0x64203237  0x20736563  0x20313333  0x00000000  0x00000000  0x00000000   0x00000000  0x00000000  0x00000000  0x00000000  0x00000000  0x00000000   0x00000000  0x00000000  0x00000000  0x00000000  0x00000000  0x00000000   0x00000000  0x00000000  0x00000000  0x00000000  0x00000000  0x00000000   0x00000000  0x00000000  0x00000001  0x00000000  0x00000000  0x00080002   0x00000003  0x00010005  0x00000000  0x00010000  0x00010000  0x00010000   0x00010000  0x00010000  0x00000000  0x00000000  0x00000000  0x600ddeee   0x00000000  0x00000000  0x00000000  0x00000000  0x00000000  0x00000000   0x00000000  0x00000000  0x00000000  0x00000000  0x00000000  0x00000000   0x00000000  0x00000000  0x00000000  0x00000000  0x00000000  0x00000000   0x00000000  0x00000000  0x00000000  0x00000000  0x00000000  0x00000000   0x00000000  0x00000000  0x00000000  0x00000000  0x00000000  0x00000000   0x00000000  0x00000000  0x00000000  0x00000000  0x00000000  0x00000000   0x00000000  0x00000000  0x00000000  0x00000000  0x00000000  0x00000000   0x00000000  0x00000000  0x00000000  0x00000000  0x00000000  0x00000000   0x00000000  0x00000000  0x00000000  0x00000000  0x00000000  0x00000000   0x00000000  0x00000000  0x00000000  0x1518133e  0x00000000  0x00000001   0x133c0002  0x001b0085  0x00000000  0x00000000  0x00fdc0a1  0x00001217   0x00100e03  0x00000000  0x010dcea4  0x00000000  0x00000000  0x00000000   0x00000000  0x00000000  0x00000000  0x00000000  0x00000000  0x00000000   0x00000000  0xdabe5344   analyze> 


Now I know those at the back will recongise this as a Solaris SPARC disk label. With vtoc, that give away VTOC_SANITY values of 0x600ddee being in the middle after the ASCII label

Advertisements

From → Solaris

2 Comments
  1. UX-admin permalink

    Holy smokes, I got nostalgia reading this…
    But, wouldn’t it have been easier to just use:
    dd if=/dev/rdsk/c#t#d#s2 of=/var/tmp/c#t#d#s2.dump bs=1024 count=1
    And then use a hex editor, or even a small AWK script to decode the dump?
    Speaking of which, do you know of any good hex editors on Solaris?

  2. Well dd would be good but if the disk has no label you can’t open it without using O_NDELAY and dd does not. An RFE that needs logging.
    As to a hex editor, ghex is not terrible even if I would like it to include a disassembler as well.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: