Showing results for 
Search instead for 
Did you mean: 

Mirror the root disk

Go to solution
Super Advisor

Mirror the root disk

Hi All,

i have dl320 g3 server and I just installed RedHat version 5 with the following partitions:

>/dev/sda -----> (First disk)
/dev/sda1 -- /boot
/dev/sda2 -- Will be used by LVM2 as following
/dev/vg00/lvol1 --- /
/dev/vg00/lvol3 --- /home
/dev/vg00/lvol4 --- /tmp
/dev/vg00/lvol5 --- /usr
/dev/vg00/lvol6 --- /var
/dev/vg00/lvol7 --- /opt

*Second Disk
/dev/sdb -- free space and i formatting with LVM mode(Will be mirror to /dev/sda disk (RAID 1))

I have 2 internal disks that are available on the system and are the same size.

I want to mirroring the root disk with another internal disk. by using GUI or text command How i can do it that ?

Trusted Contributor

Re: Mirror the root disk

Honored Contributor

Re: Mirror the root disk

This would be a variation of the procedure described in:

Since your root filesystem is on LVM, you can use pvmove to migrate your vg00 onto the RAID set while it is in use, so there will be no requirement to use a Live CD.

WARNING: if the system is rebooted while in the critical phase of this procedure, you may need to use the RHEL 5 installation CD/DVD in rescue mode to boot the system and complete the mirroring procedure.

DISCLAIMER: I have not tested this procedure.

# Copy the partition table of /dev/sda to /dev/sdb:
sfdisk -d /dev/sda | sfdisk /dev/sdb

# Change the type of partitions on /dev/sdb to "Linux raid autodetect:
fdisk /dev/sdb
SELECT "1" for partition 1
ENTER "fd" for partition type
Repeat for partition 2

# Make sure your system sees the new partition table on /dev/sdb by checking the list of visible partitions:
cat /proc/partitions

# If necessary, use the "partprobe" command to refresh the partition information:

# Create "degraded mirrored RAIDs" on /dev/sdb1 and /dev/sdb2
mdadm -Cv -ayes /dev/md0 -n2 -l1 missing /dev/sdb1
mdadm -Cv -ayes /dev/md1 -n2 -l1 missing /dev/sdb2

# Confirm that the RAIDs are running:
cat /proc/mdstat

# Format /dev/md0: this will be your new /boot.
mkfs.ext3 /dev/md0

# Mount /dev/md0 temporarily to /mnt:
mount /dev/md0 /mnt

# Copy everything from /boot (on /dev/sda1) to /mnt (on /dev/md0):
cp -a /boot/* /mnt/

# Unmount /mnt and /boot
umount /mnt
umount /boot

# Edit your /etc/fstab to mount /boot from /dev/md0 instead of /dev/sda1:
vi /etc/fstab
(At this point, the old /boot is still as it was before, only it won't be mounted when the system comes up - the new /boot will be mounted instead.)

# Mount /boot again, now using /dev/md0:
mount /boot

# Initialize /dev/md1 as LVM PV:
pvcreate /dev/md1

# Join /dev/md1 into vg00:
vgextend vg00 /dev/md1

# (Critical phase begins: *do not reboot* after this point until all the remaining steps are complete)

# Migrate all vg00 content from /dev/sda2 to /dev/md1:
pvmove -i 10 /dev/sda2 /dev/md1
(After this, the old initrd cannot mount the root filesystem, because it is not prepared to activate the RAID devices first)

# Remove the now-empty /dev/sda2 from vg00:
vgreduce vg00 /dev/sda2

# Copy the partition layout of /dev/sdb to /dev/sda:
sfdisk -d /dev/sdb | sfdisk /dev/sda

# Add the corresponding partitions of /dev/sda to the mirror sets:
mdadm /dev/md0 -a /dev/sda1 ; mdadm /dev/md1 -a /dev/sda2
(This will overwrite the old /boot filesystem: your system is definitely not bootable at this point. That will be fixed shortly...)

# The system will automatically resynchronize the mirrors. You can monitor this procedure with "cat /proc/mdstat". Wait for the resync to complete.

# Re-create your initrd: when you do this, mkinitrd will detect your root VG is on a RAID array, and it will add the necessary RAID support modules to the new initrd.

mkinitrd -f /boot/initrd-$(uname -r).img $(uname -r)

# Re-install your bootloader... twice.
The Master Boot Record is located outside /dev/md* devices, so it won't be mirrored automatically. Therefore you must install GRUB separately to both disks.

GRUB identifier "(hd0)" means "first disk detected by the system", so the bootloader on /dev/sdb needs to be installed with the assumption that if/when /dev/sdb is used to actually boot the system (= when current /dev/sda is damaged or removed), it will be (hd0) for GRUB.

The bootloader on /dev/sda must be reinstalled because the physical positions of /boot/grub/* files on the disk have been altered by this procedure.


grub> device (hd0) /dev/sdb
grub> setup (hd0)
grub> device (hd0) /dev/sda
grub> setup (hd0)
grub> quit

# (Critical phase ends: your system should now be capable of booting from RAID without a rescue CD.)

# create /etc/mdadm.conf; add a line with keyword MAILADDR and the mail address that should receive notification from disk failures:
echo "MAILADDR" >/etc/mdadm.conf

# Send a test message:
mdadm --monitor --scan -1 --test
(You should receive a TestMessage alert email for both md0 and md1. The actual RAID disk failure alarms will use a similar message format.)

# configure the RAID monitoring service to start at boot, and start it now:
chkconfig mdmonitor on
service mdmonitor start

Viktor Balogh
Honored Contributor

Re: Mirror the root disk

Hi Nejad,

Please be aware that for software two-way mirroring (that means mirroring with LVM) you need three disks: two for the two half of the mirror, and one for logging. Alternatively, you can do it from two disks by keeping the logs in memory. For further info, see "man lvconvert" and particularly the --corelog switch.

Unix operates with beer.
Super Advisor

Re: Mirror the root disk

Hi All,

I facing this message when applying this command # sfdisk -d /dev/sdb | sfdisk /dev/sda
/dev/sda2: Moved: 100.0%
[root@syslog /]# vgreduce vg00 /dev/sda2
Removed "/dev/sda2" from volume group "vg00"
[root@syslog /]# sfdisk -d /dev/sdb | sfdisk /dev/sda
Checking that no-one is using this disk right now ...
BLKRRPART: Device or resource busy

This disk is currently in use - repartitioning is probably a bad idea.
Umount all file systems, and swapoff all swap partitions on this disk.
Use the --no-reread flag to suppress this check.
Use the --force flag to overrule all checks."

How to skip this problem?

Honored Contributor

Re: Mirror the root disk

The advice given by the fdisk command is actually very good.

Looks like /dev/sda is still being used for something.

Perhaps it contains a swap partition? Run "swapon -s". If it lists any reference to /dev/sda (e.g. /dev/sda3), then you've found the cause. With "swapoff -a" you can disable swapping for the mirroring procedure. When you reboot the system or run "swapon -a", the swap partition will be enabled again.

If a swap partition is not the cause, then please show the output of these commands:

fdisk -l /dev/sda
cat /proc/mounts

Super Advisor

Re: Mirror the root disk


the problem is still and i facing a new message it is

# swapon -s
Filename Type Size Used Priority
/dev/mapper/vg00-lvol2 partition 4194296 0 -1
# swapoff -a
# mdadm /dev/md0 -a /dev/sda1
mdadm: cannot get array info for /dev/md0

Please review the results of these commands.

root@syslog /]# fdisk -l /dev/sda

Disk /dev/sda: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 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 30401 244091610 8e Linux LVM
[root@syslog /]#
[root@syslog /]# cat /proc/mounts
rootfs / rootfs rw 0 0
/dev/root / ext3 rw,data=ordered 0 0
/dev /dev tmpfs rw 0 0
/proc /proc proc rw 0 0
/sys /sys sysfs rw 0 0
none /selinux selinuxfs rw 0 0
/proc/bus/usb /proc/bus/usb usbfs rw 0 0
devpts /dev/pts devpts rw 0 0
/dev/vg00/lvol6 /var ext3 rw,data=ordered 0 0
/dev/vg00/lvol7 /opt ext3 rw,data=ordered 0 0
/dev/vg00/lvol3 /home ext3 rw,data=ordered 0 0
/dev/vg00/lvol4 /tmp ext3 rw,data=ordered 0 0
tmpfs /dev/shm tmpfs rw 0 0
/dev/vg00/lvol5 /usr ext3 rw,data=ordered 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
sunrpc /var/lib/nfs/rpc_pipefs rpc_pipefs rw 0 0
/etc/auto.misc /misc autofs rw,fd=7,pgrp=3128,timeout=300,minproto=5,maxproto=5,indirect 0 0
-hosts /net autofs rw,fd=13,pgrp=3128,timeout=300,minproto=5,maxproto=5,indirect 0 0
none /var/lib/xenstored tmpfs rw 0 0
/dev/sda1 /boot ext3 rw,data=ordered 0 0