Saturday, July 28, 2007

Installing Slackware 12 on Linux Software RAID and LVM2

This article describes how I installed Slackware 12 onto Linux Software RAID partitions and LVM logical volumes. It is the first time I played with Software RAID and LVM.

In my case, the root filesystem is installed on a RAID-1 partition (non-LVM), and other filesystems (like /home, /tmp, and swap) are on LVM logical volumes on top of RAID-1 or RAID-0 arrays. I read from somewhere (and I concur) that it is not necessary and not good to put root partition into LVM, because if anything screws up, it is easier to get into root partition and do recovery if you don't have to deal with LVM. If you run into space problems with root filesystem later, you can always move some directories to another filesystem and change the mount points easily. I still want the root filesystem to be on RAID because I want the redundancy and speed gain on reads.

Hardware Installation
I have a PC with:
- Pentium D 930 CPU
- Gigabyte GA-8i945GMH-RH motherboard
- Seagate 80GB IDE harddisk.
The motherboard supports up to 2 IDE and 4 SATA devices. I bought 2 more Seagate 7200.10 320GB SATA2 harddisks (at S$126 each, from Best Bargin, Sim Lim Square).
What to take note here is that you need SATA cable and SATA power cable to connect the harddisks to your PC. If they don't come with the harddisk or motherboard, you have to buy separately. I paid S$2 for one SATA cable, and S$3 for one SATA power cable.

Installing the harddisks is straightforward if you follow your motherboard manual, or you have basic PC assembling knowledge.

After that, make appropriate setting changes in the BIOS. I don't plan to use the on-board RAID chipset, because it cannot create RAID arrays out of partitions. So I did not enable the RAID mode in BIOS. Instead I just enabled the SATA controller so that the SATA disks can be detected by the BIOS.

Space Allocation Strategy
I partitioned the 2 harddisks as follows:
sda:
sda1 (30GB) : Windows XP (yeah, still need it for photo processing, video chatting and gaming)
sda2 (30GB) : Reserved
sda5 (80GB) : Device 0 of RAID-1 array (md0)
sda6 (40GB) : Device 1 of RAID-0 array (md1)
sda7 (10GB) : Device 0 of RAID-1 array (md2)
The rest is free space for future expansion.

sdb:
sdb1 (30GB) : Windows Data Partition (FAT)
The rest follows sda

Note: Originally I plan to install Windows on some logical partition, but I encountered some problems. Seems like Windows cannot be installed onto logical partitions, but I am not sure.

Installing Slackware
Get ready the following things:
-Slackware 12 Installation CDs (I only burned CD1)
- Slackware 12 installation files (I downloaded selected directories from a mirror site using wget) in one of your harddisk partition (I put them into my USB harddisk), because I plan to use the option to copy files from a harddisk partition.
- Grub 0.97 package from extra directory (I plan to use Grub instead of Lilo).

Boot up using Installation CD1, using the default image (huge.s) to have mdadm and LVM available.

Use fdisk/cfdisk to partition the two harddisks. In my PC they are under /dev/sda and /dev/sdb respectively. I want identical partitions in the two, so I can use the following command to duplicate sda's partitions to sdb.

sfdisk -d /dev/sda | sfdisk /dev/sdb (will wipe out existing partitions in sdb)

Below is the output from "sfdisk -d" after the partitioning:
# partition table of /dev/sda
unit: sectors

/dev/sda1 : start= 63, size= 58588992, Id= c, bootable
/dev/sda2 : start= 58589055, size= 58589055, Id= c
/dev/sda3 : start=117178110, size=253907325, Id= 5
/dev/sda4 : start= 0, size= 0, Id= 0
/dev/sda5 : start=117178173, size=156248127, Id=fd
/dev/sda6 : start=273426363, size= 78124032, Id=fd
/dev/sda7 : start=351550458, size= 19534977, Id=fd

# partition table of /dev/sdb
unit: sectors

/dev/sdb1 : start= 63, size= 58588992, Id= c, bootable
/dev/sdb2 : start= 58589055, size= 58589055, Id= c
/dev/sdb3 : start=117178110, size=253907325, Id= 5
/dev/sdb4 : start= 0, size= 0, Id= 0
/dev/sdb5 : start=117178173, size=156248127, Id=fd
/dev/sdb6 : start=273426363, size= 78124032, Id=fd
/dev/sdb7 : start=351550458, size= 19534977, Id=fd

Note setting Id=FD (Linux Raid Autodetect) allows kernel to automatically start the array when the system boots. If you don't want auto-detection, use Id=83 (Linux) instead.

After that, create the RAID arrays using mdadm (using default chunk size of 64KB):
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sd[ab]5
mdadm --create /dev/md1 --level=0 --raid-devices=2 /dev/sd[ab]6
mdadm --create /dev/md2 --level=1 --raid-devices=2 /dev/sd[ab]7

Create LVM PVs, VGs and LVs. I want an 8G RAID-1 LV for /home, a 4G RAID-0 LV for /tmp, and a 512M RAID-0 LV for swap. So:
pvcreate /dev/md0
pvcreate /dev/md1
vgcreate raid1_vg0 /dev/md0
vgcreate raid0_vg0 /dev/md1
lvcreate -L8G -nslackware_home raid1_vg0
lvcreate -L512M -nswap /raid0_vg0
lvcreate -L4G -nslackware_tmp raid0_vg0
vgchange -a y raid1_vg0
vgchange -a y raid0_vg0

Set up swap filesystem (do this manually because Slackware Setup program cannot detect swap filesystems on LVM):
mkswap /dev/raid0_vg0/swap
swapon /dev/raid0_vg0/swap

Run Setup:
setup

Skip the ADDSWAP step because I want the swap filesystem on LV but it will not look inside the LVs.

At TARGET step, I choose /dev/md2 for root (/) (ext3), /dev/raid1_vg0/slackware_home as /home (reiserfs), /dev/raid0_vg0/slackware_tmp as /tmp (reiserfs). Here what filesystem you want to use is up to individual test. Do take note that since Slackware 12, the default filesystem is changed from reiserfs to ext3, probably because of the uncertain future of reiserfs...
I also specify /dev/sda1 to be mounted as /mnt/windows-xp, and /dev/sdb1 as /mnt/windows-data.

At SOURCE step, I choose Install from a hard drive partition, then specify the partition (dev/sdc5) and path of the installation files in my USB harddisk.

After that, select the packages and install them to the selected partitions. (I choose all since I don't want to spend too much time picking through the packages)
I then go through the CONFIGURE step as per normal, but skip LILO installation. I did not create a USB boot stick because I don't have a spare one.

After that, exit the Setup program, but do not reboot first. Still need to do a couple of things:

- Install grub. By now the root filesystem of the installed system is mounted to /mnt, so:
chroot /mnt
installpkg /grub-0.97-i486-3.tgz
mkdir /boot/grub; cp /usr/lib/grub/i386-pc/* /boot/grub

Exit chroot.

- Create menu.lst under /boot/grub (better prepare it in advance in case you forgot the syntax). My grub entry for Slackware:

title Slackware 12 SMP (on /dev/md2)
root (hd0,6)
kernel /boot/vmlinuz root=/dev/md2 ro vga=773
boot

- Install grub to MBR of both sda and sdb:
grub
grub>device (hd0) /dev/sda (and sdb)
grub>root (hd0, 6)
grub>setup (hd0)
grub>quit

- Create mdadm.conf (It is not required by mdadm to work, but is useful for keeping track of arrays and member disks.).
mdadm --detail --scan >> /mnt/etc/mdadm.conf

- Add swap mount point to /mnt/etc/fstab:
/dev/raid0_vg0/swap swap swap defaults 0 0

- Run vgscan to create /etc/lvm/backup, which is checked by the init scripts in order to enable LVM (for details see /etc/rc.d/rc.S).
chroot /mnt
vgscan -v

Exit chroot.

Now reboot. After rebooting, you should see the login prompt. Go in and check if everything is started and mounted correctly.

Points to Note
- The Generic Slackware kernels cannot boot from root partitions on RAID, so the Huge kernel should be used. (It probably can with some initrd, but I didn't try that.)
- Be careful when you change your harddisk partitions. Because there is RAID arrays and PV/VG/LVs created on top of the partitions, deleting existing partitions may screw up those. Always make sure there is no existing RAID arrays or PVs using them first. See if you really need to change the partitions - after all with LVM it may not be necessary to change partitions directly. Try changing the LVs instead.

To remove the PV/LVs, use lvremove, vgreduce, and pvremove commands. To remove a partition or harddisk from a RAID array, use mdadm --zero-superblock to erase the RAID superblock from the device. The superblock is a 4K block of data written near the end of the device. It contains information for the array and the member devices. It allows the kernel to automatically start arrays when the system boots.

- If you did not manage to complete the installation process after you have created the RAID arrays and LVM stuff, you can do the following:
mdadm --assemble /dev/md0 /dev/sd[ab]5 # manually specify the RAID array and it member devices
OR mdadm --assemble --scan /dev/md[0-2] # just specify the RAID array
OR mdadm --assemble --scan --config= # assemble all MD devices using mdadm.conf
vgscan # detect all VGs

Listings
/etc/fstab:
/dev/md2 / ext3 defaults 1 1
/dev/raid0_vg0/slackware_tmp /tmp reiserfs defaults 1 2
/dev/raid1_vg0/slackware_home /home reiserfs defaults 1 2
/dev/raid0_vg0/swap swap swap defaults 0 0
/dev/sda1 /mnt/windows-xp vfat defaults 1 0
/dev/sdb1 /mnt/windows-data vfat defaults 1 0
#/dev/cdrom /mnt/cdrom auto noauto,owner,ro 0 0
/dev/fd0 /mnt/floppy auto noauto,owner 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
proc /proc proc defaults 0 0

/proc/mdstat:
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [multipath]
md1 : active raid0 sdb6[1] sda6[0] 78123904 blocks 64k chunks
md2 : active raid1 sdb7[1] sda7[0] 9767424 blocks [2/2] [UU]
md0 : active raid1 sdb5[1] sda5[0] 78123968 blocks [2/2] [UU]
unused devices:

PVs:
--- Physical volume ---
PV Name /dev/md1
VG Name raid0_vg0
PV Size 74.50 GB / not usable 0
Allocatable yes
PE Size (KByte) 4096
Total PE 19073
Free PE 17921
Allocated PE 1152
PV UUID 0DaWBK-Mw3A-MnoW-ZZNT-DeKr-kbEX-LTrbX3

--- Physical volume ---
PV Name /dev/md0
VG Name raid1_vg0
PV Size 74.50 GB / not usable 0
Allocatable yes
PE Size (KByte) 4096
Total PE 19073
Free PE 17025
Allocated PE 2048
PV UUID yab1wC-so2Y-XR8L-K3NM-9pYX-CBfD-iqdrqH

VGs:
--- Volume group ---
VG Name raid0_vg0
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 74.50 GB
PE Size 4.00 MB
Total PE 19073
Alloc PE / Size 1152 / 4.50 GB
Free PE / Size 17921 / 70.00 GB
VG UUID sTV1RZ-AShv-Rbb3-J84Y-WZcF-s4Hu-1OQQT1

--- Volume group ---
VG Name raid1_vg0
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 74.50 GB
PE Size 4.00 MB
Total PE 19073
Alloc PE / Size 2048 / 8.00 GB
Free PE / Size 17025 / 66.50 GB
VG UUID jatY6C-g1hq-Xexs-rGzb-2qcF-KOgG-xkv64E


LVs:
--- Logical volume ---
LV Name /dev/raid0_vg0/swap
VG Name raid0_vg0
LV UUID vQhFg9-U0uW-U2eT-njKp-cEyb-jmwx-7gFqkR

LV Write Access read/write
LV Status available
# open 1
LV Size 512.00 MB
Current LE 128
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:0

--- Logical volume ---
LV Name /dev/raid0_vg0/slackware_tmp
VG Name raid0_vg0
LV UUID fp2bGy-1mIw-V79A-BCdX-EGWp-NCLq-Hu90Bb
LV Write Access read/write
LV Status available
# open 2
LV Size 4.00 GB
Current LE 1024
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:1

--- Logical volume ---
LV Name /dev/raid1_vg0/slackware_home
VG Name raid1_vg0
LV UUID czyWXU-YYHc-zaVE-eFVh-x9h6-712k-HSEIps
LV Write Access read/write
LV Status available
# open 2
LV Size 8.00 GB
Current LE 2048
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:2


References:

LVM and mdadm man pages
Managing RAID on LINUX by Derek Vadala, O'Reilly 2003
http://tldp.org/HOWTO/LVM-HOWTO
http://tldp.org/HOWTO/Software-RAID-HOWTO.html
http://slacksite.com/slackware/raid.html
http://wiki.linuxquestions.org/wiki/Slackware-Guides#How_do_I_install_Slackware_on_a_with_LVM-partitions.3F
http://bbs.linuxsir.org/showthread.php?t=308297

7 comments:

Anonymous said...

thanks for this howto. however im having difficulty configuring grub. my root filesystem (/) is installed on top of a logical volume. what should be my root= ??? i tried the root=UUID=number and i've also tried root=/dev/VG/slackwarefs. any suggestions? i get the following error:

VFS cannot open root device. please append correct "root=" boot option

Pumpump said...

Hi Anonymous. I am not sure how to do that either. If you want to use LVM for / you may want to use LILO and follow this guide:
ftp://ftp.slackware.com/pub/slackware/slackware-12.1/README_LVM.TXT

Web Tasarım said...

Sorry my english firstly, i read well but i cant write :), So its useful post for me and i bookmarked your blog.

warez indir, oyun indir, dizi indir, program indir, photoshop indir

web tasarımpremium wordpress themesfotokopi, dijital cikis, ozalit, kirtasiyesesli chat

Anonymous said...

pumpump.blogspot.com is very informative. The article is very professionally written. I enjoy reading pumpump.blogspot.com every day.
canadian payday loans
online payday loans canada

mosiah said...

Thank you so much!!!

This is an excellent how-to on software RAID for Slackware!

Saved me lots of trouble trying to use a different distro, Slackware is #1.

Keep up the good work.

web tasarım said...

web tasarımtüp bebekobeziterobotik cerrahipdkskamera sistemleriturnike sistemleriboğaz turulazer epilasyonlazer epilasyonkavitasyon ile zayıflama

Webronz Web Tasarım said...

veli bilgilendirme sistemi, veli bilgilendirme, veli, e okul, e okul sistemi, veli bilgilendirme sistemi