Setting up a /var partition on software IDE raid1

From Alpine Linux
Revision as of 13:51, 31 July 2009 by Belousa (talk | contribs) (Create filesystem)
Jump to: navigation, search

This document wil show how to create harddisk mirroring using cheap IDE disks.

This document was written for alpine-1.3.8

I will setup swap on a raid1 for maximum reliability. If you prefer maximum speed, you don't need configure any raid devces for swap. Just add 2 swap partitions on different disks and linux will stripe them automatically.

The downside is that at the moment one disk fails, the system will go down. Thats why I choose to put the swap on raid1.

Setting up the RAID

Set up a raid array as described here. In this document two raid arrays are configured: md0 for swap (512MB) and md1 for /var.

It is generally a good idea to use LVM so you are able to easily extend your data storage in future. LVM is not discussed here.

Create filesystem

Now we can creat swapspace and the filesystem for /var.

mkswap /dev/md0
swapon /dev/md0

You can verify that swap was really activated with free. It should display how much swapspace you have.


We need to install the software to create the filesystem ("format" the partition). I will use ext3 here so I install e2fsprogs. If you prefer reiserfs or xfs you will have to install xfsprogs or reiserfsprogs instead.

apk_add e2fsprogs

If you use an Alpine release older than 1.3.8 you will need to manuall create a link to /etc/mtab.

ln -fs /proc/mounts /etc/mtab

Create the filesystem. The -j option makes it ext3. Without the -j option it will become non-journaling ext2. This step might take some time if your partition is big.

mke2fs -j /dev/md1

Now edit /etc/fstab and add your new partitions. Mine looks like this:

none            /proc           proc    defaults 0 0
none            /sys            sysfs   defaults 0 0
udev            /dev            tmpfs   size=100k 0 0
none            /dev/pts        devpts  defaults 0 0
tmpfs           /dev/shm        tmpfs   defaults 0 0
/dev/cdrom      /media/cdrom    iso9660 ro 0 0
/dev/fd0        /media/floppy   vfat    noauto  0 0
/dev/usba1      /media/usb      vfat    noauto  0 0
none            /proc/bus/usb   usbfs noauto 0 0
/dev/md0        swap            swap    defaults 0 0
/dev/md1        /var            ext3    defaults 0 0

Move the data

Now you should stop all services running that put anything in /var (syslog for example). If you have booted on a clean installation and not run setup-alpine, then no services should be running. However, some packages might have created dirs in /var so we need to backup /var mount the new and move all backed up dirs back to the raided /var.

mv /var /var.tmp
mkdir /var
mount /var
mv /var.tmp/* /var
rmdir /var.tmp

Verify that everyting looks ok with the df utility.

~ $ df
Filesystem           1k-blocks      Used Available Use% Mounted on
none                    255172     23544    231628   9% /
udev                       100         0       100   0% /dev
/dev/cdrom              142276    142276         0 100% /media/cdrom
/dev/md1              37977060    181056  35866876   1% /var

Survive reboots

Now we have everyting up and running. We need to make sure that everything will be restored during next reboot.

Create an initscript that will mount /var for you during boot. I call it /etc/init.d/mountdisk and it looks like this:


start() {
        ebegin "Mounting /var"
        mount /var
        eend $?

stop() {
        ebegin "Unmounting /var"
        umount /var
        eend $?

Make it exectutable:

chmod +x /etc/init.d/mountdisk

NOTE: Since Alpine-1.7.3 there is a localmount script shipped so you will not need to create your own mountdisk script.

And that /var is mounted *after* raid is created. The -k option will make alpine to unmount the /Var partition during boot. Also add start of swap too boot

rc_add -k -s 06 mountdisk
rc_add -k -s 06 swap

The /dev/md* device nodes will not be created automatically so we need to put the on floppy too.

lbu include /dev/md*

If you have users on the server and want the /home be permantent you can create a directory /var/home and create links to /var/home.

mkdir /var/home
mv /home/* /var/home/
ln -s /var/home/* /home/

NOTE: You cannot just replace /home with a link that points to /var/home since the base has a director /home. When the boot tries to copy the config from floppy it will fail because of the already existing /home directory.

Make sure the links are stored to floppy:

lbu include /home/*

Also remeber to move any newly created users to /var/home and create a link:

adduser bob
mv /home/bob /var/home/
ln -s /var/home/bob /home/bob
lbu include /home/bob

Save to floppy:

lbu commit floppy

Test it works

Reboot computer. Now should the raid start and /var sould be mounted. Check with df:

~ $ df
Filesystem           1k-blocks      Used Available Use% Mounted on
none                    255172     23976    231196   9% /
mdev                       100         0       100   0% /dev
/dev/cdrom              140932    140932         0 100% /media/cdrom
/dev/md1              37977060    180984  35866948   1% /var


Since the package database is placed on disk, you cannot update by simply replacing the CDROM. You will have to either run the upgrade on the new CDROM or run apk_add -u ... && update-conf manually.