This is a brief summary of how to set up your machine to use the Logical Volume Manager (lvm) in conjunction with the very excellent Reiser filesystem (reiserfs).
Please note: These instructions only work for Debian 2.2 (potato), using a 2.2.x kernel. The instructions for Debian 3.0 and 2.4.x kernels differ slightly. I'll get around to writing about these whenever I have time.
The benefits of doing this are great. The main ones being the live resizing of partitions and filesystems. Under normal circumstances, resizing filesystems involves at least unmounting the partition in question, and at worst having to shut down the machine and install an additional hard disk.
Another benefit comes with the fact that reiserfs is a journaling filesystem, roughly meaning that it keeps track of data as it's written, thus making it easier and quicker to verify in the case of a system crash (no more waiting for fscking ages for your machine to come back up!). This can come in handy if your business happens to rely heavily on a particular machine being available at all times. Here's a better definition:
A journaling file system is a fault-resilient file system in which data integrity is ensured because updates to directories and bitmaps are constantly written to a serial log on disk before the original disk log is updated. In the event of a system failure, a full journaling filesystem ensures that the data on the disk has been restored to its pre-crash configuration. It also recovers unsaved data and stores it in the location where it would have gone if the computer had not crashed, making it an important feature for mission-critical applications.
So, after obtaining and setting up your kernel to support lvm and reiserfs (later 2.4 kernels already have lvm and reiserfs support, but it's still a good idea to patch them with the latest lvm patch) and partitioning your disk accordingly (see below), it's time to start creating your logical volumes.
Prerequisites:
- Custom kernel, patched for LVM and Reiserfs
- Reiserfs utilities (cd /usr/src/linux/fs/reiserfs/utils; make; make install)
- LVM tools (apt-get install lvm)
Procedure:
Create a partition for use as a Physical Volume. Must have the partition label 8e. Keep the boot partition on ext2fs, as we won't otherwise be able to access it in emergencies!
eg.Device Boot Start End Blocks Id System /dev/hda1 1 66 530113+ 83 Linux /dev/hda2 67 132 530145 82 Linux swap /dev/hda3 133 1650 12193335 8e Unknown
- Designate a partition (or partitions) to be used in the Physical Volume:
# pvcreate /dev/hda3
- Create a volume group:
# vgscan # To set up. If you don't do this, you get # nasty errors at the vgcreate. # vgcreate vg00 /dev/hda3 - Start making, formating and mounting the Logical Volumes:
The basic idea is to create a logical volume within the volume group you just created, create a filesystem on it (in our case, reiserfs), then mount it in the appropriate place.
After all this, don't forget to edit /etc/fstab so the new partitions are mounted automatically at boot time. (Failure to do so would most likely require you to boot from a rescue disk and edit the fstab from there.)
The commands for creating the most common logical volumes are listed below. Please make sure they are really what you want to do before hitting <CR>. It's a good idea to decide how much space you want to allocate to each partition before starting to create your logical volumes!
Oh, and it's best practice to be in single-user mode whenever you do this, although I've found it's not strictly necessary.
It's also good to verify that these have worked after issuing each command. A simple
dfshould suffice.For /usr, /var, /tmp, /home (edit partition sizes as required):
I tend to do /usr first, as it's the biggest. Note also that /tmp should contain no files, as we're not going to bother copying its contents outa there first. This is why it's good to be in single-user mode :-)
# lvcreate -L1000m -nusr vg00 && mkreiserfs /dev/vg00/usr \ && mv /usr /oldusr && mkdir /usr \ && mount /dev/vg00/usr /usr && chmod 755 /usr \ && mv /oldusr/* /usr/ && rmdir /oldusr # lvcreate -L3000m -nvar vg00 && mkreiserfs /dev/vg00/var \ && mv /var /oldvar && mkdir /var \ && mount /dev/vg00/var /var && chmod 755 /var \ && mv /oldvar/* /var/ && rmdir /oldvar # lvcreate -L512m -ntmp vg00 && mkreiserfs /dev/vg00/tmp \ && mount /dev/vg00/tmp /tmp && chmod 1777 /tmp # lvcreate -L512m -nhome vg00 && mkreiserfs /dev/vg00/home \ && mv /home /oldhome && mkdir /home \ && mount /dev/vg00/home /home && chmod 2775 /home \ && mv /oldhome/* /home/ && rmdir /oldhome
- Edit the fstab.
Typical /etc/fstab entries:
/dev/vg00/usr /usr reiserfs nodev 0 0 /dev/vg00/var /var reiserfs nodev 0 0 /dev/vg00/tmp /tmp reiserfs nosuid,nodev 0 0 /dev/vg00/home /home reiserfs nosuid,nodev 0 0
You may also like to create:/dev/vg00/databases /databases reiserfs nosuid,nodev,noatime,noexec 0 0 /dev/vg00/www /www reiserfs nosuid,nodev,noatime 0 0
- Reboot!
The above procedure results in a system that looks like this:
$ df Filesystem 1k-blocks Used Available Use% Mounted on /dev/hda1 521748 26012 469232 5% / /dev/vg00/usr 1023964 223836 800128 22% /usr /dev/vg00/var 3071900 53476 3018424 2% /var /dev/vg00/tmp 524268 32840 491428 6% /tmp /dev/vg00/home 524268 32848 491420 6% /home $ mount /dev/hda1 on / type ext2 (rw,errors=remount-ro,errors=remount-ro) proc on /proc type proc (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) /dev/vg00/usr on /usr type reiserfs (rw,nodev) /dev/vg00/var on /var type reiserfs (rw,nodev) /dev/vg00/tmp on /tmp type reiserfs (rw,nosuid,nodev) /dev/vg00/home on /home type reiserfs (rw,nosuid,nodev)
And that's all there is to it :-)
Have fun!
S.
Back to Tech index