You are on page 1of 20

ROOT DISK MIRRORING ON DEBIAN

LINUX
Mirror is a simple way to gain redundancy on a single Unix server. By building mirrored root disks
(as a RAID1 Group), system would be safer in case one disk failed. System still accessible
anytime a single disk failure happen.

Mirroring with 2 physical disks


In this scenario we will try to build a mirrored root disk on Debian Linux server. We will prepare
new disk drive as first component of RAID1 group. Then we will copy all content of root disk into
it. After data has been copied, we will reboot the server and force the server to boot using the
new disk. Once the system up, we will attach existing root disk as second component of RAID1
group. At the end we can use both disk as bootable disk.

Preparation
1. Lets start by identified existing system :
Platform : this test environment is using Debian Linux release 7.1 (code name :
Wheezy) :
root@debian01:~#0date
Tue0Sep024000:48:070WIT02013
root@debian01:~#0uname0=a
Linux0debian0103.2.0=4=686=pae0#10SMP0Debian03.2.46=1+deb7u10i6860GNU/Linux
root@debian01:~#0lsb_release0=a
No0LSB0modules0are0available.
Distributor0ID:0Debian

Description:0000Debian0GNU/Linux07.10(wheezy)
Release:00007.1
Codename:000wheezy
root@debian01:~#0

Physical disks : we can check installed disks using fdisk0=l command as shown in
the following example :
root@debian01:~#0fdisk0=l
Disk0/dev/sda:021.50GB,0214748364800bytes
2550heads,0630sectors/track,026100cylinders,0total0419430400sectors
Units0=0sectors0of010*05120=05120bytes
Sector0size0(logical/physical):05120bytes0/05120bytes
I/O0size0(minimum/optimal):05120bytes0/05120bytes
Disk0identifier:00x0004f798
000Device0Boot000000Start000000000End000000Blocks000Id00System
/dev/sda1000*0000000020480000001945590000000962560008300Linux
/dev/sda200000000001945600000197263350000097658880008300Linux
/dev/sda300000000197263360000236318710000019527680008200Linux0swap0/0Solaris
/dev/sda400000000236318720000419409910000091545600008300Linux
Disk0/dev/sdb:021.50GB,0214748364800bytes
2550heads,0630sectors/track,026100cylinders,0total0419430400sectors
Units0=0sectors0of010*05120=05120bytes
Sector0size0(logical/physical):05120bytes0/05120bytes
I/O0size0(minimum/optimal):05120bytes0/05120bytes
Disk0identifier:00x00000000
Disk0/dev/sdb0doesn't0contain0a0valid0partition0table
root@debian01:~#

On the example above, we can see 2 disk drives installed. First is the active root disk
( /dev/sda ) and the second one is new disk ( /dev/sdb ).
ASSUMPTION : For the sake of simplicity we will call the existing root disk
( /dev/sda ) as rootdisk . And the second disk ( /dev/sdb ) as rootmirror .
Filesystem : we also need to know what filesystem used by each partition. To do that
we can use blkid command that also can provide us UUID information for each
partition :
root@debian01:~#0blkid
/dev/sda3:0UUID="c1b679fb=d59f=4478=a138=fe2e3a6bceb0"0TYPE="swap"
/dev/sr0:0LABEL="Debian07.1.00i38601"0TYPE="iso9660"
/dev/sda1:0UUID="1398dd06=7ef2=46c3=9ace=a2328b1db783"0TYPE="ext3"
/dev/sda2:0UUID="4a066d6d=c8ad=46a4=ae54=118da63dcbd2"0TYPE="ext3"
/dev/sda4:0UUID="8d819942=fe5d=4634=aab7=28ceca9b2fe1"0TYPE="ext3"
root@debian01:~#

Partition structure : we can check existing partition structure & its mountpoint by
examining the /etc/fstab file :
root@debian01:~#0cat0/etc/fstab
#0/etc/fstab:0static0file0system0information.

#
#0Use0'blkid'0to0print0the0universally0unique0identifier0for0a
#0device;0this0may0be0used0with0UUID=0as0a0more0robust0way0to0name0devices
#0that0works0even0if0disks0are0added0and0removed.0See0fstab(5).
#
#0<file0system>0<mount0point>000<type>00<options>0000000<dump>00<pass>
#0/0was0on0/dev/sda20during0installation
UUID=4a066d6d=c8ad=46a4=ae54=118da63dcbd20/000000000000000ext30000errors=remount=ro000000000
1
#0/boot0was0on0/dev/sda10during0installation
UUID=1398dd06=7ef2=46c3=9ace=a2328b1db7830/boot00000000000ext30000defaults0000000000000000
2
#0/home0was0on0/dev/sda40during0installation
UUID=8d819942=fe5d=4634=aab7=28ceca9b2fe10/home00000000000ext30000defaults0000000000000000
2
#0swap0was0on0/dev/sda30during0installation
UUID=c1b679fb=d59f=4478=a138=fe2e3a6bceb00none000000000000swap0000sw0000000000000000000000
0
/dev/sr000000000/media/cdrom0000udf,iso96600user,noauto00000000000000
root@debian01:~#0

Or we can use the simplest but slightly less informative df command :


root@debian01:~#0df0=h
Filesystem0000000000000000000000000000000000000000000000Size00Used0Avail0Use%0Mounted0
on
rootfs000000000000000000000000000000000000000000000000009.2G00636M008.1G0008%0/
udev0000000000000000000000000000000000000000000000000000010M00000000010M0000%0/dev
tmpfs000000000000000000000000000000000000000000000000000101M00236K00101M0001%0/run
/dev/disk/by=uuid/4a066d6d=c8ad=46a4=ae54=118da63dcbd2009.2G00636M008.1G0008%0/
tmpfs0000000000000000000000000000000000000000000000000005.0M000000005.0M0000%0
/run/lock
tmpfs000000000000000000000000000000000000000000000000000584M00000000584M0000%0
/run/shm
/dev/sda100000000000000000000000000000000000000000000000092M00022M00065M0025%0/boot
/dev/sda4000000000000000000000000000000000000000000000008.6G00148M008.1G0002%0/home
root@debian01:~#

From those two output, we know that :


/dev/sda1 contains /boot filesystem
/dev/sda2 contains root filesystem
/dev/sda3 used as swap space
/dev/sda4 contains /home filesystem
2. We will use mdadm package for manage RAID group and build the mirror. To install mdadm
package in Debian-way, we can use apt=get0install command as shown below :
root@debian01:~#0apt=get0install0mdadm
Reading0package0lists...0Done
Building0dependency0tree0000000
Reading0state0information...0Done
The0following0NEW0packages0will0be0installed:
00mdadm
00upgraded,010newly0installed,000to0remove0and000not0upgraded.
Need0to0get000B/5660kB0of0archives.
After0this0operation,010980kB0of0additional0disk0space0will0be0used.
Preconfiguring0packages0...
Selecting0previously0unselected0package0mdadm.

(Reading0database0...0246940files0and0directories0currently0installed.)
Unpacking0mdadm0(from0.../m/mdadm/mdadm_3.2.5=5_i386.deb)0...
Processing0triggers0for0man=db0...
Setting0up0mdadm0(3.2.5=5)0...
Generating0array0device0nodes...0done.
Generating0mdadm.conf...0done.
update=initramfs:0deferring0update0(trigger0activated)
[0ok0]0Assembling0MD0arrays...done0(no0arrays0found0in0config0file0or0automatically).
[0ok0]0Starting0MD0monitoring0service:0mdadm0==monitor.
Processing0triggers0for0initramfs=tools0...
update=initramfs:0Generating0/boot/initrd.img=3.2.0=4=686=pae
W:0mdadm:0/etc/mdadm/mdadm.conf0defines0no0arrays.
W:0mdadm:0no0arrays0defined0in0configuration0file.
root@debian01:~#0

3. Before moving forward, we need to backup several important files


( /etc/fstab , /etc/default/grub , and /etc/mdadm/mdadm.conf ) as shown in the
following example :
root@debian01:~#0cp0/etc/fstab0/etc/fstab_orig
root@debian01:~#0cp0/etc/default/grub00/etc/default/grub_orig
root@debian01:~#0cp0/etc/mdadm/mdadm.conf00/etc/mdadm/mdadm.conf_orig

4. Next we need to load several module to the running kernel :


root@debian01:~#0modprobe0linear
root@debian01:~#0modprobe0multipath
root@debian01:~#0modprobe0raid0
root@debian01:~#0modprobe0raid1
root@debian01:~#0modprobe0raid5
root@debian01:~#0modprobe0raid6
root@debian01:~#0modprobe0raid10

5. Information of active & running RAID group can be seen inside /proc/mdstat file :
root@debian01:~#0cat0/proc/mdstat0
Personalities0:0[linear]0[multipath]0[raid0]0[raid1]0[raid6]0[raid5]0[raid4]0[raid10]0
unused0devices:0<none>
root@debian01:~#0

We cant see any information yet since we dont have active RAID group yet. Soon we will
go back checking /proc/mdstat when the RAID1 group has been created.

RAID1 Group Setup


We will start create new RAID1 Group for join both disks as mirrored configuration.
1. First we will work on the new ( /dev/sdb ) or what we called rootmirror . We need to
prepare rootmirror before put it in the RAID1 group. Since rootmirror is new disk, it
doesnt have valid partition table yet :
root@debian01:~#0fdisk0=l0/dev/sdb

Disk0/dev/sdb:021.50GB,0214748364800bytes
2550heads,0630sectors/track,026100cylinders,0total0419430400sectors
Units0=0sectors0of010*05120=05120bytes
Sector0size0(logical/physical):05120bytes0/05120bytes
I/O0size0(minimum/optimal):05120bytes0/05120bytes
Disk0identifier:00x00000000
Disk0/dev/sdb0doesn't0contain0a0valid0partition0table
root@debian01:~#0

What we need to do is copy the partition table from the existing root disk ( /dev/sda ) using
sfdisk command as shown below :
root@debian01:~#0sfdisk0=d0/dev/sda0|0sfdisk0==force0/dev/sdb
Checking0that0no=one0is0using0this0disk0right0now0...
OK
Disk0/dev/sdb:026100cylinders,02550heads,0630sectors/track
sfdisk:0ERROR:0sector000does0not0have0an0msdos0signature
0/dev/sdb:0unrecognized0partition0table0type
Old0situation:
No0partitions0found
New0situation:
Units0=0sectors0of05120bytes,0counting0from00
000Device0Boot0000Start0000000End000#sectors00Id00System
/dev/sdb1000*0000002048000019455900000192512008300Linux
/dev/sdb200000000194560001972633500019531776008300Linux
/dev/sdb300000019726336002363187100003905536008200Linux0swap0/0Solaris
/dev/sdb400000023631872004194099100018309120008300Linux
Warning:0partition010does0not0end0at0a0cylinder0boundary
Warning:0partition020does0not0start0at0a0cylinder0boundary
Warning:0partition020does0not0end0at0a0cylinder0boundary
Warning:0partition030does0not0start0at0a0cylinder0boundary
Warning:0partition030does0not0end0at0a0cylinder0boundary
Warning:0partition040does0not0start0at0a0cylinder0boundary
Warning:0partition040does0not0end0at0a0cylinder0boundary
Successfully0wrote0the0new0partition0table
Re=reading0the0partition0table0...
If0you0created0or0changed0a0DOS0partition,0/dev/foo7,0say,0then0use0dd(1)
to0zero0the0first05120bytes:00dd0if=/dev/zero0of=/dev/foo70bs=5120count=1
(See0fdisk(8).)
root@debian01:~#0

After copy the partition table, we can see that rootmirror now has the same partition
layout as the root disk :
root@debian01:~#0fdisk0=l0/dev/sdb
Disk0/dev/sdb:021.50GB,0214748364800bytes
2550heads,0630sectors/track,026100cylinders,0total0419430400sectors
Units0=0sectors0of010*05120=05120bytes
Sector0size0(logical/physical):05120bytes0/05120bytes
I/O0size0(minimum/optimal):05120bytes0/05120bytes
Disk0identifier:00x00000000
000Device0Boot000000Start000000000End000000Blocks000Id00System

/dev/sdb1000*0000000020480000001945590000000962560008300Linux
/dev/sdb200000000001945600000197263350000097658880008300Linux
/dev/sdb300000000197263360000236318710000019527680008200Linux0swap0/0Solaris
/dev/sdb400000000236318720000419409910000091545600008300Linux
root@debian01:~#

2. Since we will join rootmirror into a RAID1 group, we need to set every partition under it
to use Linux raid auto type. We use fdisk command to set the partition type, here is the
sample :
root@debian01:~#0fdisk0/dev/sdb
Command0(m0for0help):0t
Partition0number0(1=4):01
Hex0code0(type0L0to0list0codes):0L
0000Empty000000000002400NEC0DOS0000000008100Minix0/0old0Lin0bf00Solaris00000000
0100FAT12000000000002700Hidden0NTFS0Win08200Linux0swap0/0So0c100DRDOS/sec0(FAT=
0200XENIX0root0000003900Plan0900000000008300Linux00000000000c400DRDOS/sec0(FAT=
0300XENIX0usr00000003c00PartitionMagic008400OS/20hidden0C:00c600DRDOS/sec0(FAT=
0400FAT160<32M0000004000Venix080286000008500Linux0extended00c700Syrinx000000000
0500Extended000000004100PPC0PReP0Boot0008600NTFS0volume0set0da00Non=FS0data0000
0600FAT16000000000004200SFS00000000000008700NTFS0volume0set0db00CP/M0/0CTOS0/0.
0700HPFS/NTFS/exFAT04d00QNX4.x00000000008800Linux0plaintext0de00Dell0Utility000
0800AIX00000000000004e00QNX4.x02nd0part08e00Linux0LVM0000000df00BootIt000000000
0900AIX0bootable00004f00QNX4.x03rd0part09300Amoeba0000000000e100DOS0access00000
0a00OS/20Boot0Manag05000OnTrack0DM0000009400Amoeba0BBT000000e300DOS0R/O00000000
0b00W950FAT3200000005100OnTrack0DM60Aux09f00BSD/OS0000000000e400SpeedStor000000
0c00W950FAT320(LBA)05200CP/M000000000000a000IBM0Thinkpad0hi0eb00BeOS0fs00000000
0e00W950FAT160(LBA)05300OnTrack0DM60Aux0a500FreeBSD000000000ee00GPT000000000000
0f00W950Ext'd0(LBA)05400OnTrackDM6000000a600OpenBSD000000000ef00EFI0(FAT=12/16/
1000OPUS0000000000005500EZ=Drive00000000a700NeXTSTEP00000000f000Linux/PA=RISC0b
1100Hidden0FAT1200005600Golden0Bow000000a800Darwin0UFS000000f100SpeedStor000000
1200Compaq0diagnost05c00Priam0Edisk00000a900NetBSD0000000000f400SpeedStor000000
1400Hidden0FAT160<306100SpeedStor0000000ab00Darwin0boot00000f200DOS0secondary00
1600Hidden0FAT1600006300GNU0HURD0or0Sys0af00HFS0/0HFS+000000fb00VMware0VMFS0000
1700Hidden0HPFS/NTF06400Novell0Netware00b700BSDI0fs000000000fc00VMware0VMKCORE0
1800AST0SmartSleep006500Novell0Netware00b800BSDI0swap0000000fd00Linux0raid0auto
1b00Hidden0W950FAT307000DiskSecure0Mult0bb00Boot0Wizard0hid0fe00LANstep00000000
1c00Hidden0W950FAT307500PC/IX00000000000be00Solaris0boot0000ff00BBT000000000000
1e00Hidden0W950FAT108000Old0Minix000000
Hex0code0(type0L0to0list0codes):0fd
Changed0system0type0of0partition020to0fd0(Linux0raid0autodetect)
00000000Command0(m0for0help):0t
00000000Partition0number0(1=4):02
00000000Hex0code0(type0L0to0list0codes):0fd
00000000Changed0system0type0of0partition010to0fd0(Linux0raid0autodetect)
Command0(m0for0help):0t
Partition0number0(1=4):03
Hex0code0(type0L0to0list0codes):0fd
Changed0system0type0of0partition030to0fd0(Linux0raid0autodetect)
Command0(m0for0help):0t
Partition0number0(1=4):04
Hex0code0(type0L0to0list0codes):0fd
Changed0system0type0of0partition040to0fd0(Linux0raid0autodetect)
Command0(m0for0help):0w
The0partition0table0has0been0altered!

Calling0ioctl()0to0re=read0partition0table.
Syncing0disks.
root@debian01:~#0

Here is the explanation about what happen on the example above :


Start fdisk utility by typing fdisk0/dev/sdb followed by Enter. fdisk utility will
ready to work on /dev/sdb .
Type t to start setting the partition type. Press Enter to continue.
Then type the number of partition we want to set. Press Enter to continue.
There are many partition type available, we can see all available type by type L
followed by Enter.
In this case we want to use partition type Linux raid auto so we type fd followed by
Enter.
After all partition set up, we must finalize the changes by typing w (as in Write this
changes to the disk) followed by Enter.
3. With partition type already set, we can continue create md device a.k.a virtual partition.
md is abrreviation for Multiple Devices. Before create new md device, we should clean up
the partition using the following command :
00000000root@debian01:~#0mdadm0==zero=superblock0/dev/sdb1
00000000root@debian01:~#0mdadm0==zero=superblock0/dev/sdb2
00000000root@debian01:~#0mdadm0==zero=superblock0/dev/sdb3
00000000root@debian01:~#0mdadm0==zero=superblock0/dev/sdb4

Actually this step only applicable if the partition has been used as md device. In this case it
didnt really matter since we use new empty disk.
4. To start create md device, we use mdadm0==create command. Here is the syntax to
create md device using mdadm command :
mdadm0==create0/dev/md<ID>0==level=<RAID0level>0==raid=disks=<number0of0physical0disk>0
<disk#1>0<disk#2>

We will create md device for each partition. Since we want to create RAID1 disk group, we
set ==level=1 . And because we only have 2 physical disks involved, then we set
==raid=disks=2 .
So lets start to prepare first partition on rootmirror as first md device :
root@debian01:~#0mdadm0==create0/dev/md00==level=10==raid=disks=20missing0/dev/sdb1
mdadm:0Note:0this0array0has0metadata0at0the0start0and
0000may0not0be0suitable0as0a0boot0device.00If0you0plan0to
0000store0'/boot'0on0this0device0please0ensure0that
0000your0boot=loader0understands0md/v1.x0metadata,0or0use
0000==metadata=0.90
Continue0creating0array?0y
mdadm:0Defaulting0to0version01.20metadata
mdadm:0array0/dev/md00started.

root@debian01:~#

Because we dont want to touch the existing root disk ( /dev/sda ) yet, we will mark it as
missing .
Then we can continue with second partition of rootmirror :
root@debian01:~#0mdadm0==create0/dev/md10==level=10==raid=disks=20missing0/dev/sdb2
mdadm:0Note:0this0array0has0metadata0at0the0start0and
0000may0not0be0suitable0as0a0boot0device.00If0you0plan0to
0000store0'/boot'0on0this0device0please0ensure0that
0000your0boot=loader0understands0md/v1.x0metadata,0or0use
0000==metadata=0.90
Continue0creating0array?0y
mdadm:0Defaulting0to0version01.20metadata
mdadm:0array0/dev/md10started.
root@debian01:~#0

Finish by create virtual partition for third and fourth partition of rootmirror :
root@debian01:~#0mdadm0==create0/dev/md20==level=10==raid=disks=20missing0/dev/sdb3
mdadm:0Note:0this0array0has0metadata0at0the0start0and
0000may0not0be0suitable0as0a0boot0device.00If0you0plan0to
0000store0'/boot'0on0this0device0please0ensure0that
0000your0boot=loader0understands0md/v1.x0metadata,0or0use
0000==metadata=0.90
Continue0creating0array?0y
mdadm:0Defaulting0to0version01.20metadata
mdadm:0array0/dev/md20started.
root@debian01:~#
root@debian01:~#0mdadm0==create0/dev/md30==level=10==raid=disks=20missing0/dev/sdb4
mdadm:0Note:0this0array0has0metadata0at0the0start0and
0000may0not0be0suitable0as0a0boot0device.00If0you0plan0to
0000store0'/boot'0on0this0device0please0ensure0that
0000your0boot=loader0understands0md/v1.x0metadata,0or0use
0000==metadata=0.90
Continue0creating0array?0y
mdadm:0Defaulting0to0version01.20metadata
mdadm:0array0/dev/md30started.
root@debian01:~#0

5. Now we have 4 virtual partition, so the next step is to make the new filesystem on each
partition. We will use ext3 filesystem for /dev/md0 , /dev/md1 , and /dev/md3 . To
create a ext3 filesystem we use mkfs.ext3 command as shown in the following example
:
root@debian01:~#0mkfs.ext30/dev/md00
mke2fs01.42.50(29=Jul=2012)
Filesystem0label=
OS0type:0Linux
Block0size=10240(log=0)
Fragment0size=10240(log=0)
Stride=00blocks,0Stripe0width=00blocks
240960inodes,0961280blocks
48060blocks0(5.00%)0reserved0for0the0super0user
First0data0block=1
Maximum0filesystem0blocks=67371008

120block0groups
81920blocks0per0group,081920fragments0per0group
20080inodes0per0group
Superblock0backups0stored0on0blocks:0
00008193,024577,040961,057345,073729
Allocating0group0tables:0done0000000000000000000000000000
Writing0inode0tables:0done0000000000000000000000000000
Creating0journal0(40960blocks):0done
Writing0superblocks0and0filesystem0accounting0information:0done0
root@debian01:~#0mkfs.ext30/dev/md1
mke2fs01.42.50(29=Jul=2012)
Filesystem0label=
OS0type:0Linux
Block0size=40960(log=2)
Fragment0size=40960(log=2)
Stride=00blocks,0Stripe0width=00blocks
6108000inodes,024393920blocks
1219690blocks0(5.00%)0reserved0for0the0super0user
First0data0block=0
Maximum0filesystem0blocks=2499805184
750block0groups
327680blocks0per0group,0327680fragments0per0group
81440inodes0per0group
Superblock0backups0stored0on0blocks:0
000032768,098304,0163840,0229376,0294912,0819200,0884736,01605632
Allocating0group0tables:0done0000000000000000000000000000
Writing0inode0tables:0done0000000000000000000000000000
Creating0journal0(327680blocks):0done
Writing0superblocks0and0filesystem0accounting0information:0done0
root@debian01:~#0mkfs.ext30/dev/md3
mke2fs01.42.50(29=Jul=2012)
Filesystem0label=
OS0type:0Linux
Block0size=40960(log=2)
Fragment0size=40960(log=2)
Stride=00blocks,0Stripe0width=00blocks
5723200inodes,022865600blocks
1143280blocks0(5.00%)0reserved0for0the0super0user
First0data0block=0
Maximum0filesystem0blocks=2344615936
700block0groups
327680blocks0per0group,0327680fragments0per0group
81760inodes0per0group
Superblock0backups0stored0on0blocks:0
000032768,098304,0163840,0229376,0294912,0819200,0884736,01605632
Allocating0group0tables:0done0000000000000000000000000000
Writing0inode0tables:0done0000000000000000000000000000
Creating0journal0(327680blocks):0done
Writing0superblocks0and0filesystem0accounting0information:0done0
root@debian01:~#

6. For /dev/md2 , we will marked it as swap space using mkswap command as shown in the
following example :
root@debian01:~#0mkswap0=f0/dev/md2
Setting0up0swapspace0version01,0size0=019516760KiB

no0label,0UUID=2fa8b47b=e889=4160=9fd0=c21b88b6d3e3
root@debian01:~#0

7. Each virtual partition need to be started during the boot process. So we need to register all
the virtual partition we had made into mdadm.conf file. What we need to register is the
output of the following command :
root@debian01:~#0mdadm0==examine0==scan
ARRAY0/dev/md/00metadata=1.20UUID=5d7d8672:c019a7d0:69310f29:3cd65d040name=debian01:0
ARRAY0/dev/md/10metadata=1.20UUID=67631129:b7766c7e:d1200d55:036ad1c60name=debian01:1
ARRAY0/dev/md/20metadata=1.20UUID=19cbe54c:2aa2126c:92eda6ee:ffc62fb90name=debian01:2
ARRAY0/dev/md/30metadata=1.20UUID=d15793a1:348c6380:a94d73b3:a47f3bf70name=debian01:3
root@debian01:~#0

We can copy those output to /etc/mdadm/mdadm.conf manually using text editor, or we


can use simple redirection as shown below :
root@debian01:~#0mdadm0==examine0==scan0>>0/etc/mdadm/mdadm.conf

8. In the Linux system each partition will has its own mountpoint (except for swap partition).
Information about the partition and related mountpoint stored inside /etc/fstab file. Here
is the sample of /etc/fstab file :
root@debian01:~#0cat0/etc/fstab
#0/etc/fstab:0static0file0system0information.
#
#0Use0'blkid'0to0print0the0universally0unique0identifier0for0a
#0device;0this0may0be0used0with0UUID=0as0a0more0robust0way0to0name0devices
#0that0works0even0if0disks0are0added0and0removed.0See0fstab(5).
#
#0<file0system>0<mount0point>000<type>00<options>0000000<dump>00<pass>
#0/0was0on0/dev/sda20during0installation
UUID=4a066d6d=c8ad=46a4=ae54=118da63dcbd20/000000000000000ext30000errors=remount=ro000000000
1
#0/boot0was0on0/dev/sda10during0installation
UUID=1398dd06=7ef2=46c3=9ace=a2328b1db7830/boot00000000000ext30000defaults0000000000000000
2
#0/home0was0on0/dev/sda40during0installation
UUID=8d819942=fe5d=4634=aab7=28ceca9b2fe10/home00000000000ext30000defaults0000000000000000
2
#0swap0was0on0/dev/sda30during0installation
UUID=c1b679fb=d59f=4478=a138=fe2e3a6bceb00none000000000000swap0000sw0000000000000000000000
0
/dev/sr000000000/media/cdrom0000udf,iso96600user,noauto00000000000000
root@debian01:~#0

Each partition displayed with its UUID (Universally Unique Identifier). Those UUID is
belongs to existing root disk ( /dev/sda ). We need to modify the partition address using
new virtual partition identity. Here is the final /etc/fstab after modification :
root@debian01:~#0cat0/etc/fstab
#0/etc/fstab:0static0file0system0information.
#
#0Use0'blkid'0to0print0the0universally0unique0identifier0for0a
#0device;0this0may0be0used0with0UUID=0as0a0more0robust0way0to0name0devices

#0that0works0even0if0disks0are0added0and0removed.0See0fstab(5).
#
#0<file0system>0<mount0point>000<type>00<options>0000000<dump>00<pass>
/dev/md10000/000000000000000ext30000errors=remount=ro000000000001
/dev/md00000/boot00000000000ext30000defaults000000000000000000002
/dev/md30000/home00000000000ext30000defaults000000000000000000002
/dev/md20000none000000000000swap0000sw000000000000000000000000000
/dev/sr00000/media/cdrom0000udf,iso96600user,noauto00000000000000
root@debian01:~#

9. Next step is to modify /etc/default/grub . We need to set GRUB_DISABLE_LINUX_UUID


parameter to true . By default GRUB_DISABLE_LINUX_UUID0=0true was commented, so
what we need is to remove # to uncommented that line.
10. Before start copying all existing root disk files, we need to mount each virtual partition. Here
is the sample how we mount all virtual partitions :
root@debian01:~#0mkdir0/mnt/md0
root@debian01:~#0mkdir0/mnt/md1
root@debian01:~#0mkdir0/mnt/md3
root@debian01:~#0mount0/dev/md00/mnt/md0
root@debian01:~#0mount0/dev/md10/mnt/md1
root@debian01:~#0mount0/dev/md30/mnt/md3

We dont mount /dev/md2 since it is swap partition.


11. With all virtual partition mounted, we can start copy files from existing root disk :
root@debian01:~#0cp0=dpRx0/0/mnt/md10
root@debian01:~#0cp0=dpRx0/boot0/mnt/md0
root@debian01:~#0cp0=dpRx0/home0/mnt/md3

12. Then we need to install the boot loader on the virtual partition. We will do it from chroot
environment. There are some steps to prepare chroot environment as shown in the
following example :
root@debian01:~#0umount0/mnt/md0
root@debian01:~#0mount0/dev/md00/mnt/md1/boot
root@debian01:~#0mount0=t0proc0none0/mnt/md1/proc
root@debian01:~#0mount0=o0bind0/dev0/mnt/md1/dev
root@debian01:~#0mount0=o0bind0/sys0/mnt/md1/sys

13. We can continue to enter chroot environment & execute update=grub command to fix
the boot loader as shown in the following example :
root@debian01:~#0chroot0/mnt/md1
root@debian01:/#0update=grub
Generating0grub.cfg0...
Found0linux0image:0/boot/vmlinuz=3.2.0=4=686=pae
Found0initrd0image:0/boot/initrd.img=3.2.0=4=686=pae
done

14. Still from chroot environment of virtual partitions, we also need to generate the
initramfs image. initramfs is used during boot process to load all root filesystem.
root@debian01:/#0update=initramfs0=u
update=initramfs:0Generating0/boot/initrd.img=3.2.0=4=686=pae
mdadm:0cannot0open0/dev/md/0:0No0such0file0or0directory
mdadm:0cannot0open0/dev/md/1:0No0such0file0or0directory
mdadm:0cannot0open0/dev/md/2:0No0such0file0or0directory
mdadm:0cannot0open0/dev/md/3:0No0such0file0or0directory
root@debian01:/#0

We can ignore those kind of errors for now.


15. Last things must be done from inside chroot is reinstall boot loader on both disk drives.
Debian system use GRUB boot loader by default. To reinstall boot loader we use
grub=install command as shown below :
root@debian01:/#0grub=install0/dev/sda
Installation0finished.0No0error0reported.
root@debian01:/#0grub=install0/dev/sdb
Installation0finished.0No0error0reported.
root@debian01:/#0exit

16. We can exit chroot environment and shutdown the system :


root@debian01:/#0
exit
root@debian01:~#0reboot
root@debian01:~#0shutdown0=h0now
Broadcast0message0from0root@debian70(pts/3)0(Tue0Sep024001:04:0302013):
The0system0is0going0down0for0system0halt0NOW!
root@debian01:~#0000

17. Then we will boot the server using the second disk ( /dev/sdb ). If all the setup above
success, then system can boot using /dev/sdb ( rootmirror ) disk.

Attach Root Disk To RAID1 Group


After reboot system should already use the virtual partition. As we can see from df command
output below :
root@debian01:~#0df0=h
Filesystem000000Size00Used0Avail0Use%0Mounted0on
rootfs00000000009.2G00637M008.1G0008%0/
udev000000000000010M00000000010M0000%0/dev
tmpfs00000000000101M00276K00101M0001%0/run
/dev/md1000000009.2G00637M008.1G0008%0/
tmpfs000000000005.0M000000005.0M0000%0/run/lock
tmpfs00000000000584M00000000584M0000%0/run/shm
/dev/md000000000091M00022M00065M0026%0/boot
/dev/md3000000008.6G00148M008.1G0002%0/home

root@debian01:~#

We can check the RAID1 information for each virtual partition using the following command :
mdadm0=D0/dev/md<ID>

At this stage RAID1 Group only have single component which is rootmirror disk we prepared
on previous section. Since we define the RAID1 group to have 2 component, then mdadm0=D
command will report the degraded state of every virtual partition.
root@debian01:~#0mdadm0=D0/dev/md0
/dev/md0:
00000000Version0:01.2
00Creation0Time0:0Tue0Sep024000:54:3102013
00000Raid0Level0:0raid1
00000Array0Size0:0961280(93.890MiB098.440MB)
00Used0Dev0Size0:0961280(93.890MiB098.440MB)
000Raid0Devices0:02
00Total0Devices0:01
0000Persistence0:0Superblock0is0persistent
0000Update0Time0:0Tue0Sep024001:04:3302013
0000000000State0:0clean,0degraded0
0Active0Devices0:01
Working0Devices0:01
0Failed0Devices0:00
00Spare0Devices0:00
00000000000Name0:0debian01:000(local0to0host0debian01)
00000000000UUID0:05d7d8672:c019a7d0:69310f29:3cd65d04
000000000Events0:034
0000Number000Major000Minor000RaidDevice0State
0000000000000000000000000000000000000000removed
0000000100000008000000017000000001000000active0sync000/dev/sdb1
root@debian01:~#
root@debian01:~#0mdadm0=D0/dev/md1
/dev/md1:
00000000Version0:01.2
00Creation0Time0:0Tue0Sep024000:54:3902013
00000Raid0Level0:0raid1
00000Array0Size0:097575680(9.310GiB09.990GB)
00Used0Dev0Size0:097575680(9.310GiB09.990GB)
000Raid0Devices0:02
00Total0Devices0:01
0000Persistence0:0Superblock0is0persistent
0000Update0Time0:0Tue0Sep024001:05:0102013
0000000000State0:0clean,0degraded0
0Active0Devices0:01
Working0Devices0:01
0Failed0Devices0:00
00Spare0Devices0:00
00000000000Name0:0debian01:100(local0to0host0debian01)
00000000000UUID0:067631129:b7766c7e:d1200d55:036ad1c6
000000000Events0:0118
0000Number000Major000Minor000RaidDevice0State
0000000000000000000000000000000000000000removed

0000000100000008000000018000000001000000active0sync000/dev/sdb2
root@debian01:~#
root@debian01:~#0mdadm0=D0/dev/md2
/dev/md2:
00000000Version0:01.2
00Creation0Time0:0Tue0Sep024000:54:4702013
00000Raid0Level0:0raid1
00000Array0Size0:019516800(1906.260MiB01998.520MB)
00Used0Dev0Size0:019516800(1906.260MiB01998.520MB)
000Raid0Devices0:02
00Total0Devices0:01
0000Persistence0:0Superblock0is0persistent
0000Update0Time0:0Tue0Sep024000:55:1802013
0000000000State0:0clean,0degraded0
0Active0Devices0:01
Working0Devices0:01
0Failed0Devices0:00
00Spare0Devices0:00
00000000000Name0:0debian01:200(local0to0host0debian01)
00000000000UUID0:019cbe54c:2aa2126c:92eda6ee:ffc62fb9
000000000Events0:02
0000Number000Major000Minor000RaidDevice0State
0000000000000000000000000000000000000000removed
0000000100000008000000019000000001000000active0sync000/dev/sdb3
root@debian01:~#
root@debian01:~#0mdadm0=D0/dev/md3
/dev/md3:
00000000Version0:01.2
00Creation0Time0:0Tue0Sep024000:54:5502013
00000Raid0Level0:0raid1
00000Array0Size0:091462400(8.720GiB09.370GB)
00Used0Dev0Size0:091462400(8.720GiB09.370GB)
000Raid0Devices0:02
00Total0Devices0:01
0000Persistence0:0Superblock0is0persistent
0000Update0Time0:0Tue0Sep024001:04:3302013
0000000000State0:0clean,0degraded0
0Active0Devices0:01
Working0Devices0:01
0Failed0Devices0:00
00Spare0Devices0:00
00000000000Name0:0debian01:300(local0to0host0debian01)
00000000000UUID0:0d15793a1:348c6380:a94d73b3:a47f3bf7
000000000Events0:014
0000Number000Major000Minor000RaidDevice0State
0000000000000000000000000000000000000000removed
0000000100000008000000020000000001000000active0sync000/dev/sdb4
root@debian01:~#0
root@debian01:~#0cat0/proc/mdstat0
Personalities0:0[raid1]0
md30:0active0raid10sdb4[1]
00000091462400blocks0super01.20[2/1]0[_U]
md20:0active0(auto=read=only)0raid10sdb3[1]
00000019516800blocks0super01.20[2/1]0[_U]
md10:0active0raid10sdb2[1]
00000097575680blocks0super01.20[2/1]0[_U]

md00:0active0raid10sdb1[1]
000000961280blocks0super01.20[2/1]0[_U]
unused0devices:0<none>

root@debian01:~#0

This section will finish mirroring with attaching the previous rootdisk ( /dev/sda ) to the
RAID1 Group.
1. We need to set the partition type on rootdisk to Linux raid auto :
root@debian01:~#0fdisk0=l0/dev/sda
Disk0/dev/sda:021.50GB,0214748364800bytes
2550heads,0630sectors/track,026100cylinders,0total0419430400sectors
Units0=0sectors0of010*05120=05120bytes
Sector0size0(logical/physical):05120bytes0/05120bytes
I/O0size0(minimum/optimal):05120bytes0/05120bytes
Disk0identifier:00x0004f798
000Device0Boot000000Start000000000End000000Blocks000Id00System
/dev/sda1000*0000000020480000001945590000000962560008300Linux
/dev/sda200000000001945600000197263350000097658880008300Linux
/dev/sda300000000197263360000236318710000019527680008200Linux0swap0/0Solaris
/dev/sda400000000236318720000419409910000091545600008300Linux
root@debian01:~#0fdisk0/dev/sda
Command0(m0for0help):0t
Partition0number0(1=4):01
Hex0code0(type0L0to0list0codes):0fd
Changed0system0type0of0partition010to0fd0(Linux0raid0autodetect)
Command0(m0for0help):0t
Partition0number0(1=4):02
Hex0code0(type0L0to0list0codes):0fd
Changed0system0type0of0partition020to0fd0(Linux0raid0autodetect)
Command0(m0for0help):0t
Partition0number0(1=4):03
Hex0code0(type0L0to0list0codes):0fd
Changed0system0type0of0partition030to0fd0(Linux0raid0autodetect)
Command0(m0for0help):0t
Partition0number0(1=4):04
Hex0code0(type0L0to0list0codes):0fd
Changed0system0type0of0partition040to0fd0(Linux0raid0autodetect)
Command0(m0for0help):0w
The0partition0table0has0been0altered!
Calling0ioctl()0to0re=read0partition0table.
Syncing0disks.
root@debian01:~#

2. We can check that all partition inside /dev/sda ( rootdisk ) now has been converted to
Linux0raid0auto type.

root@debian01:~#0fdisk0=l0/dev/sda
Disk0/dev/sda:021.50GB,0214748364800bytes
2550heads,0630sectors/track,026100cylinders,0total0419430400sectors
Units0=0sectors0of010*05120=05120bytes
Sector0size0(logical/physical):05120bytes0/05120bytes
I/O0size0(minimum/optimal):05120bytes0/05120bytes
Disk0identifier:00x0004f798
000Device0Boot000000Start000000000End000000Blocks000Id00System
/dev/sda1000*000000002048000000194559000000096256000fd00Linux0raid0autodetect
/dev/sda20000000000194560000019726335000009765888000fd00Linux0raid0autodetect
/dev/sda30000000019726336000023631871000001952768000fd00Linux0raid0autodetect
/dev/sda40000000023631872000041940991000009154560000fd00Linux0raid0autodetect
root@debian01:~#0

3. Now we can put rootdisk to the existing RAID1 Group. Each partition under rootdisk
will be attached to existing virtual partition ( md device).
root@debian01:~#0mdadm0==add0/dev/md00/dev/sda1
mdadm:0added0/dev/sda1
root@debian01:~#0mdadm0==add0/dev/md10/dev/sda2
mdadm:0added0/dev/sda2
root@debian01:~#0mdadm0==add0/dev/md20/dev/sda3
mdadm:0added0/dev/sda3
root@debian01:~#0mdadm0==add0/dev/md30/dev/sda4
mdadm:0added0/dev/sda4
root@debian01:~#

4. After all partition of rootdisk join the RAID1 group, system will start
recovery/resynchronization automatically. We can monitor the recovery process by looking
at /proc/mdstat file :
root@debian01:~#0cat0/proc/mdstat0
Personalities0:0[raid1]0
md30:0active0raid10sda4[2]0sdb4[1]
00000091462400blocks0super01.20[2/1]0[_U]
00000000resync=DELAYED
md20:0active0raid10sda3[2]0sdb3[1]
00000019516800blocks0super01.20[2/1]0[_U]
00000000resync=DELAYED
md10:0active0raid10sda2[2]0sdb2[1]
00000097575680blocks0super01.20[2/1]0[_U]
000000[==>..................]00recovery0=011.6%0(1132800/9757568)0finish=1.1min0
speed=125866K/sec
md00:0active0raid10sda1[2]0sdb1[1]
000000961280blocks0super01.20[2/2]0[UU]
unused0devices:0<none>
root@debian01:~#

Or we can use mdadm0=D command as shown in the following example :


root@debian01:~#0mdadm0=D0/dev/md0
/dev/md0:

00000000Version0:01.2
00Creation0Time0:0Tue0Sep024000:54:3102013
00000Raid0Level0:0raid1
00000Array0Size0:0961280(93.890MiB098.440MB)
00Used0Dev0Size0:0961280(93.890MiB098.440MB)
000Raid0Devices0:02
00Total0Devices0:02
0000Persistence0:0Superblock0is0persistent
0000Update0Time0:0Tue0Sep024001:06:3002013
0000000000State0:0clean0
0Active0Devices0:02
Working0Devices0:02
0Failed0Devices0:00
00Spare0Devices0:00
00000000000Name0:0debian01:000(local0to0host0debian01)
00000000000UUID0:05d7d8672:c019a7d0:69310f29:3cd65d04
000000000Events0:055
0000Number000Major000Minor000RaidDevice0State
0000000200000008000000001000000000000000active0sync000/dev/sda1
0000000100000008000000017000000001000000active0sync000/dev/sdb1
root@debian01:~#0mdadm0=D0/dev/md1
/dev/md1:
00000000Version0:01.2
00Creation0Time0:0Tue0Sep024000:54:3902013
00000Raid0Level0:0raid1
00000Array0Size0:097575680(9.310GiB09.990GB)
00Used0Dev0Size0:097575680(9.310GiB09.990GB)
000Raid0Devices0:02
00Total0Devices0:02
0000Persistence0:0Superblock0is0persistent
0000Update0Time0:0Tue0Sep024001:06:4202013
0000000000State0:0clean,0degraded,0recovering0
0Active0Devices0:01
Working0Devices0:02
0Failed0Devices0:00
00Spare0Devices0:01
0Rebuild0Status0:013%0complete
00000000000Name0:0debian01:100(local0to0host0debian01)
00000000000UUID0:067631129:b7766c7e:d1200d55:036ad1c6
000000000Events0:0138
0000Number000Major000Minor000RaidDevice0State
0000000200000008000000002000000000000000spare0rebuilding000/dev/sda2
0000000100000008000000018000000001000000active0sync000/dev/sdb2
root@debian01:~#0mdadm0=D0/dev/md2
/dev/md2:
00000000Version0:01.2
00Creation0Time0:0Tue0Sep024000:54:4702013
00000Raid0Level0:0raid1
00000Array0Size0:019516800(1906.260MiB01998.520MB)
00Used0Dev0Size0:019516800(1906.260MiB01998.520MB)
000Raid0Devices0:02
00Total0Devices0:02
0000Persistence0:0Superblock0is0persistent
0000Update0Time0:0Tue0Sep024001:06:2902013
0000000000State0:0clean,0degraded,0resyncing0(DELAYED)0
0Active0Devices0:01

Working0Devices0:02
0Failed0Devices0:00
00Spare0Devices0:01
00000000000Name0:0debian01:200(local0to0host0debian01)
00000000000UUID0:019cbe54c:2aa2126c:92eda6ee:ffc62fb9
000000000Events0:04
0000Number000Major000Minor000RaidDevice0State
0000000200000008000000003000000000000000spare0rebuilding000/dev/sda3
0000000100000008000000019000000001000000active0sync000/dev/sdb3
root@debian01:~#0mdadm0=D0/dev/md3
/dev/md3:
00000000Version0:01.2
00Creation0Time0:0Tue0Sep024000:54:5502013
00000Raid0Level0:0raid1
00000Array0Size0:091462400(8.720GiB09.370GB)
00Used0Dev0Size0:091462400(8.720GiB09.370GB)
000Raid0Devices0:02
00Total0Devices0:02
0000Persistence0:0Superblock0is0persistent
0000Update0Time0:0Tue0Sep024001:06:3202013
0000000000State0:0clean,0degraded,0resyncing0(DELAYED)0
0Active0Devices0:01
Working0Devices0:02
0Failed0Devices0:00
00Spare0Devices0:01
00000000000Name0:0debian01:300(local0to0host0debian01)
00000000000UUID0:0d15793a1:348c6380:a94d73b3:a47f3bf7
000000000Events0:018
0000Number000Major000Minor000RaidDevice0State
0000000200000008000000004000000000000000spare0rebuilding000/dev/sda4
0000000100000008000000020000000001000000active0sync000/dev/sdb4
root@debian01:~#0

5. When recovery/resync process completed, both disks will be in sync state. No more
degraded status in the mdadm0=D output :
root@debian01:~#0mdadm0=D0/dev/md0
/dev/md0:
00000000Version0:01.2
00Creation0Time0:0Tue0Sep024000:54:3102013
00000Raid0Level0:0raid1
00000Array0Size0:0961280(93.890MiB098.440MB)
00Used0Dev0Size0:0961280(93.890MiB098.440MB)
000Raid0Devices0:02
00Total0Devices0:02
0000Persistence0:0Superblock0is0persistent
0000Update0Time0:0Tue0Sep024001:06:4302013
0000000000State0:0clean0
0Active0Devices0:02
Working0Devices0:02
0Failed0Devices0:00
00Spare0Devices0:00
00000000000Name0:0debian01:000(local0to0host0debian01)
00000000000UUID0:05d7d8672:c019a7d0:69310f29:3cd65d04
000000000Events0:055

0000Number000Major000Minor000RaidDevice0State
0000000200000008000000001000000000000000active0sync000/dev/sda1
0000000100000008000000017000000001000000active0sync000/dev/sdb1
root@debian01:~#0mdadm0=D0/dev/md1
/dev/md1:
00000000Version0:01.2
00Creation0Time0:0Tue0Sep024000:54:3902013
00000Raid0Level0:0raid1
00000Array0Size0:097575680(9.310GiB09.990GB)
00Used0Dev0Size0:097575680(9.310GiB09.990GB)
000Raid0Devices0:02
00Total0Devices0:02
0000Persistence0:0Superblock0is0persistent
0000Update0Time0:0Tue0Sep024001:09:2902013
0000000000State0:0clean0
0Active0Devices0:02
Working0Devices0:02
0Failed0Devices0:00
00Spare0Devices0:00
00000000000Name0:0debian01:100(local0to0host0debian01)
00000000000UUID0:067631129:b7766c7e:d1200d55:036ad1c6
000000000Events0:0157
0000Number000Major000Minor000RaidDevice0State
0000000200000008000000002000000000000000active0sync000/dev/sda2
0000000100000008000000018000000001000000active0sync000/dev/sdb2
root@debian01:~#0mdadm0=D0/dev/md2
/dev/md2:
00000000Version0:01.2
00Creation0Time0:0Tue0Sep024000:54:4702013
00000Raid0Level0:0raid1
00000Array0Size0:019516800(1906.260MiB01998.520MB)
00Used0Dev0Size0:019516800(1906.260MiB01998.520MB)
000Raid0Devices0:02
00Total0Devices0:02
0000Persistence0:0Superblock0is0persistent
0000Update0Time0:0Tue0Sep024001:08:5902013
0000000000State0:0clean0
0Active0Devices0:02
Working0Devices0:02
0Failed0Devices0:00
00Spare0Devices0:00
00000000000Name0:0debian01:200(local0to0host0debian01)
00000000000UUID0:019cbe54c:2aa2126c:92eda6ee:ffc62fb9
000000000Events0:023
0000Number000Major000Minor000RaidDevice0State
0000000200000008000000003000000000000000active0sync000/dev/sda3
0000000100000008000000019000000001000000active0sync000/dev/sdb3
root@debian01:~#0mdadm0=D0/dev/md3
/dev/md3:
00000000Version0:01.2
00Creation0Time0:0Tue0Sep024000:54:5502013
00000Raid0Level0:0raid1
00000Array0Size0:091462400(8.720GiB09.370GB)
00Used0Dev0Size0:091462400(8.720GiB09.370GB)
000Raid0Devices0:02
00Total0Devices0:02
0000Persistence0:0Superblock0is0persistent

0000Update0Time0:0Tue0Sep024001:08:4902013
0000000000State0:0clean0
0Active0Devices0:02
Working0Devices0:02
0Failed0Devices0:00
00Spare0Devices0:00
00000000000Name0:0debian01:300(local0to0host0debian01)
00000000000UUID0:0d15793a1:348c6380:a94d73b3:a47f3bf7
000000000Events0:037
0000Number000Major000Minor000RaidDevice0State
0000000200000008000000004000000000000000active0sync000/dev/sda4
0000000100000008000000020000000001000000active0sync000/dev/sdb4
root@debian01:~#0

6. Now both /dev/sda & /dev/sdb successfully joined as mirror disks. Both disks will hold
the same files. We can verify it by rebooting the server using each disk.

You might also like