opennode-os

OpenNode OS migration to softraid (live)

If in need to migrate OpenNode OS from single disk installation (no hardware raid) to linux software raid setup (RAID1) - please use this recipe. Conversion can be done online without much interrupting server operations besides a bit reduced disk IO.

Migration process

# Partition scheme on sdb
# /dev/sdb1 - 1GB
# /dev/sdb2 - rest of the disk for LVM PV
# set part 1,2 types to RAID
# set boot flag on /dev/sdb1

# We are using parted - as it's GPT aware tool
parted
select /dev/sdb
# Make msdos disk label when using disks up to 2TB
mklabel msdos
# Make GPT disk label when using disks larger than 2TB
mklabel gpt
# Create /boot raid partition
mkpart primary 0 1G
mkpart primary 1G -1
set 1 boot on
set 1 raid on
set 2 raid on
quit

# Refresh kernel partition table before proceeding
partprobe /dev/sdb
    
# Zero out previous raid superblocks (if any)
mdadm --zero-superblock /dev/sdb1   # it's ok to get errors like 'Unrecognised md component device' - means that no remainings of RAID are left
mdadm --zero-superblock /dev/sdb2

# Create raid devices (using --assume-clean avoid first resync)
mdadm --create /dev/md0 --level 1 --metadata=0.90 --raid-devices=2 --assume-clean missing /dev/sdb1
mdadm --create /dev/md1 --level 1 --raid-devices=2 --assume-clean missing /dev/sdb2
    
# Format boot device
mkfs.ext4 /dev/md0

# Copy data from boot part
mount /dev/md0 /mnt/
rsync -av /boot/* /mnt/
rsync -av /boot/.vm* /mnt/
umount /mnt

# Mount new boot part
umount /boot
mount /dev/md0 /boot

# Migrate LVM data to raid
pvcreate /dev/md1
vgextend VolGroupL0 /dev/md1
pvmove /dev/sda2 /dev/md1
vgreduce VolGroupL0 /dev/sda2
pvremove /dev/sda2

# Re-create sda partitions for raid setup
parted
select /dev/sda
mklabel msdos / gpt
mkpart primary 0 1G
mkpart primary 1G -1
set 1 boot on
set 1 raid on
set 2 raid on
quit

# Refresh kernel partition table before proceeding
partprobe /dev/sda

#add sda boot partition to RAID
mdadm /dev/md0 --add /dev/sda1

# Create mdadm.conf
cp /etc/mdadm.conf /etc/mdadm.conf_orig
mdadm --examine --scan >> /etc/mdadm.conf

# Edit /boot/grub/device.map
nano -w /boot/grub/device.map
--- MODIFY ---
(hd0)   /dev/sda
(hd1)   /dev/sdb
--- MODIFY ---

# Get MD1 array UUID
cat /etc/mdadm.conf | grep md/1

# Update grub conf
nano -w /boot/grub/grub.conf
# remove rd_NO_MD option from kernel boot options
# add rd_MD_UUID=$UUID to kernel boot options
# example:
# kernel /vmlinuz-2.6.32-042stab053.5 ro root=/dev/mapper/VolGroupL0-root rd_LVM_LV=VolGroupL0/root rd_MD_UUID=1c95d02a:15fa85c9:6f10d779:265c3e45 rd_LVM_LV=VolGroupL0/swap rd_NO_LUKS rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us crashkernel=auto rhgb quiet

# Install bootloader to sda and sdb MBR
grub-install /dev/sda
grub-install /dev/sdb

# Get the boot filesystem UUID
tune2fs -l /dev/md0 | grep UUID
# Replace boot part UUID in fstab
nano -w /etc/fstab

# Add LVM part for resync
mdadm /dev/md1 --add /dev/sda2

#Tip - how to verify bootloader in MBR (should return strings containing GRUB)
file -s /dev/sda
file -s /dev/sdb