Vinum HOWTO for two mirrored disks


This page dates from March 2002. I'm not even sure why it's here any more, but there's no longer any useful information in it.
Preface

Vinum is a Logical Volume Manager for FreeBSD. It is able to do RAID-0, RAID-1 and RAID-5. Also RAID-4, though this doesn't buy you anything. This document took a lot of information from a really good HOWTO page from written by scanner at jurai dot net. Thanks to scanner and the freebsd-isp at freebsd dot org mailing-list for information and documentation.

Foreword for RAID-1, mirrored disks

Layout: one small disk for your FreeBSD system, which means for /. Two big disks for your mirrored disks. Why this? You need to have one system disk because FreeBSD connot boot off a vinum partition - it's like the chicken and the egg: first you have to load the kernel in order to initialize the vinum mirrored disks, so you cannot boot off vinum disks. You can't find a disk small enough for a root partition and swap only. You'd be a whole lot better off putting swap on the second disk and making it the same size as the root file system, leaving the rest of both disks for a Vinum drive.

O.k., so what now? I have written this document for a fresh installation of the system. Please keep in mind, that partitioning can mean you destroy data. Take a backup first. Well, let's start: First you have to install your system to the FreeBSD system disk. Don't install ports and linux compatibility, because they use lot's of space in /usr. You can do it afterwards with sysinstall.

It's easier to do it now.

Fresh installation of FreeBSD

Good, choose whatever install method you like (let's assume we've choosen "Standard"). Partition your first disk (e.g. the FreeBSD System disk) and use the entire disk by pressing "a" and write your data to disk by pressing "w". Choosse the next disk and do the same and also for the last one. Then install the bootmanager only for the first disk (your FreeBSD system disk). After that you have to label your disk and put slices on it. For the first disk take the following layout:

Part Mount Size
da0s1a / [Nearly the full disk]
da0s1b swap [The rest]

As mentioned above, put the swap on the second disk

Installation and the mirrored disks

For the two other disks make slices for the directories you want to mirror, like for example /usr and /var. Don't define these mountpoints here, but rather choose dummy mountpoints like /a or /b! Pay attention to create for each directory the same slices (e.g. da1s1e is 4000MB, and da2s1e is also 4000MB):

Part Mount Size:
da1s1e /a [e.g.15000MB]
da1s1f /b [e.g.5000MB]
da2s1e /c [e.g.15000MB]
da2s1f /d [e.g.5000MB]

It is wrong to make more than one Vinum drive per spindle. Drop, say, /dev/da1s1e and /dev/da1s2e

Install your FreeBSD system. Remember to keep your system as tiny as possible (e.g. not to install ports, linux compatibitity etc.).

Vinum Configuration

When the system is up we get into the vinum configuration. First of all comes the disklabeling procedure. FreeBSD slices are labeled 4.2BSD which is not suitable for vinum. Use the following command to change this:

# disklabel -e [name of the partition of the first to be mirrored partition, e.g. da1]

This is vi, you should know about how to use it. Change 4.2BSD to vinum (pay attention: vinum should be written in small letters!)

Do the same for your second to be mirrored paritition.

The next step is to create a vinum configuration file. The name and its location are irrelevant. I did it by creating it in /etc:

# vi /etc/vinum.conf

The layout I have choosen is very simple. This is an example, adjust it to your needs:
I have /usr and /var choosen to be mirrored slices. The command "df" gives the following layout:

/dev/da0s1a     49583    24678    20939    54%    /
/dev/da1s1e  14887091        1 14887090     0%    /a
/dev/da2s1e  14887091        1 14887090     0%    /b
/dev/da1s1f   4887091        1  4887090     0%    /c
/dev/da2s1f   4887091        1  4887090     0%    /d

What you should have would look like:

/dev/da0s1a     49583    24678    20939    54%    /
/dev/da1s1f  19772182        1 19772182     0%    /c
/dev/da2s1f  19772182        1 19772182     0%    /d

So my configuration file looks like that:

drive drive1 device /dev/da1s1e
drive drive2 device /dev/da2s1e
 volume usr
  plex org concat
    sd length 0 drive drive1
  plex org concat
    sd length 0 drive drive2
drive drive3 device /dev/da1s1f
drive drive4 device /dev/da2s1f
 volume var
  plex org concat
    sd length 0 drive drive3
  plex org concat
    sd length 0 drive drive4
Change that to:

drive drive1 device /dev/da1s1f
drive drive2 device /dev/da2s1f
 volume usr
  plex org concat
    sd length 14887091s drive drive1
  plex org concat
    sd length 14887091s drive drive2
 volume var
  plex org concat
    sd length 0 drive drive1
  plex org concat
    sd length 0 drive drive2

The names drive1,2,3,4 are optional as the volume name is (usr, var). For me it was easier that way, adjust it to your needs.
Then copy tar and vi to the root file system, just to be sure if something goes wrong:

# cp /usr/bin/vi /bin/vi
# cp /usr/bin/tar /bin/tar

Then start the vinum program (man vinum for further information!)

# vinum # This leads to the vinum prompt in the next line:
vinum -> create -f [name of your configuration, in my case /etc/vinum.conf]

If you wish to see your configuration, type dumpconfig.

If you wish to see your configuration, type list. dumpconfig is a utility to show what's really on the disk, and may not reflect the running configuration. It's also difficult to read, and it doesn't show the names of the drives.

If you want to discard your configuration, type resetconfig.

You should only use resetconfig in an emergency. To remove items from the configuration, use rm.

If your configuration suits your needs, hit "control + d" to finish.

After these operations, the configuration will not be correct. It's possible you'd miss it if you abuse dumpconfig to display the configuration, but the subdisks usr.p1.s0 and var.p1.s0 will be in empty state, and the plexes usr.p1 and var.p1 will be faulty:

2 volumes:
V usr                   State: up       Plexes:       2 Size:        921 MB
V var                   State: up       Plexes:       2 Size:       1092 MB

4 plexes:
P usr.p0              C State: up       Subdisks:     1 Size:        921 MB
P usr.p1              C State: faulty   Subdisks:     1 Size:        921 MB
P var.p0              C State: up       Subdisks:     1 Size:       1092 MB
P var.p1              C State: faulty   Subdisks:     1 Size:       1092 MB

4 subdisks:
S usr.p0.s0             State: up       PO:        0  B Size:        921 MB
S usr.p1.s0             State: empty    PO:        0  B Size:        921 MB
S var.p0.s0             State: up       PO:        0  B Size:       1092 MB
S var.p1.s0             State: empty    PO:        0  B Size:       1092 MB

To start them, use the init command. Alternatively, modify your configuration to:

 volume usr setupstate
  plex org concat
    sd length 14887091s drive drive1
  plex org concat
    sd length 14887091s drive drive2

to indicate that any discrepancies in the content can be ignored, since you will be doing a newfs on the volume.

After that newfs your slice with the following command:

# newfs -v /dev/vinum/[name name of your mirror, e.g. usr]

Do this for all of your slices you have configured for vinum! (e.g. var, etc.)

Then mount your new vinum slices lets say to /mnt/[name of the slice you want to clone:

# mkdir /mnt/usr
# mount /dev/vinum/usr /mnt/usr

Do this for every slice you want to clone.

Copying your old directories to the vinum slices

Then you have to copy the files in your old directory to the new slice:

# cd /
# tar cfv usr.tar usr
# mv usr.tar /mnt
# tar xfv usr.tar

Do this for every slice you want to clone.

Edit /etc/fstab

If this and the previous steps were successful, edit your fstab:

# vi /etc/fstab

Add the following line:

/dev/vinum/[name of your mirror, e.g. usr] /[name of your mountpoint, e.g. /usr] ufs rw 2 2

Repeat these steps for all of your mirror sets, like /var etc.

Don't forget /etc/rc.conf!!

Now we are nearly finished! Add the following line to your /etc/rc.conf:

start_vinum="YES"

and reboot:

# reboot

After the System has come up make a "df" in order to see the fabulous mirrored disks!

Something goes wrong after the reboot

If something goes wrong, e.g. you have not specified the right mountpoint etc.: you have vi in /bin, which means you can edit /etc/fstab, you have vinum in single user and you have still the copy of /usr and /var! You can repair everything like you want and repeat this steps by debbuging your configuration!

After-vinum configuration

If all went smooth, reboot into single user mode and mount /. Remove your old /usr, var and other directories you don't need anymore. Reboot. The system should come up into multiuser. Now delete your *.tar files in /mnt and finish your installation (e.g. install ports, linux compatibility, upgrade your system to RELENG_4 or whatever). At this stage the vinum part should be finished.

PAY ATTENTION!: If you want to upgrade your system to -STABLE do the following:

Make your normal cvsup to grep your new sources. When you are finished, make the following:

# cd /usr/src
# make buildworld
# make buildkernel KERNCONF=YOUR_KERNEL_HERE
# make installkernel KERNCONF=YOUR_KERNEL_HERE

Don't reboot yet!! First of all take a backup of your /sbin/vinum:

# cp /sbin/vinum /sbin/vinum.bak
# cd /usr/src/sbin/vinum
# make && make install
# reboot

Stop in single user mode (boot -s at the prompt).

# fsck /dev/YOUR_ROOT_FILESYSTEM_HERE
# mount /
# vinum start
# fsck /dev/vinum/YOUR_TO_BE_MOUNTED_FILESYSTEM
# mount /YOUR_TO_BE_MOUNTED_FILESYSTEM

Repeat the last for all of your essential slices (like /usr, /var, etc.)

Then go on with your normal upgrade process:

# make installworld
# mergemaster # For a fresh install it's the best way to type "i", else type "m"
# reboot

I don't understand the point of all this rigmarole. You shouldn't need to do anything special here.

Enjoy your new upgraded system! Michael Dosser.