[FUG-BR] gmirror em slice

William David FUG-BR fugbr em biosystems.ath.cx
Quinta Novembro 20 12:31:05 BRST 2008


acho que isso vai resolver e fazer automático para você


# switch to /bin/sh as this script uses Bourne-Shell syntax
exec /bin/sh

# make step-by-step list more reusable by allowing the two disk devices
# and the resulting mirror device to be adapted to the local situation
d1=ad0; d2=ad1; gm=gm0

# make sure the second disk is treated as a really fresh one
dd if=/dev/zero of=/dev/${d2} bs=512 count=79

# place a PC MBR onto the second disk with a single FreeBSD slice
# /dev/mirror/${gm} as large as the /dev/${d1}s1 We reduce the size by
# one block because ${d1} and ${d1}s1 else would share the same last sector
# which could lead to ${d1} be recognized as the GEOM provider instead of
# ${d1}s1. Notice also that fdisk(8) usually further reduces the size by
# more blocks to make sure the size is a multiple of the cylinder size.
size=`fdisk /dev/${d1} | grep ', size ' |\
    head -1 | sed -e 's;^.*size \([0-9]*\).*$;\1;'`
size=`expr $size - 1`
fdisk -v -B -I /dev/${d2}
(echo "p 1 165 63 $size"; echo "a 1") | fdisk -v -f- -i /dev/${d2}

# place a GEOM mirror label onto first slice of second disk (actually on
# the last block of the disk slice) and activate the GEOM mirror kernel
# layer (which makes the /dev/mirror/${gm} device available).
gmirror label -v -n -b round-robin ${gm} /dev/${d2}s1
gmirror load

# place a BSD disklabel onto /dev/mirror/${gm} which is nearly identical
# to the BSD disklabel on /dev/${d1}s1 but has the slightly reduced total
# slice size (partition "c" because of the additional GEOM mirror label
# block) and hence a slightly smaller last partition. NOTICE: partition
# "a" always should start at offset 16 because of the BSD disklabel
# and partition "c" at offset 0 and notice that partition "c" has to
# cover the whole disk.
bsdlabel -w -B /dev/mirror/${gm}
( bsdlabel /dev/mirror/${gm} | grep 'c:'; \
  bsdlabel /dev/${d1}s1 | grep -v 'c:' ) | \
awk 'BEGIN { d = 0; n = 0; } \
    /c:/ { \
        d = $2; \
        printf("%s %d %s %s %s %s\n", $1, d, $3, $4, $5, $6); next; \
    } \
    /[abdefgh]:/ { \
        p = $2; if (d > 0 && n+p > d) { p = d-n }; \
        if ($1 == "a:") { n += $3 }; n += p; \
        printf("%s %d %s %s %s %s\n", $1, p, $3, $4, $5, $6); \
    } \
' >/tmp/bsdlabel.txt
bsdlabel -R /dev/mirror/${gm} /tmp/bsdlabel.txt

# dump & restore filesystem data from first to second disk
for p in `bsdlabel /dev/${d1}s1 |\
          egrep '^ *[adefgh]:' | sed -e 's/^ *\([adefgh]\).*/\1/'`; do \
    fs=`egrep "^ */dev/${d1}s1$p" /etc/fstab | awk '{ print $2; }'`; \
    newfs -U /dev/mirror/${gm}$p && \
    mount /dev/mirror/${gm}$p /mnt$fs && \
    dump -L -0 -f- $fs | (cd /mnt$fs && restore -r -v -f-); \
done

# adjust new system configuration for GEOM mirror based setup
cp -p /mnt/etc/fstab /mnt/etc/fstab.orig
sed -e "s;dev/${d1}s1;dev/mirror/${gm};g" \
    </mnt/etc/fstab.orig >/mnt/etc/fstab
echo 'geom_mirror_load="YES"' >>/mnt/boot/loader.conf

# instruct boot stage 2 loader on first disk to boot
# with the boot stage 3 loader from the second disk
# (mainly because BIOS might not allow easy booting from second
# ATA disk or at least requires manual intervention on the console)
# In general make sure your BIOS boot order is configured to try to
# boot of both ATA disks.
echo $d2 | sed -e 's;^\([^0-9]*\)\([0-9][0-9]*\)$;1:\1(\2,a)/boot/loader;' \
    >/boot.config

# reboot system
# (for running on top of new GEOM mirror on second disk)
shutdown -r now


Mais detalhes sobre a lista de discussão freebsd