We'll look at how to go from a single drive to raid 1, may be usfull to have mirroring if something goes wrong when patching or to have redundancy
I used vmware player to achieve the mirroring mirroring
root@localhost ~]# echo "- - -"
> /sys/class/scsi_host/host0/scan
[root@localhost ~]# echo "- - -"
> /sys/class/scsi_host/host1/scan
[root@localhost ~]# echo "- - -"
> /sys/class/scsi_host/host2/scan
- Check the new drives have been added by the kernel
dmesg
d 2:0:1:0: [sdb] 67108864 512-byte
logical blocks: (34.3 GB/32.0 GiB)
sd 2:0:1:0: [sdb] Write Protect is off
sd 2:0:1:0: [sdb] Mode Sense: 61 00 00
00
sd 2:0:1:0: [sdb] Cache data
unavailable
sd 2:0:1:0: [sdb] Assuming drive cache:
write through
sd 2:0:1:0: [sdb] Cache data
unavailable
sd 2:0:1:0: [sdb] Assuming drive cache:
write through
sdb: unknown partition table
sd 2:0:1:0: [sdb] Cache data
unavailable
sd 2:0:1:0: [sdb] Assuming drive cache:
write through
sd 2:0:1:0: [sdb] Attached SCSI disk
sd 2:0:1:0: Attached scsi generic sg2
type 0
scsi 2:0:2:0: Direct-Access VMware,
VMware Virtual S 1.0 PQ: 0 ANSI: 2
scsi target2:0:2: Beginning Domain
Validation
scsi target2:0:2: Domain Validation
skipping write tests
scsi target2:0:2: Ending Domain
Validation
scsi target2:0:2: FAST-40 WIDE SCSI
80.0 MB/s ST (25 ns, offset 127)
sd 2:0:2:0: [sdc] 67108864 512-byte
logical blocks: (34.3 GB/32.0 GiB)
sd 2:0:2:0: [sdc] Write Protect is off
sd 2:0:2:0: [sdc] Mode Sense: 61 00 00
00
sd 2:0:2:0: [sdc] Cache data
unavailable
sd 2:0:2:0: [sdc] Assuming drive cache:
write through
sd 2:0:2:0: [sdc] Cache data
unavailable
sd 2:0:2:0: [sdc] Assuming drive cache:
write through
sdc: unknown partition table
sd 2:0:2:0: [sdc] Cache data
unavailable
sd 2:0:2:0: [sdc] Assuming drive cache:
write through
- create a raid partition on the 2 new drives
fdisk /dev/sdb
Device contains neither a valid DOS
partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk
identifier 0x6eb9d2e3.
Changes will remain in memory only,
until you decide to write them.
After that, of course, the previous
content won't be recoverable.
Warning: invalid flag 0x0000 of
partition table 4 will be corrected by w(rite)
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-4177, default 1):
Using default value 1
Last cylinder, +cylinders or
+size{K,M,G} (1-4177, default 4177):
Using default value 4177
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): L
0 Empty 24 NEC DOS
81 Minix / old Lin bf Solaris
1 FAT12 39 Plan 9
82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 3c PartitionMagic
83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 40 Venix 80286
84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 41 PPC PReP
Boot 85 Linux extended c7 Syrinx
5 Extended 42 SFS
86 NTFS volume set da Non-FS data
6 FAT16 4d QNX4.x
87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS 4e QNX4.x 2nd part
88 Linux plaintext de Dell Utility
8 AIX 4f QNX4.x 3rd part
8e Linux LVM df BootIt
9 AIX bootable 50 OnTrack DM
93 Amoeba e1 DOS access
a OS/2 Boot Manag 51 OnTrack DM6 Aux
94 Amoeba BBT e3 DOS R/O
b W95 FAT32 52 CP/M
9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 53 OnTrack DM6 Aux
a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 54 OnTrackDM6
a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 55 EZ-Drive
a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 56 Golden Bow
a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 5c Priam Edisk
a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 61 SpeedStor
a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 63 GNU HURD or
Sys ab Darwin boot f2 DOS secondary
16 Hidden FAT16 64 Novell Netware
af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 65 Novell Netware
b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 70 DiskSecure Mult
b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 75 PC/IX
bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 80 Old Minix
be Solaris boot ff BBT
1e Hidden W95 FAT1
Hex code (type L to list codes): 83
Changed system type of partition 1 to
fd (Linux raid autodetect)
Command (m for help): w
The partition table has been altered!
Note: la partitions flags have to be 83
and they need to be set to bootable
- Create the array for /boot
[root@localhost ~]# mdadm --create
--metadata=0.90 --level=1 /dev/md0 --raid-devices=2 /dev/sdb1
/dev/sdc1
mdadm: array /dev/md0 started.
4.5) Create the array for the volume
group:
mdadm --create --metadata=0.90
--level=1 /dev/md1 --raid-devices=2 /dev/sdd1 /dev/sde1
- Check the array status (As you can see it it sync'ing now)
cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdc1[1] sdb1[0]
33551616 blocks [2/2] [UU]
[=======>.............]
resync = 35.7% (12000128/33551616) finish=1.7min speed=206252K/sec
6)Create the volume group on the
array md1
fdisk /dev/md1
Partition number (1-4): 1
First cylinder (131074-8387904, default
131074):
Using default value 131074
Last cylinder, +cylinders or
+size{K,M,G} (131074-8387904, default 8387904):
Using default value 8387904
Hex code (type L to list codes): 8e
Changed system type of partition 2 to
8e (Linux LVM)
Command (m for help): p
Disk /dev/md0: 34.4 GB, 34356854784
bytes
2 heads, 4 sectors/track, 8387904
cylinders
Units = cylinders of 8 * 512 = 4096
bytes
Sector size (logical/physical): 512
bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes /
512 bytes
Disk identifier: 0x57153f95
Device Boot Start End
Blocks Id System
/dev/md1p1 1 8387904
33027324 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition
table.
Syncing disks.
- Create the /boot on the new array
mkfs -t ext3 -L '/boot' dev/md0
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
32768 inodes, 131072 blocks
6553 blocks (5.00%) reserved for the
super user
First data block=0
Maximum filesystem blocks=134217728
4 block groups
32768 blocks per group, 32768 fragments
per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem
accounting information: done
This filesystem will be automatically
checked every 20 mounts or
180 days, whichever comes first. Use
tune2fs -c or -i to override.
- Create the targte volume group (root_vg) on the array
[root@localhost ~]# vgcreate
root_vg_md0 /dev/md1p1
No physical volume label read from
/dev/md1p1
Physical volume "/dev/md1p1"
successfully created
Volume group "root_vg_md0"
successfully created
- Create the target logical volumes (same size using logical extents as original)
lvcreate -l 2049 -n rootvol
root_vg_md0
lvcreate -l 2431 -n usrvol
root_vg_md0
lvcreate -l 512 -n swapvol
root_vg_md0
lvcreate -l 1023 -n homevol
root_vg_md0
- Create the fs
mkfs -t ext4
/dev/root_vg_md0/rootvol
mkfs -t ext4 /dev/root_vg_md0/usrvol
mkfs -t ext4
/dev/root_vg_md0/varvol
mkfs -t ext4
/dev/root_vg_md0/varvol
mkfs -t ext4
/dev/root_vg_md0/homevol
- Create the mount points
mkdir -p /migration/boot &&
mkdir /migration/root && mkdir /migration/usr &&
mkdir /migration/var && mkdir /migration/home
- mount the new fs
[root@localhost ~]# mount /dev/md0p1
/migration/boot
[root@localhost ~]# mount
/dev/root_vg_md0/rootvol /migration/root
[root@localhost ~]# mount
/dev/root_vg_md0/usrvol /migration/usr
[root@localhost ~]# mount
/dev/root_vg_md0/varvol /migration/var
[root@localhost ~]# mount
/dev/root_vg_md0/homevol /migration/home
- We need to create snapshots, these require space so we need to expand the original rootvg in case we do not have free physical extents to use
[root@localhost ~]# mount /dev/md0
/migration/boot
[root@localhost ~]# mount
/dev/root_vg_md0/rootvol /migration/root
[root@localhost ~]# mount
/dev/root_vg_md0/usrvol /migration/usr
[root@localhost ~]# mount
/dev/root_vg_md0/varvol /migration/var
[root@localhost ~]# mount
/dev/root_vg_md0/homevol /migration/home
[root@localhost ~]# vgextend vg_livedvd
/dev/sdd1
No physical volume label read from
/dev/sdd1
Physical volume "/dev/sdd1"
successfully created
Volume group "vg_livedvd"
successfully extended
- Create the snapshots
lvcreate -s
/dev/mapper/vg_livedvd-LogVol00 -n root_snap -L 512M
lvcreate -s
/dev/mapper/vg_livedvd-LogVol04 -n home_snap -L 512M
lvcreate -s
/dev/mapper/vg_livedvd-LogVol01 -n usr_snap -L 512M
lvcreate -s
/dev/mapper/vg_livedvd-LogVol03 -n var_snap -L 512M
- Mount the snaphots
[root@localhost ~]# mount
/dev/mapper/vg_livedvd-root_snap /snap/root
[root@localhost ~]# mount
/dev/mapper/vg_livedvd-usr_snap /snap/usr
[root@localhost ~]# mount
/dev/mapper/vg_livedvd-var_snap /snap/var
[root@localhost ~]# mount
/dev/mapper/vg_livedvd-home_snap /snap/home
- As you can see new target volumes and snapshots are mounted
df -kh
Filesystem Size Used Avail
Use% Mounted on
/dev/mapper/vg_livedvd-LogVol00
7.9G 343M 7.5G
5% /
tmpfs 504M 232K 504M
1% /dev/shm
/dev/sda1 504M 38M 441M
8% /boot
/dev/mapper/vg_livedvd-LogVol04
4.0G 120M 3.7G
4% /home
/dev/mapper/vg_livedvd-LogVol01
7.9G 4.3G 3.2G
58% /usr
/dev/mapper/vg_livedvd-LogVol03
9.4G 309M 8.6G
4% /var
/dev/sr0 1.7G 1.7G 0
100% /media/CentOS-6.4-i386-LiveDVD
/dev/md0p1 504M 17M 462M
4% /migration/boot
/dev/mapper/root_vg_md0-rootvol
7.9G 147M 7.4G
2% /migration/root
/dev/mapper/root_vg_md0-usrvol
7.9G 147M 7.4G
2% /migration/usr
/dev/mapper/root_vg_md0-varvol
9.4G 150M 8.8G
2% /migration/var
/dev/mapper/root_vg_md0-homevol
4.0G 72M 3.7G
2% /migration/home
/dev/mapper/vg_livedvd-root_snap
7.9G 330M 7.5G
5% /snap/root
/dev/mapper/vg_livedvd-usr_snap
7.9G 4.2G 3.3G
57% /snap/usr
/dev/mapper/vg_livedvd-var_snap
9.4G 309M 8.6G
4% /snap/var
/dev/mapper/vg_livedvd-home_snap
4.0G 120M 3.7G
4% /snap/home
From the snaps copy the data to the new
volumes
cd /snap/usr
tar cvpf - ./* | (cd /migration/usr/;
tar xvpf -)
cd /snap/var
tar cvpf - ./* | (cd
/migration/var/; tar xvpf -)
cd /snap/home
tar cvpf - ./* | (cd
/migration/home/; tar xvpf -)
cd /boot
tar cvpf - ./* | (cd
/migration/boot/; tar xvpf -)
cd /snap/root
tar cvpf - ./* | (cd /migration/root/;
tar xvpf -)
- edit the device.map
cat /boot/grub/device.map
# this device map was generated by
anaconda
(hd0) /dev/sda
(hd1) /dev/sdb
(hd2) /dev/sdc
(hd3) /dev/sdd
18) Install the bootloader on the array
members
[root@localhost ~]# grub-install
/dev/sdbInstallation finished. No error reported.
This is the contents of the device map
/boot/grub/device.map.
Check if this is correct or not. If any
of the lines is incorrect,
fix it and re-run the script
`grub-install'.
# this device map was generated by
anaconda
(hd0) /dev/sda
(hd1) /dev/sdb
(hd2) /dev/sdc
(hd3) /dev/sdd
[root@localhost ~]# grub-install
/dev/sdc
- Regenerate the initramfs (don-t forget to backup your original initramfs)
mdadm --detail --scan
ARRAY /dev/md/0_0 metadata=0.90
UUID=0058c09f:33ada452:bfe78010:bc810f04
[root@localhost ~]# mdadm --detail
--scan > /etc/mdadm.conf
[root@localhost ~]# dracut --mdadmconf
--force /boot/initramfs-2.6.32-358.el6.i686.img
[root@localhost ~]# cd /boot
- update the new boot partition
[root@localhost boot]# tar cvpf - ./* |
(cd /migration/boot/; tar xvpf -)
- blkid | grep /dev/md (we need to update the new vg)
/dev/md0: LABEL="/boot"
UUID="e1f2317f-edb0-42ef-82a5-bff4364d3f9e" TYPE="ext4"
/dev/md127p2:
UUID="pn3qA5-Ggo4-g4VC-jttj-VhU5-Qyr3-Yx750q"
TYPE="LVM2_member"
- update the new fstab on /migration/root/etc/fstab with the new boot uuid
- we now set up the grub
grub
grub> root(hd3,0)
grub> setup (hd3,0)
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 (hd3,0)
root (hd3,0)
Filesystem type is ext2fs, partition
type 0x83
grub> setup (hd3,0)
setup (hd3,0)
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 (hd3,0)"... failed (this is not fatal)
Running "embed
/grub/e2fs_stage1_5 (hd3,0)"... failed (this is not fatal)
Running "install /grub/stage1
(hd3,0) /grub/stage2 p /grub/grub.conf "... succeeded
Done.
21) Reboot machine