Saturday, January 4, 2014

Unix - Disk Management

Identifying the harddisks installed

  • Listing all the disks and drives attached to the system

    # camcontrol devlist    (or, atacontrol list)
    
    at scbus2 target 0 lun 0 (ada0,pass0)
    at scbus3 target 0 lun 0 (cd0,pass1)

  • Listing harddisks detected during the system bootup

    # dmesg | grep ad 
    
    ada0 at ata4 bus 0 scbus2 target 0 lun 0
    ada0:  ATA-8 SATA 2.x device
    ada0: 300.000MB/s transfers (SATA 2.x, UDMA5, PIO 8192bytes)
    ada0: 238418MB (488281250 512 byte sectors: 16H 63S/T 16383C)
    ada0: Previously was known as ad4
    Trying to mount root from ufs:/dev/ada0p2 [rw]...

  • Listing harddisks and their partitions

    # ls /dev | grep ad
    
    ad4
    ad4p1
    ad4p2
    ad4p3
    ada0
    ada0p1
    ada0p2
    ada0p3

  • Listing hardware level information of a harddisks

    # diskinfo -c ada0
    ada0
       512             # sectorsize
       250000000000    # mediasize in bytes (232G)
       488281250       # mediasize in sectors
       0               # stripesize
       0               # stripeoffset
       484406          # Cylinders according to firmware.
       16              # Heads according to firmware.
       63              # Sectors according to firmware.
       WD-WMAV12345678 # Disk ident.
    
    I/O command overhead:
       time to read 10MB block      0.124816 sec = 0.006 msec/sector
       time to read 20480 sectors   2.126440 sec = 0.104 msec/sector
       calculated command overhead               = 0.098 msec/sector
    

  • #fdisk ada0

    ******* Working on device /dev/ada0 *******
    parameters extracted from in-core disklabel are:
    cylinders=484521 heads=16 sectors/track=63 (1008 blks/cyl)
    
    Figures below won't work with BIOS for partitions not in cyl 1
    parameters to be used for BIOS calculations are:
    cylinders=484521 heads=16 sectors/track=63 (1008 blks/cyl)
    
    Media sector size is 512
    Warning: BIOS sector numbering starts with sector 1
    Information from DOS bootblock is:
    The data for partition 1 is:
    sysid 238 (0xee),(EFI GPT)
        start 1, size 488397167 (238475 Meg), flag 80 (active)
     beg: cyl 0/ head 1/ sector 1;
     end: cyl 1023/ head 255/ sector 63
    

Identifying the harddisk partitions

  • Identifying basic information about harddisk partitions

    # gpart show
    
    =>       34  488281183  ada0  GPT  (232G)
             34        128     1  freebsd-boot  (64k)
            162  478150528     2  freebsd-ufs  (228G)
      478150690    8388608     3  freebsd-swap  (4.0G)
      486539298    1741919        - free -  (850M)
    

  • Displaying detailed information of harddisk partitions

    # gpart list
    
    Geom name: ada0
    modified: false
    state: OK
    fwheads: 16
    fwsectors: 63
    last: 488281216
    first: 34
    entries: 128
    scheme: GPT
    Providers:
    1. Name: ada0p1
       Mediasize: 65536 (64k)
       Sectorsize: 512
       Stripesize: 0
       Stripeoffset: 17408
       Mode: r0w0e0
       rawuuid: 740aff84-9a1e-11e3-b778-002219173177
       rawtype: 83bd6b9d-7f41-11dc-be0b-001560b84f0f
       label: (null)
       length: 65536
       offset: 17408
       type: freebsd-boot
       index: 1
       end: 161
       start: 34
    2. Name: ada0p2
       Mediasize: 244813070336 (228G)
       Sectorsize: 512
       Stripesize: 0
       Stripeoffset: 82944
       Mode: r1w1e1
       rawuuid: 740b80b0-9a1e-11e3-b778-002219173177
       rawtype: 516e7cb6-6ecf-11d6-8ff8-00022d09712b
       label: (null)
       length: 244813070336
       offset: 82944
       type: freebsd-ufs
       index: 2
       end: 478150689
       start: 162
    3. Name: ada0p3
       Mediasize: 4294967296 (4.0G)
       Sectorsize: 512
       Stripesize: 0
       Stripeoffset: 17408
       Mode: r1w1e0
       rawuuid: 740eaebd-9a1e-11e3-b778-002219173177
       rawtype: 516e7cb5-6ecf-11d6-8ff8-00022d09712b
       label: (null)
       length: 4294967296
       offset: 244813153280
       type: freebsd-swap
       index: 3
       end: 486539297
       start: 478150690
    Consumers:
    1. Name: ada0
       Mediasize: 250000000000 (232G)
       Sectorsize: 512
       Mode: r2w2e3
    

  • df -h
    
    Filesystem      Size    Used   Avail Capacity  Mounted on
    /dev/ada0p2     220G    7.6G    195G     4%    /
    devfs           1.0k    1.0k      0B   100%    /dev
    nfsServer:/home 435G     15G    420G     3%    /usr/home
    

Mounting and unmounting external drives

For a USB memory stick,
  • # mount -t msdosfs /dev/da0s1 /tmp/usb
  • # umount /tmp/usb
While inserting a USB memory stick, a notification on the console will indicate the new device location like /dev/da0. But, you have to find the active partition of the drive like /dev/da0s1 to mount (# ls /dev | grep da could be used).


Note: Unix commands and file locations used here have been tested on FreeBSD systems.