Transformer un Boot ZFS simple en Boot ZFS en miroir

De OpenWikiBSD
Aller à : navigation, rechercher

L'install de Solaris 11 se fait par défaut sur le premier disque en installant un système ZFS.

Nous allons voir comment, après l'install, rendre cette installation tolérante aux pannes disques.

La source du doc

Mirror

Sous Solaris

  • Savoir quels sont les disques disponibles :
format

Searching for disks...done

AVAILABLE DISK SELECTIONS:
       0. c7t0d0 <IBM-ESX-GNS073C3ESTT0ZF-JP86 cyl 1955 alt 2 hd 255 sec 63>
          /pci@0,0/pci8086,3599@6/pci8086,330@0/pci1014,2cc@7,1/sd@0,0
       1. c7t1d0 <IBM-ESX-MAW3073NC     F-C206 cyl 1955 alt 2 hd 255 sec 63>
          /pci@0,0/pci8086,3599@6/pci8086,330@0/pci1014,2cc@7,1/sd@1,0

Ce sera donc c7t0d0 et c7t1d0

  • Où est installé le système :
zpool status

  pool: rpool
 state: ONLINE
config:

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

Solaris est donc installé sur c7t0d0s0

On va donc copier le tout sur c7t1d0s0

fdisk -W /tmp/c7t0d0p0  c7t0d0p0
fdisk -F /tmp/c7t0d0p0 c7t1d0p0
prtvtoc /dev/rdsk/c7t0d0s0 | fmthard -s - /dev/rdsk/c7t1d0s0
zpool attach -f rpool c7t0d0s0 c7t1d0s0
installgrub /boot/grub/stage1 /boot/grub/stage2 /dev/rdsk/c7t1d0s0


Script

On va faire un script de l'ensemble :

#!/bin/bash
# Usage script disk_dest

if [ "$1" == "" ]
then
echo "Choose the next disk you want to use as mirror and relaunch the script using cXtXdX as parameter.(Use q to exit the format program)"
exit
fi

NXTDSK=$1

ZFSBOOT=`/usr/sbin/zpool status |grep ONLINE |grep -v rpool|grep -v state|awk '{print $1}'|cut -d"s" -f1`
ZFSBOOTP=$ZFSBOOT"p0"
ZFSBOOTS=$ZFSBOOT"s0"
NXTDSKP=$NXTDSK"p0"
NXTDSKS=$NXTDSK"s0"

if [ "$ZFSBOOT" == "$NXTDSK" ]
then
echo "Error. $ZFSBOOT equals $NXTDSK.Can't mirror a disk on itself....Dummy!"
exit
fi

#echo "fdisk -W /tmp/$ZFSBOOTP  $ZFSBOOTP"
#echo "fdisk -F /tmp/$ZFSBOOTP  $NXTDSKP"
#echo "prtvtoc /dev/rdsk/$ZFSBOOTS | fmthard -s - /dev/rdsk/$NXTDSKS"
#echo "zpool attach -f rpool $ZFSBOOTS $NXTDSKS"
#echo "installgrub /boot/grub/stage1 /boot/grub/stage2 /dev/rdsk/$NXTDSKS"

echo "Copying label of $ZFSBOOT to $NXTDSK"
fdisk -W /tmp/$ZFSBOOTP  $ZFSBOOTP
fdisk -F /tmp/$ZFSBOOTP  $NXTDSKP
prtvtoc /dev/rdsk/$ZFSBOOTS | fmthard -s - /dev/rdsk/$NXTDSKS
echo " Making bootable $NXTDSK"
installgrub /boot/grub/stage1 /boot/grub/stage2 /dev/rdsk/$NXTDSKS
echo "Attaching $NXTDSK to zpool"
zpool attach -f rpool $ZFSBOOTS $NXTDSKS
echo "Don't reboot now!!!! Wait for resilvering to complete"

Ce qui donne :


zpool status
 pool: rpool
state: ONLINE
 scan: none requested
config:
       NAME        STATE     READ WRITE CKSUM
       rpool       ONLINE       0     0     0
         c3t3d0s0  ONLINE       0     0     0
errors: No known data errors
./MakeZFSBootRedundant.sh  c3t4d0
Copying label of c3t3d0 to c3t4d0
fmthard: Partition 2 specifies the full disk and is not equal
full size of disk.  The full disk capacity is 143315865 sectors.
fmthard: Partition 2 specified as 143347995 sectors starting at 0
       does not fit. The full disk contains 143315865 sectors.
fmthard:  New volume table of contents now in place.
Making bootable c3t4d0
stage2 written to partition 0, 282 sectors starting at 50 (abs 16115)
stage1 written to partition 0 sector 0 (abs 16065)
Attaching $c3t4d0 to zpool
Make sure to wait until resilver is done before rebooting.
Don't reboot now!!!! Wait for resilvering to complete
zpool status
  pool: rpool
state: ONLINE
status: One or more devices is currently being resilvered.  The pool will
       continue to function, possibly in a degraded state.
action: Wait for the resilver to complete.
 scan: resilver in progress since Wed Dec  7 17:49:57 2011
   1,65G scanned out of 36,6G at 18,6M/s, 0h32m to go
   1,65G resilvered, 4,51% done
config:
       NAME          STATE     READ WRITE CKSUM
       rpool         ONLINE       0     0     0
         mirror-0    ONLINE       0     0     0
           c3t3d0s0  ONLINE       0     0     0
           c3t4d0s0  ONLINE       0     0     0  (resilvering)
errors: No known data errors


Sous Linux

On va remplacer sdc, mort par sdb.


zpool  status
 pool: rpool
state: DEGRADED
status: One or more devices could not be used because the label is missing or
invalid.  Sufficient replicas exist for the pool to continue
functioning in a degraded state.
action: Replace the device using 'zpool replace'.
see: http://zfsonlinux.org/msg/ZFS-8000-4J
scan: scrub repaired 0 in 0h33m with 0 errors on Sun May  7 13:33:21 2017
config:

NAME STATE READ WRITE CKSUM rpool DEGRADED 0 0 0 mirror-0 DEGRADED 0 0 0 sda2 ONLINE 0 0 0 13467370790387964796 UNAVAIL 0 0 0 was /dev/sdc2

 zpool  detach sdc2
 ceph-disk zap /dev/sdb
 zpool labelclear /dev/sdb
 sfdisk -d /dev/sda |sfdisk /dev/sdb
 sgdisk -G /dev/sdb
 sfdisk -d /dev/sdb
 zpool attach rpool sda2 sdb2
zpool status
pool: rpool
state: ONLINE
status: One or more devices is currently being resilvered.  The pool will
continue to function, possibly in a degraded state.
action: Wait for the resilver to complete.
scan: resilver in progress since Sun May  7 18:35:55 2017
   2.34G scanned out of 155G at 10.7M/s, 4h3m to go
   2.33G resilvered, 1.51% done
config:

NAME STATE READ WRITE CKSUM rpool ONLINE 0 0 0 mirror-0 ONLINE 0 0 0 sda2 ONLINE 0 0 0 sdb2 ONLINE 0 0 0 (resilvering)

grub-install /dev/sdb 



C'est bon, votre OS est redondant! Maintenant, vous pouvez redémarrer.

Raid-Z

Si vous souhaitez avoir un boot en RAID-Z, alors il faut utiliser zpool add et non zpool attach et il vous faut 3 disques minimum:

fdisk -W /tmp/c7t0d0p0  c7t0d0p0
fdisk -F /tmp/c7t0d0p0 c7t3d0p0
fdisk -F /tmp/c7t0d0p0 c7t5d0p0
prtvtoc /dev/rdsk/c7t0d0s0 | fmthard -s - /dev/rdsk/c7t3d0s0
prtvtoc /dev/rdsk/c7t0d0s0 | fmthard -s - /dev/rdsk/c7t5d0s0
zpool add  rpool raidz c7t3d0s0 c7t5d0s0
installgrub /boot/grub/stage1 /boot/grub/stage2 /dev/rdsk/c7t3d0s0
installgrub /boot/grub/stage1 /boot/grub/stage2 /dev/rdsk/c7t5d0s0