1.分区:
1.1.创建分区:
[root@localhost~]# fdisk /dev/sdc
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): 3
First cylinder (5-2610, default 5):
Using default value 5
Last cylinder, +cylinders or +size{K,M,G}(5-2610, default 2610): +30M
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
1.2.查看分区情况:
[root@localhost~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x000abc53
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinderboundary.
/dev/sda2 64 2611 20458496 8e Linux LVM
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x5449b42b
Device Boot Start End Blocks Id System
/dev/sdb1 1 7 56196 83 Linux
/dev/sdb2 8 11 32130 83 Linux
Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0xe8f6c09c
Device Boot Start End Blocks Id System
/dev/sdc1 1 4 32098+ 83 Linux
/dev/sdc3 5 9 40162+ 83 Linux
Disk /dev/mapper/VolGroup-lv_root: 18.7 GB,18698207232 bytes
255 heads, 63 sectors/track, 2273 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x00000000
Disk /dev/mapper/VolGroup-lv_swap: 2248 MB,2248146944 bytes
255 heads, 63 sectors/track, 273 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x00000000
2.创建卷
2.1.创建物理卷:
[root@localhost ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
[root@localhost ~]# pvcreate /dev/sdb2
Physical volume "/dev/sdb2" successfully created
[root@localhost ~]# pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created
[root@localhost ~]# pvcreate /dev/sdc3
Physical volume "/dev/sdc3" successfully created
2.2.创建卷组:
[root@localhost~]# vgcreate vg0 /dev/sdb1 /dev/sdc1
Volume group "vg0" successfullycreated
2.3.创建逻辑卷镜像:
[root@localhost~]# lvcreate -L 20M -m1 -n mirror /dev/vg0
Logical volume "mirror" created
3.对逻辑卷的处理
3.1.格式化硬盘:
[root@localhost~]# mkfs.ext4 /dev/vg0/mirror
3.2.创建挂载点:
[root@localhost~]# mkdir /mirror
3.3. 挂载硬盘:
root@localhost~]# mount /dev/vg0/mirror /mirror
[root@localhost~]# cd /mirror
[root@localhostmirror]# ls
lost+found
4.查看日志:
Aug 1504:27:47 localhost kernel: device-mapper: dm-log-userspace: version 1.1.0loaded
Aug 1504:28:13 localhost lvm[1002]: Monitoring mirror device vg0-mirror for events.
Aug 1504:28:13 localhost lvm[1002]: vg0-mirror is now in-sync.
5.破坏逻辑卷镜像
5.1. 查看正常的逻辑卷情况:
[root@localhost mirror]# lvs -a -o devices
Devices
/dev/sda2(0)
/dev/sda2(4458)
mirror_mimage_0(0),mirror_mimage_1(0)
/dev/sdb1(0)
/dev/sdc1(0)
/dev/sdc1(5)
5.2. 破坏镜像lvm,删除/dev/sdc1
[root@localhostmirror]# dd if=/dev/zero of=/dev/sdc1 count=10
10+0records in
10+0records out
5120bytes (5.1 kB) copied, 0.00544565 s, 940 kB/s
5.3. 查看破坏后的逻辑卷情况:
[root@localhostmirror]# lvs -a -o devices
Couldn't find device with uuiddjiZ7N-IOMf-Ix9S-xFic-BgrD-FAm4-AZ8PBq.
Devices
/dev/sda2(0)
/dev/sda2(4458)
mirror_mimage_0(0),mirror_mimage_1(0)
/dev/sdb1(0)
unknown device(0)
unknown device(5)
5.4.逻辑卷仍然可以用:
[root@localhost mirror]# lvscan
Couldn't find device with uuid djiZ7N-IOMf-Ix9S-xFic-BgrD-FAm4-AZ8PBq.
ACTIVE '/dev/vg0/mirror' [20.00 MiB] inherit
ACTIVE '/dev/VolGroup/lv_root' [17.41 GiB] inherit
ACTIVE '/dev/VolGroup/lv_swap' [2.09 GiB] inherit
5.5.逻辑卷镜像的恢复:
5.5.1. 在vg0新加一个pv,对数据进行恢复:
[root@localhostmirror]# vgextend vg0 /dev/sdc3
Volume group "vg0" successfullyextended
5.5.2. 用/dev/sdc3替换坏掉的/dev/sdc1
[root@localhostmirror]# lvconvert -m1 /dev/vg0/mirror /dev/sdc3 /dev/sdb1
vg0/mirror: Converted: 20.0%
vg0/mirror: Converted: 100.0%
/dev/sdc1 已经被/dev/sdc3 取代了
[root@localhostmirror]# lvs -a -o devices
Devices
/dev/sda2(0)
/dev/sda2(4458)
mirror_mimage_0(0),mirror_mimage_1(0)
/dev/sdb1(0)
/dev/sdc3(0)
/dev/sdc3(5)
查看镜像状态:已经恢复
[root@localhostmirror]# lvdisplay /dev/vg0/mirror
--- Logical volume ---
LV Path /dev/vg0/mirror
LV Name mirror
VG Name vg0
LV UUID CRAaF2-cPVL-5pja-6ceW-QWCp-aRiJ-WgMhx2
LV Write Access read/write
LV Creation host, time localhost.localdomain,2014-08-15 04:28:12 +0800
LV Status available
# open 1
LV Size 20.00 MiB
Current LE 5
Mirrored volumes 2
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:5