Centos 6 how to guide convert LVM non-RAID into mdadm 1/10 RAID array live without reinstalling

Here is the scenario you or a client have a remote machine that was installed as a standard/default minimal Centos 6.x machine on a single disk with LVM for whatever reason.  Often many people do not know how to install it to a RAID array so it is common to have this problem and why reinstall if you don't need to?  In some cases on a remote system you can't easily reinstall without physical or KVM access.

So in this case you add a second physical or disk or already have one and want to make it a RAID array but don't want much downtime, dataloss etc...

In this tutorial we will show you how to turn this default install into a mdadm ARRAY with RAID10 on the / and a RAID 1 /boot and RAID 1 SWAP all without any downtime or other intervention (assuming all goes well and all steps are followed) :)

Install rsync:

yum -y install rsync

#disable selinux! otherwise you won't be able to login (it will logout #instantly and show this in the logs

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

centos cannot login session closed immediately


login: pam_unix(login:session): session opened for user root by LOGIN(uid=0)
login: ROOT LOGIN ON tty1
pam_unix(login:session): session closed for user root

Step 1.)
Create your partitions on the second disc (I assume your second disc is /dev/sdb).
md0=/dev/sdb1 is a 500M /boot partition
md1=/dev/sdb2 is a 1024M swap partition
md2=/dev/sdb3 is the / partition

fdisk /dev/sdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652): +500M

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (66-652, default 66):
Using default value 66
Last cylinder, +cylinders or +size{K,M,G} (66-652, default 652): +1024M

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4):
Value out of range.
Partition number (1-4): 3
First cylinder (198-652, default 198):
Using default value 198
Last cylinder, +cylinders or +size{K,M,G} (198-652, default 652):
Using default value 652

Command (m for help): t
Partition number (1-4):
Value out of range.
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): t
Partition number (1-4): 3
Hex code (type L to list codes): fd
Changed system type of partition 3 to fd (Linux raid autodetect)

Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0008b7d9

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          65      522081   fd  Linux raid autodetect
/dev/sdb2              66         197     1060290   fd  Linux raid autodetect
/dev/sdb3             198         652     3654787+  fd  Linux raid autodetect

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

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

====================

Step 2.) Create RAID arrays
md0=/dev/sdb1 is a 500M /boot partition
md1=/dev/sdb2 is a 1024M swap partition
md2=/dev/sdb3 is the / partition

mdadm --create /dev/md0 --metadata=0.90 --level=1 --raid-devices=2 /dev/sdb1 missing
mdadm --create /dev/md1 --level=10 --raid-devices=2 --layout=f2 /dev/sdb2 missing
mdadm --create /dev/md2 --level=10 --raid-devices=2 --layout=f2 /dev/sdb3 missing


[root@localhost ~]# mdadm --create /dev/md0 --metadata=0.90 --level=1 --raid-devices=2 /dev/sdb1 missing
mdadm: array /dev/md0 started.
[root@localhost ~]# mdadm --create /dev/md1 --level=10 --raid-devices=2 --layout=f2 /dev/sdb2 missing
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.
[root@localhost ~]# mdadm --create /dev/md2 --level=10 --raid-devices=2 --layout=f2 /dev/sdb3 missing
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md2 started.

[root@localhost ~]# cat /proc/mdstat
Personalities : [raid1] [raid10]
md2 : active raid10 sdb3[0]
      3652608 blocks super 1.2 512K chunks 2 far-copies [2/1] [U_]
     
md1 : active raid10 sdb2[0]
      1058816 blocks super 1.2 512K chunks 2 far-copies [2/1] [U_]
     
md0 : active raid1 sdb1[0]
      521984 blocks [2/1] [U_]

Step 3.) Make filesystems on RAID arrays
md0=/dev/sdb1 is a 500M /boot partition
md1=/dev/sdb2 is a 1024M swap partition
md2=/dev/sdb3 is the / partition
     

mkfs.ext4 /dev/md0
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
130560 inodes, 521984 blocks
26099 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
64 block groups
8192 blocks per group, 8192 fragments per group
2040 inodes per group
Superblock backups stored on blocks:
    8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

Writing inode tables: done                           
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@localhost ~]# mkswap /dev/md1
mkswap: /dev/md1: warning: don't erase bootbits sectors
        on whole disk. Use -f to force.
Setting up swapspace version 1, size = 1058812 KiB
no label, UUID=821efb1f-95cd-4aab-803b-e26d9fa6a920
[root@localhost ~]# mkfs.ext4
mkfs.ext4     mkfs.ext4dev 
[root@localhost ~]# mkfs.ext4 /dev/md2
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=128 blocks, Stripe width=256 blocks
228480 inodes, 913152 blocks
45657 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=935329792
28 block groups
32768 blocks per group, 32768 fragments per group
8160 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done                           
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.



Step 4.) Create chroot environment/mount RAID arrays

md0=/dev/sdb1 is a 500M /boot partition
md1=/dev/sdb2 is a 1024M swap partition
md2=/dev/sdb3 is the / partition


mount /dev/md2 /mnt
mkdir /mnt/boot
mount /dev/md0 /mnt/boot/

#time to rsync all your files
rsync -Phaz / --exclude=/mnt --exclude=/sys/* --exclude=/proc/* /mnt

sent 243.20M bytes  received 377.68K bytes  1.87M bytes/sec
total size is 635.16M  speedup is 2.61


#setup chroot environment

for mount in dev sys proc; do
mount -o bind /$mount /mnt/$mount
done

#chroot
chroot /mnt

#setup mdadm.conf
for md in 0 1 2; do
mdadm --detail --brief /dev/md$md >> /etc/mdadm.conf
done

#create new initrd with correct mdadm info
dracut -f

#get UUID of / for the next steps
blkid /dev/md2
/dev/md2: UUID="0e68a84d-cb61-4856-b23b-c2e2aa8294fb" TYPE="ext4"

#backup grub menu.lst
cp /boot/grub/menu.lst /boot/grub/menu.lst-before-raid

#disable selinux just in case
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

#change this:
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-431.el6.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
        initrd /initramfs-2.6.32-431.el6.x86_64.img

#

#to:
default=0
timeout=5
#splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-431.el6.x86_64)
        root (hd1,0)
        kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=UUID=0e68a84d-cb61-4856-b23b-c2e2aa8294fb KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
        initrd /initramfs-2.6.32-431.el6.x86_64.img

#

#install grub on second drive


[root@localhost /]# grub
Probing devices to guess BIOS drives. This may take a long time.


    GNU GRUB  version 0.97  (640K lower / 3072K upper memory)

 [ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename.]
grub> root (hd1,0)
root (hd1,0)
 Filesystem type is ext2fs, partition type 0xfd
grub> setup (hd1)
setup (hd1)
 Checking if "/boot/grub/stage1" exists... no
 Checking if "/grub/stage1" exists... yes
 Checking if "/grub/stage2" exists... yes
 Checking if "/grub/e2fs_stage1_5" exists... yes
 Running "embed /grub/e2fs_stage1_5 (hd1)"...  27 sectors are embedded.
succeeded
 Running "install /grub/stage1 (hd1) (hd1)1+27 p (hd1,0)/grub/stage2 /grub/grub.conf"... succeeded
Done.
grub>


#edit fstab
#change
/dev/mapper/VolGroup-lv_root /                       ext4    defaults        1 1
UUID=ed0608b8-271a-47e9-b0ee-88060a006b0d /boot                   ext4    defaults        1 2
/dev/mapper/VolGroup-lv_swap swap                    swap    defaults        0 0
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
                                                                                          
#

#get /boot ID
blkid /dev/md0
/dev/md0: UUID="4bcf5b66-9d0c-4f5b-a9d8-2d524fbf1ccf" TYPE="ext4"

# swap ID
blkid /dev/md1
/dev/md1: UUID="821efb1f-95cd-4aab-803b-e26d9fa6a920" TYPE="swap"

#backup /etc/fstab
cp /etc/fstab /etc/fstab-beforeraid

#to
UUID=0e68a84d-cb61-4856-b23b-c2e2aa8294fb /                       ext4    defaults        1 1
UUID=4bcf5b66-9d0c-4f5b-a9d8-2d524fbf1ccf /boot                   ext4    defaults        1 2
UUID=821efb1f-95cd-4aab-803b-e26d9fa6a920 swap                    swap    defaults        0 0
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
                                                                                         
#




#final and crucial grub setup, we need to tell grub that the root is on hd1,0 (or sdb1) and to install it to the first hard drive (which is what will boot and will enter the old environment if we don't do this):
    GNU GRUB  version 0.97  (640K lower / 3072K upper memory)

 [ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename.]
grub> root (hd1,0)
root (hd1,0)
 Filesystem type is ext2fs, partition type 0xfd
grub> setup (hd0)
setup (hd0)
 Checking if "/boot/grub/stage1" exists... no
 Checking if "/grub/stage1" exists... yes
 Checking if "/grub/stage2" exists... yes
 Checking if "/grub/e2fs_stage1_5" exists... yes
 Running "embed /grub/e2fs_stage1_5 (hd0)"...  27 sectors are embedded.
succeeded
 Running "install /grub/stage1 d (hd0) (hd0)1+27 p (hd1,0)/grub/stage2 /grub/grub.conf"... succeeded
Done.
 


Tags:

centos, convert, lvm, raid, mdadm, array, reinstallinghere, installed, default, minimal, disk, install, reinstall, kvm, downtime, dataloss, etc, tutorial, swap, intervention, rsync, yum, disable, selinux, login, logout, instantly, logs, sed, enforcing, disabled, config, pam_unix, user, uid, tty, partitions, disc, dev, sdb, md, partition, fdisk, dos, compatible, mode, deprecated, recommended, display, sectors, extended, primary, cylinder, cylinders, hex, codes, fd, linux, autodetect, mb, bytes, sector, optimal, identifier, altered, ioctl, syncing, disks, arrays, metadata, devices, layout, localhost, defaulting, proc, mdstat, personalities, active, chunks, copies, u_, filesystems, mkfs, ext, mke, fs, filesystem, label, os, fragment, stride, stripe, width, inodes, reserved, maximum, groups, fragments, superblock, backups, stored, inode, creating, superblocks, accounting, automatically, mounts, whichever, override, mkswap, erase, bootbits, swapspace, kib, uuid, efb, aab, fa, chroot, mount, mnt, mkdir, phaz, exclude, sys, speedup, bind, conf, initrd, info, dracut, blkid, quot, cb, aa, fb, grub, lst, cp, timeout, splashimage, hd, splash, xpm, gz, hiddenmenu, _, kernel, vmlinuz, ro, mapper, volgroup, lv_root, rd_no_luks, lang, en_us, utf, rd_no_md, rd_lvm_lv, lv_swap, sysfont, latarcyrheb, crashkernel, auto, keyboardtype, pc, keytable, rd_no_dm, rhgb, initramfs, img, probing, bios, gnu, bash, editing, supported, tab, lists, completions, filename, xfd, fs_stage, embed, embedded, succeeded, edit, fstab, defaults, ee, tmpfs, shm, devpts, pts, gid, sysfs, bcf, fbf, ccf, beforeraid, crucial,

Latest Articles

  • FreePBX 17 How To Add a Trunk
  • Docker Container Onboot Policy - How to make sure a container is always running
  • FreePBX 17 How To Add Phones / Extensions and Register
  • Warning: The driver descriptor says the physical block size is 2048 bytes, but Linux says it is 512 bytes. solution
  • Cisco How To Use a Third Party SIP Phone (eg. Avaya, 3CX)
  • Cisco Unified Communication Manager (CUCM) - How To Add Phones
  • pptp / pptpd not working in DD-WRT iptables / router
  • systemd-journald high memory usage solution
  • How to Install FreePBX 17 in Linux Debian Ubuntu Mint Guide
  • How To Install Cisco's CUCM (Cisco Unified Communication Manager) 12 Guide
  • Linux Ubuntu Redhat How To Extract Images from PDF
  • Linux and Windows Dual Boot Issue NIC Won't work After Booting Windows
  • Cisco CME How To Enable ACD hunt groups
  • How to install gns3 on Linux Ubuntu Mint
  • How to convert audio for Asterisk .wav format
  • Using Cisco CME Router with Asterisk as a dial-peer
  • Cisco CME How To Configure SIP Trunk VOIP
  • Virtualbox host Only Network Error Failed to save host network interface parameter - Cannot change gateway IP of host only network
  • Cisco CME and C7200 Router Testing and Learning Environment on Ubuntu 20+ Setup Tutorial Guide
  • Abusive IP ranges blacklist