FreeBSD 10 software raid 1 (mirror)

This howto describes migration of freebsd 10 installation which is installed on single hard drive(with MBR partition scheme) to software raid mirror.

# df -h
Filesystem Size Used Avail Capacity Mounted on
/dev/ada0s1a 68G 4.1G 58G 7% /
devfs 1.0K 1.0K 0B 100% /dev

As wee see, the freebsd installation is placed on /dev/ada0.

I attached a second hdd, it’s a ada1.

# dmesg | grep ada
ada0 at ata0 bus 0 scbus0 target 0 lun 0
ada0: <SAMSUNG HD081GJ JE100-21> ATA-7 SATA 2.x device
ada0: Serial Number S0UZJ1NS101363
ada0: 150.000MB/s transfers (SATA, UDMA5, PIO 8192bytes)
ada0: 76319MB (156301488 512 byte sectors: 16H 63S/T 16383C)
ada0: Previously was known as ad0
ada1 at ata1 bus 0 scbus1 target 0 lun 0
ada1: <SAMSUNG HD081GJ JE100-21> ATA-7 SATA 2.x device
ada1: Serial Number S0UZJ1NS101354
ada1: 150.000MB/s transfers (SATA, UDMA5, PIO 8192bytes)
ada1: 76319MB (156301488 512 byte sectors: 16H 63S/T 16383C)
ada1: Previously was known as ad2
Trying to mount root from ufs:/dev/ada0s1a [rw]...

Media size of disk /dev/ada0

# diskinfo -v ada0 | head -n3
ada0
512 # sectorsize
80026361856 # mediasize in bytes (75G)

# sysctl kern.geom.debugflags=16
kern.geom.debugflags: 0 -> 16


# gmirror label -v -b round-robin gm0 /dev/ada0
Metadata value stored on /dev/ada0.
Done.

echo geom_mirror_load="YES" > /boot/loader.conf

# gmirror load

# ls /dev/mirror/
gm0 gm0s1 gm0s1a gm0s1b

The default /etc/fstab file.

# cat /etc/fstab
# Device Mountpoint FStype Options Dump Pass#
/dev/ada0s1a / ufs rw 1 1
/dev/ada0s1b none swap sw 0 0

 

We have to replace /dev/ada0 with gm0 device.

# cat /etc/fstab
# Device Mountpoint FStype Options Dump Pass#
/dev/mirror/gm0s1a / ufs rw 1 1
/dev/mirror/gm0s1b none swap sw 0 0

reboot

Now, we booted from gm0 device.

# df -h
Filesystem Size Used Avail Capacity Mounted on
/dev/mirror/gm0s1a 68G 4.1G 58G 7% /
devfs 1.0K 1.0K 0B 100% /dev

 

Let’s check the gmirror status

# gmirror status
Name Status Components
mirror/gm0 COMPLETE ada0 (ACTIVE)

Insert the second hard drive to the mirror.

# gmirror insert gm0 /dev/ada1

Rebuilding progress

# gmirror status
Name Status Components
mirror/gm0 DEGRADED ada0 (ACTIVE)
ada1 (SYNCHRONIZING, 0%)

# gstat

dT: 1.002s w: 1.000s
L(q) ops/s r/s kBps ms/r w/s kBps ms/w %busy Name
2 513 513 65662 2.8 0 0 0.0 93.4| ada0
0 518 0 0 0.0 518 65664 1.1 50.3| ada1
2 513 513 65662 2.8 0 0 0.0 93.4| mirror/gm0
0 0 0 0 0.0 0 0 0.0 0.0| mirror/gm0s1
0 0 0 0 0.0 0 0 0.0 0.0| mirror/gm0s1a
0 0 0 0 0.0 0 0 0.0 0.0| mirror/gm0s1b

 

When rebuilding completed, both hard drives will be ACTIVE.

 

 

 

# gmirror status
Name Status Components
mirror/gm0 COMPLETE ada0 (ACTIVE)
ada1 (ACTIVE)


# gmirror list
Geom name: gm0
State: COMPLETE
Components: 2
Balance: round-robin
Slice: 4096
Flags: NONE
GenID: 0
SyncID: 1
ID: 2281483116
Providers:
1. Name: mirror/gm0
Mediasize: 80026361344 (75G)
Sectorsize: 512
Mode: r2w2e5
Consumers:
1. Name: ada0
Mediasize: 80026361856 (75G)
Sectorsize: 512
Mode: r1w1e1
State: ACTIVE
Priority: 0
Flags: NONE
GenID: 0
SyncID: 1
ID: 2778897359
2. Name: ada1
Mediasize: 80026361856 (75G)
Sectorsize: 512
Mode: r1w1e1
State: ACTIVE
Priority: 0
Flags: NONE
GenID: 0
SyncID: 1
ID: 144619298

If we have a failed drive

# gmirror status
Name Status Components
mirror/gm0 DEGRADED ada0 (ACTIVE)
#
#
# gmirror list
Geom name: gm0
State: DEGRADED
Components: 2
Balance: round-robin
Slice: 4096
Flags: NONE
GenID: 0
SyncID: 2
ID: 2281483116
Providers:
1. Name: mirror/gm0
Mediasize: 80026361344 (75G)
Sectorsize: 512
Mode: r2w2e5
Consumers:
1. Name: ada0
Mediasize: 80026361856 (75G)
Sectorsize: 512
Mode: r1w1e1
State: ACTIVE
Priority: 0
Flags: NONE
GenID: 0
SyncID: 2
ID: 144619298

Shutdown the computer and replace the failed drive with new one,power on pc and boot from the working hdd.

# gmirror status
Name Status Components
mirror/gm0 DEGRADED ada1 (ACTIVE)

# gmirror forget gm0

# gmirror insert gm0 /dev/ada0

# gmirror status
Name Status Components
mirror/gm0 DEGRADED ada1 (ACTIVE)
ada0 (SYNCHRONIZING, 11%)

Leave a Reply

Your email address will not be published. Required fields are marked *