Friday 23 December 2016

Set Timezone - Solaris 11

To get the current set timezone:
svccfg -s timezone:default listprop timezone/localtime
To set the timezone:
# svccfg -s timezone:default setprop timezone/localtime = Europe/London
# svcadm refresh timezone

Wednesday 14 December 2016

Breaking a ZFS mirror - Solaris 11

So you've mirrored your system disk wrongly! This is how you would break it and fix the problem before re-mirroring:
root@solaris11server:~$ zpool status
  pool: rpool
 state: ONLINE
status: The pool is formatted using an older on-disk format. The pool can
        still be used, but some features are unavailable.
action: Upgrade the pool using 'zpool upgrade'. Once this is done, the
        pool will no longer be accessible on older software versions.
  scan: resilvered 108G in 20m20s with 0 errors on Fri Dec  2 10:16:44 2016

config:

        NAME                         STATE     READ WRITE CKSUM
        rpool                        ONLINE       0     0     0
          mirror-0                   ONLINE       0     0     0
            c0t5000CCA0166ED0ECd0s0  ONLINE       0     0     0
            c0t5000CCA0166F8C50d0    ONLINE       0     0     0

errors: No known data errors
Added mirror as disk not slice. Turned disk into an EFI/GPT tabled disk. Using format and selecting the disk gives this messsage:
selecting c0t5000CCA0166F8C50d0
[disk formatted]
/dev/dsk/c0t5000CCA0166F8C50d0s0 is part of active ZFS pool rpool. Please see zpool(1M).
Reading the primary EFI GPT label failed.  Using backup label.
Use the 'backup' command to restore the primary label.
Do we use the back command? Don't know. We must break the mirror first though - using zpool detach:
root@solaris11server:~# zpool detach rpool c0t5000CCA0166F8C50d0
root@solaris11server:~# zpool status
  pool: rpool
 state: ONLINE
status: The pool is formatted using an older on-disk format. The pool can
        still be used, but some features are unavailable.
action: Upgrade the pool using 'zpool upgrade'. Once this is done, the
        pool will no longer be accessible on older software versions.
  scan: resilvered 108G in 20m20s with 0 errors on Fri Dec  2 10:16:44 2016

config:

        NAME                       STATE     READ WRITE CKSUM
        rpool                      ONLINE       0     0     0
          c0t5000CCA0166ED0ECd0s0  ONLINE       0     0     0

errors: No known data errors
Now look at the partition map on our good disk:
root@solaris11server:~# prtvtoc /dev/rdsk/c0t5000CCA0166ED0ECd0s0
* /dev/rdsk/c0t5000CCA0166ED0ECd0s0 (volume "solaris") partition map
*
* Dimensions:
*     512 bytes/sector
*     625 sectors/track
*      20 tracks/cylinder
*   12500 sectors/cylinder
*   46875 cylinders
*   46873 accessible cylinders
*
* Flags:
*   1: unmountable
*  10: read-only
*
* Unallocated space:
*       First     Sector    Last
*       Sector     Count    Sector
*           0     12500     12499
*
*                          First     Sector    Last
* Partition  Tag  Flags    Sector     Count    Sector  Mount Directory
       0      2    00      12500 585900000 585912499
       2      5    01          0 585912500 585912499
And compare it with our bad disk:
root@solaris11server:~# prtvtoc /dev/rdsk/c0t5000CCA0166F8C50d0s0
* /dev/rdsk/c0t5000CCA0166F8C50d0s0 partition map
*
* Dimensions:
*     512 bytes/sector
* 585937500 sectors
* 585937433 accessible sectors
*
* Flags:
*   1: unmountable
*  10: read-only
*
* Unallocated space:
*       First     Sector    Last
*       Sector     Count    Sector
*          34       222       255
*
*                          First     Sector    Last
* Partition  Tag  Flags    Sector     Count    Sector  Mount Directory
       0      4    00        256 585920827 585921082
       8     11    00  585921083     16384 585937466
So let us label our bad disk with the proper SMI label - not the EFI one:
root@solaris11server:~# format -e /dev/rdsk/c0t5000CCA0166F8C50d0
selecting /dev/rdsk/c0t5000CCA0166F8C50d0
[disk formatted]


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
        inquiry    - show disk ID
        scsi       - independent SCSI mode selects
        cache      - enable, disable or query SCSI disk cache
        volname    - set 8-character volume name
        !     - execute , then return
        quit
format> label
[0] SMI Label
[1] EFI Label
Specify Label type[1]: 0
Auto configuration via format.dat[no]?
Auto configuration via generic SCSI-2[no]?
format> p


PARTITION MENU:
        0      - change `0' partition
        1      - change `1' partition
        2      - change `2' partition
        3      - change `3' partition
        4      - change `4' partition
        5      - change `5' partition
        6      - change `6' partition
        7      - change `7' partition
        select - select a predefined table
        modify - modify a predefined partition table
        name   - name the current table
        print  - display the current table
        label  - write partition map and label to the disk
        ! - execute , then return
        quit
partition> p
Current partition table (default):
Total disk cylinders available: 46873 + 2 (reserved cylinders)

Part      Tag    Flag     Cylinders         Size            Blocks
  0       root    wm       0 -    20      128.17MB    (21/0/0)       262500
  1       swap    wu      21 -    41      128.17MB    (21/0/0)       262500
  2     backup    wu       0 - 46872      279.38GB    (46873/0/0) 585912500
  3 unassigned    wm       0                0         (0/0/0)             0
  4 unassigned    wm       0                0         (0/0/0)             0
  5 unassigned    wm       0                0         (0/0/0)             0
  6        usr    wm      42 - 46872      279.13GB    (46831/0/0) 585387500
  7 unassigned    wm       0                0         (0/0/0)             0

partition> q
Now, let's copy the partition table of our good disk over to our bad one:
root@solaris11server:~# prtvtoc /dev/rdsk/c0t5000CCA0166ED0ECd0s0 | fmthard -s - /dev/rdsk/c0t5000CCA0166F8C50d0s2
fmthard:  New volume table of contents now in place.
root@solaris11server:~# prtvtoc /dev/rdsk/c0t5000CCA0166F8C50d0s0
* /dev/rdsk/c0t5000CCA0166F8C50d0s0 partition map
*
* Dimensions:
*     512 bytes/sector
*     625 sectors/track
*      20 tracks/cylinder
*   12500 sectors/cylinder
*   46875 cylinders
*   46873 accessible cylinders
*
* Flags:
*   1: unmountable
*  10: read-only
*
* Unallocated space:
*       First     Sector    Last
*       Sector     Count    Sector
*           0     12500     12499
*
*                          First     Sector    Last
* Partition  Tag  Flags    Sector     Count    Sector  Mount Directory
       0      2    00      12500 585900000 585912499
       2      5    01          0 585912500 585912499
All is now good, so let's attach (mirror) our system disks:
root@solaris11server:~# zpool attach rpool c0t5000CCA0166ED0ECd0s0 c0t5000CCA0166F8C50d0s0
Make sure to wait until resilver is done before rebooting.
root@solaris11server:~# zpool status
  pool: rpool
 state: DEGRADED
status: One or more devices is currently being resilvered.  The pool will
        continue to function in a degraded state.
action: Wait for the resilver to complete.
        Run 'zpool status -v' to see device specific details.
  scan: resilver in progress since Wed Dec 14 10:13:36 2016
    1.52G scanned out of 108G at 58.9M/s, 30m52s to go
    1.52G resilvered, 1.41% done
config:

        NAME                         STATE     READ WRITE CKSUM
        rpool                        DEGRADED     0     0     0
          mirror-0                   DEGRADED     0     0     0
            c0t5000CCA0166ED0ECd0s0  ONLINE       0     0     0
            c0t5000CCA0166F8C50d0s0  DEGRADED     0     0     0  (resilvering)

errors: No known data errors
After the resilvering has finished, our system is mirrored correctly! :)