Tuesday Dec 23, 2008

Reading random disk blocks with format

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

Monday Mar 19, 2007

Disk errors, fdisk and format

I had some problems upgrading this laptop to nv60 this weekend. First I managed to try it with the power lead not fully connected so instead of coming back to an upgraded system I came back to a flat battery.

Then the second attempt hung and the only clues were in the messages file:


Mar 18 09:39:09 principia gda: [ID 107833 kern.warning] WARNING: /pci@0,0/pci-ide@1f,1/ide@0/cmdk@0,0 (Disk0):
Mar 18 09:39:09 principia       Error for command 'read sector' Error Level: Fat
al
Mar 18 09:39:09 principia gda: [ID 107833 kern.notice]  Requested Block 62711776
, Error Block: 62711832
Mar 18 09:39:09 principia gda: [ID 107833 kern.notice]  Sense Key: uncorrectable
 data error
Mar 18 09:39:09 principia gda: [ID 107833 kern.notice]  Vendor 'Gen-ATA ' error
 code: 0x7

So I ran up format to see if I could use the analyse option to find the broken block and either repair it or add it to the defect list. So I get the current disk:


format> current
Current Disk = c0d0
<DEFAULT cyl 20031 alt 2 hd 32 sec 63>
/pci@0,0/pci-ide@1f,1/ide@0/cmdk@0,0

format> 

That the geometry is probably made up is not important. With those numbers there are 2016 sectors per cylinder which puts block 62711832 in cylinder 31107 on the disk. Moving so lets plug that into analyse ask it to do 2016 blocks so I test the whole “cylinder” and with luck I can move on. So go into the analyse menu:


analyze> setup
Analyze entire disk[yes]? no
Enter starting block number[0, 0/0/0]: 31107/0/0
`31107' is out of range.
Enter starting block number[0, 0/0/0]: 62711832
`31107/1/57' is out of range.
Enter starting block number[0, 0/0/0]: 

Well that is odd. Now I remember that this system will dual boot, could it be that format is using the Solaris partition and not the whole disk? Looking at the fdsik this would explain it:


             Total disk size is 38760 cylinders
             Cylinder size is 2016 (512 byte) blocks

                                               Cylinders
      Partition   Status    Type          Start   End   Length    %
      =========   ======    ============  =====   ===   ======   ===
          1                 IFS: NTFS         0  8319    8320     21
          2       Active    Solaris        18727  38759    20033     52
          3                 Solaris        8319  18395    10077     26

So the block must be in fdisk partition 2. Subtracting 18727 from 31107 gets me the relative offset in the Solaris partition of 13280 which in turn ends up being in the swap partition, which is the least inconvenient place as I can delete the swap run the analysis, which found nothing, and add the swap back.


I can't help thinking format should not behave like this, or at least have an option to use absolute addresses, perhaps it has and I don't know about it. Anyway roll on EFI.


Tags:

About

This is the old blog of Chris Gerhard. It has mostly moved to http://chrisgerhard.wordpress.com

Search

Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today