Linux Howtos – Raid1 Setup On CentOS5

February 26th, 2011

 

Setup Raid1 on Already Installed System

 

 

This Howto covers Raid1 setup on preinstalled Centos 5.5 system. Raid array will have 2 disks.

 

Lets get some info about current partitions:

# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1305 10377990 8e Linux LVM

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn’t contain a valid partition table

 

# cat /etc/fstab

/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
/dev/sda1 /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/VolGroup00/LogVol01 swap swap defaults 0 0

 

There were 2 partitions, sda1 with /boot and sda2 with LVM.
LVM partition had / and swap part.

Now we need to start system in rescue mode. Reboot and set in BIOS boot priority. Insert CentOS install cd, save changes in BIOS and reboot again. When it boots up type:


boot: linux rescue

Choose language
Choose keyboard type
Choose NO in network interfaces menu
Choose SKIP mounting current system in rescue screen menu

You entered rescue mode. This mode is also very useful for fixing critical system problems.

Load a few kernel modules (to avoid a reboot):

# modprobe linear
# modprobe multipath
# modprobe raid0
# modprobe raid1
# modprobe raid5
# modprobe raid6
# modprobe raid10

# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
unused devices:

Copy partition structure from old system disk to new disk:

# sfdisk -d /dev/sda | sfdisk /dev/sdb

We need to change partition type to raid for both partitions:

# fdisk /dev/sdb

Command (m for help): <-- t Partition number (1-4): <-- 1 Hex code (type L to list codes): <-- fd Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): <-- t Partition number (1-4): <-- 2 Hex code (type L to list codes): <-- fd Changed system type of partition 2 to fd (Linux raid autodetect)

Command (m for help): <-- w The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Create RAID arrays:

# mdadm –create /dev/md0 –level=1 –raid-disks=2 missing /dev/sdb1
mdadm: array /dev/md0 started.

# mdadm –create /dev/md1 –level=1 –raid-disks=2 missing /dev/sdb2
mdadm: array /dev/md1 started.

Create filesystems on these arrays. First for /boot partition:

# mkfs.ext3 -L ‘/boot’ /dev/md0

Then for / and swap in LVM partition:

# lvm pvcreate /dev/md1

# lvm vgcreate RaidArray /dev/md1

# lvm lvcreate –size 1G –name swap RaidArray

# lvm vgdisplay RaidArray

Look for “Free PE / Size” record (in this case it was):
Free PE / Size 2277 / 8.89GB

# lvm lvcreate –size 8.89G –name Root RaidArray

# mkswap /dev/RaidArray/swap

# mkfs.ext3 -L ‘/’ /dev/RaidArray/Root

Copy content of each old partition to equivalent raid partition:

# mkdir /mnt/boot.old
# mount -o ro /dev/sda1 /mnt/boot.old

# mkdir /mnt/boot.new
# mount /dev/md0 /mnt/boot.new

We need to activate LVM:

# lvm vgchange –available y VolGroup00

# mkdir /mnt/root.old
# mount -o ro /dev/VolGroup00/LogVol00 /mnt/root.old

# mkdir /mnt/root.new
# mount /dev/RaidArray/Root /mnt/root.new

Copy content:

# rsync -avXH /mnt/boot.old/* /mnt/boot.new/
# rsync -avXH /mnt/root.old/* /mnt/root.new/

Or if you prefer tar:

# tar -C /mnt/boot.old -cf – . | tar -C /mnt/boot.new -xf -
# tar -C /mnt/root.old -cf – . | tar -C /mnt/root.new -xf -

If you have SELinux create a flag file to request SELinux attributes get relabeled on boot time:

# touch /mnt/root.new/.autorelabel

Setup grub on raid disk:

# grub
root (hd1,0)
setup (hd1)
quit

In /mnt/boot.new/grub/menu.lst instead /dev/VolGroup00/LogVol00 put /dev/RaidArray/Root.

In /mnt/root.new/etc/fstab instead /dev/VolGroup00/LogVol00 put /dev/RaidArray/Root, instead /dev/VolGroup00/LogVol01 put /dev/RaidArray/swap and instead LABEL=/boot put /dev/md0 .

We need to create new initrd:

# umount /mnt/boot.new
# mount /dev/md0 /mnt/root.new/boot
# mount -o bind /proc /mnt/root.new/proc
# mount -o bind /dev /mnt/root.new/dev
# mount -o bind /sys /mnt/root.new/sys
# mount -o bind /selinux /mnt/root.new/selinux

Enter the new system:

# chroot /mnt/root.new

Find the current initrd image:

# ls /boot/*.img

returns something like:
/boot/initrd-2.6.18-128.1.6.el5.img

Create new initrd image:

# mkinitrd -f /boot/initrd-2.6.18-128.1.6.el5.img 2.6.18-128.1.6.el5

Go back to rescue mode from chroot:

# exit

Time to cleanup:

# umount /mnt/root.new/selinux
# umount /mnt/root.new/sys
# umount /mnt/root.new/dev
# umount /mnt/root.new/proc
# umount /mnt/root.new/boot
# umount /mnt/root.new
# umount /mnt/boot.old
# umount /mnt/root.old

Shutdown the system, remove/unplug sda drive or set in bios that primary disk is sdb and power on the machine.

If it boots normally check if the system is on raid:

# mount

You should check if some lines have:
/dev/RaidArray/Root
/dev/RaidArray/swap
/dev/md0

Shutdown the system and reinsert sda drive making it secondary drive in bios.
Startup system in rescue mode as before.
Check:

# fdisk -l

In my case disks were sdb (raid disk) and sda (old, no raid disk).

Since there is no default mdadm.conf file in the installation media it should be created:

# mdadm –examine –scan > /etc/mdadm.conf

Activate all discovered RAID devices:

# mdadm –assemble –scan

See the current RAID status:

# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb1[1]
104320 blocks [2/1] [U_]

md1 : active raid1 sdb2[1]
10377920 blocks [2/1] [U_]

unused devices:

Convert partitions on old no-raid device so it can be paired with raid device:

# sfdisk -d /dev/sdb | sfdisk /dev/sda

Check if new partitions are in Linux raid type:

# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 fd Linux raid autodetect
/dev/sda2 14 1305 10377990 fd Linux raid autodetect

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 * 1 13 104391 fd Linux raid autodetect
/dev/sdb2 14 1305 10377990 fd Linux raid autodetect

Add new partitions to raid device:

# mdadm /dev/md0 -a /dev/sda1
# mdadm /dev/md1 -a /dev/sda2

You can check the sync progress:

# cat /proc/mdstat

Personalities : [raid0] [raid1] [raid6] [raid5] [raid4]
md1 : active raid1 sdb2[2] sda2[0]
10377990 blocks [2/1] [U_]
[>………………..] recovery = 0.2% (25497/10377990) finish=8.7min speed=23744K/sec

md0 : active raid1 sdb1[1] sda1[0]
104320 blocks [2/2] [UU]

unused devices:

Install grub on new raid disk:

# grub
root (hd0,0)
setup (hd0)
quit

To avoid error message when checking fdisk -l (Disk /dev/sdX doesn’t contain a valid partition table) you should do:

# fdisk /dev/sda
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks

# fdisk /dev/sdb
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks

You now have functional raid1 system made of 2 disks.

 

Resources:

http://wiki.centos.org/HowTos/CentOS5ConvertToRAID

http://howtoforge.net/software-raid1-grub-boot-fedora-8

http://tldp.org/HOWTO/LVM-HOWTO/createlv.html

Linux Tips and Tricks – Check System Runlevel

January 15th, 2011

 

How To Check What Is the Runlevel of Linux System?

 

 

You can do this on several ways. Most common way is to issue a command:

 

# runlevel

 

Or you could check the content of some of these files:

 

For RH/Fedora/Centos:

#cat /etc/inittab

 

For Debian/Ubuntu:

#cat /etc/init/rc-sysinit.conf

Mathematical Solving Problem

April 16th, 2010

 

Test Your Calculus Skills

 

 

This is one interesting mathematical riddle. It is very simple – when you know all about basic rules of math and calculus. Unfortunately, I am not one of those guys so I had to search for the answer. Can you also solve it?

 


Math Problem