지난번에는 빈 디스크 두개를 LVM 미러 걸어 마운트해서 사용하는것을 해보았다.(http://blog.boxcorea.com/wp/archives/448). 이번에는 현재 사용하는 리눅스OS를 lvm으로 미러링하는 것으로 전체적인 과정은 지난번과 동일하다. 다만, 이렇게 하기 위해서는 현재 설치되어 있는 리눅스의 파티션이 8e(Linux LVM)타입으로 설정되어 있어야 한다. 아울러, 아래 과정은 kvm guest상에서 실행한 것이기에 실제 머신에서 잘 되는지 확인은 안된 상태다.
1. 디스크 준비.(현재 os는 /dev/sda, 미러할 디스크는 /dev/sdb이다).
root@ubuntu:~# fdisk -l
Disk /dev/sda: 12.9 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders, total 25165824 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000e1d91Device Boot Start End Blocks Id System
/dev/sda1 * 2048 25163775 12580864 8e Linux LVMDisk /dev/sdb: 12.9 GB, 12884901888 bytes
128 heads, 33 sectors/track, 5957 cylinders, total 25165824 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x5a1456d3Device Boot Start End Blocks Id System
/dev/sdb1 2048 25165823 12581888 8e Linux LVMDisk /dev/mapper/vg00-lvol1: 197 MB, 197132288 bytes
255 heads, 63 sectors/track, 23 cylinders, total 385024 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000Disk /dev/mapper/vg00-lvol1 doesn’t contain a valid partition table
Disk /dev/mapper/vg00-lvol2: 12.0 GB, 11999903744 bytes
255 heads, 63 sectors/track, 1458 cylinders, total 23437312 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000Disk /dev/mapper/vg00-lvol2 doesn’t contain a valid partition table
Disk /dev/mapper/vg00-lvol3: 683 MB, 683671552 bytes
255 heads, 63 sectors/track, 83 cylinders, total 1335296 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000Disk /dev/mapper/vg00-lvol3 doesn’t contain a valid partition table
root@ubuntu:~# fdisk sdb
fdisk: unable to open sdb: No such file or directory
root@ubuntu:~# fdisk /dev/sdbCommand (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition’s system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)Command (m for help): p
Disk /dev/sdb: 12.9 GB, 12884901888 bytes
128 heads, 33 sectors/track, 5957 cylinders, total 25165824 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x5a1456d3Device Boot Start End Blocks Id System
/dev/sdb1 2048 25165823 12581888 8e Linux LVMCommand (m for help): q
root@ubuntu:~# fdisk /dev/sda
Command (m for help): p
Disk /dev/sda: 12.9 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders, total 25165824 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000e1d91Device Boot Start End Blocks Id System
/dev/sda1 * 2048 25163775 12580864 8e Linux LVMCommand (m for help): q
root@ubuntu:~# ls
root@ubuntu:~# fdisk -lDisk /dev/sda: 12.9 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders, total 25165824 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000e1d91Device Boot Start End Blocks Id System
/dev/sda1 * 2048 25163775 12580864 8e Linux LVMDisk /dev/sdb: 12.9 GB, 12884901888 bytes
128 heads, 33 sectors/track, 5957 cylinders, total 25165824 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x5a1456d3Device Boot Start End Blocks Id System
/dev/sdb1 2048 25165823 12581888 8e Linux LVMDisk /dev/mapper/vg00-lvol1: 197 MB, 197132288 bytes
255 heads, 63 sectors/track, 23 cylinders, total 385024 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000Disk /dev/mapper/vg00-lvol1 doesn’t contain a valid partition table
Disk /dev/mapper/vg00-lvol2: 12.0 GB, 11999903744 bytes
255 heads, 63 sectors/track, 1458 cylinders, total 23437312 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000Disk /dev/mapper/vg00-lvol2 doesn’t contain a valid partition table
Disk /dev/mapper/vg00-lvol3: 683 MB, 683671552 bytes
255 heads, 63 sectors/track, 83 cylinders, total 1335296 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000Disk /dev/mapper/vg00-lvol3 doesn’t contain a valid partition table
root@ubuntu:~# clearroot@ubuntu:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg00-lvol2 12G 1.3G 9.4G 12% /
udev 489M 4.0K 489M 1% /dev
tmpfs 200M 240K 199M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 498M 0 498M 0% /run/shm
/dev/mapper/vg00-lvol1 187M 34M 143M 20% /boot
root@ubuntu:~# lvs -a
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lvol1 vg00 -wi-ao 188.00m
lvol2 vg00 -wi-ao 11.18g
lvol3 vg00 -wi-ao 652.00m
root@ubuntu:~# pvdisplay
— Physical volume —
PV Name /dev/sda1
VG Name vg00
PV Size 12.00 GiB / not usable 2.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 3071
Free PE 0
Allocated PE 3071
PV UUID 1Pm39W-fy23-dv05-KIeR-iuLA-6D8Q-GbnSkW
2. 미러할 디스크(sdb1)의 pv를 생성.
root@ubuntu:~# pvcreate /dev/sdb1
Physical volume “/dev/sdb1” successfully created
root@ubuntu:~# pvs
PV VG Fmt Attr PSize PFree
/dev/sda1 vg00 lvm2 a- 12.00g 0
/dev/sdb1 lvm2 a- 12.00g 12.00g
root@ubuntu:~# vgs
VG #PV #LV #SN Attr VSize VFree
vg00 1 3 0 wz–n- 12.00g 0
root@ubuntu:~# lvs -a -o +devices
LV VG Attr LSize Origin Snap% Move Log Copy% Convert Devices
lvol1 vg00 -wi-ao 188.00m /dev/sda1(0)
lvol2 vg00 -wi-ao 11.18g /dev/sda1(47)
lvol3 vg00 -wi-ao 652.00m /dev/sda1(2908)
3. VG에 생성한 PV를 추가
root@ubuntu:~# vgextend vg00 /dev/sdb1
Volume group “vg00” successfully extended
root@ubuntu:~# pvs
PV VG Fmt Attr PSize PFree
/dev/sda1 vg00 lvm2 a- 12.00g 0
/dev/sdb1 vg00 lvm2 a- 12.00g 12.00g
root@ubuntu:~# lvconvert -m 1 vg00/lvol1
Insufficient suitable allocatable extents for logical volume : 47 more required
Unable to allocate extents for mirror(s).
root@ubuntu:~# lvconvert -m 1 -corelog vg00/lvol1
Invalid argument orelog
Error during parsing of command line.
4. 각 LV를 mirror해준다.
root@ubuntu:~# lvconvert -m 1 –corelog vg00/lvol2
vg00/lvol2: Converted: 0.0%vg00/lvol2: Converted: 2.0%
vg00/lvol2: Converted: 3.8%
vg00/lvol2: Converted: 5.6%
vg00/lvol2: Converted: 7.4%
vg00/lvol2: Converted: 9.8%
vg00/lvol2: Converted: 12.4%
vg00/lvol2: Converted: 15.1%
vg00/lvol2: Converted: 17.8%
vg00/lvol2: Converted: 19.8%
vg00/lvol2: Converted: 22.1%
vg00/lvol2: Converted: 24.7%
vg00/lvol2: Converted: 27.3%
vg00/lvol2: Converted: 29.8%
vg00/lvol2: Converted: 32.1%
vg00/lvol2: Converted: 34.6%
vg00/lvol2: Converted: 37.0%
vg00/lvol2: Converted: 39.1%
vg00/lvol2: Converted: 41.7%
vg00/lvol2: Converted: 44.4%
vg00/lvol2: Converted: 46.9%
vg00/lvol2: Converted: 49.4%
vg00/lvol2: Converted: 51.9%
vg00/lvol2: Converted: 54.4%
vg00/lvol2: Converted: 56.2%
vg00/lvol2: Converted: 58.0%
vg00/lvol2: Converted: 59.7%
vg00/lvol2: Converted: 61.7%
vg00/lvol2: Converted: 64.2%
vg00/lvol2: Converted: 66.9%
vg00/lvol2: Converted: 69.6%
vg00/lvol2: Converted: 72.0%
vg00/lvol2: Converted: 73.9%
vg00/lvol2: Converted: 76.0%
vg00/lvol2: Converted: 78.7%
vg00/lvol2: Converted: 81.3%
vg00/lvol2: Converted: 83.9%
vg00/lvol2: Converted: 86.5%
vg00/lvol2: Converted: 89.2%
vg00/lvol2: Converted: 91.8%
vg00/lvol2: Converted: 94.5%
vg00/lvol2: Converted: 97.1%
vg00/lvol2: Converted: 99.6%
vg00/lvol2: Converted: 100.0%
root@ubuntu:~#
root@ubuntu:~#
root@ubuntu:~# lvs -a -o +devices
LV VG Attr LSize Origin Snap% Move Log Copy% Convert Devices
lvol1 vg00 -wi-ao 188.00m /dev/sda1(0)
lvol2 vg00 mwi-ao 11.18g 100.00 lvol2_mimage_0(0),lvol2_mimage_1(0)
[lvol2_mimage_0] vg00 iwi-ao 11.18g /dev/sda1(47)
[lvol2_mimage_1] vg00 iwi-ao 11.18g /dev/sdb1(0)
lvol3 vg00 -wi-ao 652.00m /dev/sda1(2908)
root@ubuntu:~# pvs
PV VG Fmt Attr PSize PFree
/dev/sda1 vg00 lvm2 a- 12.00g 0
/dev/sdb1 vg00 lvm2 a- 12.00g 840.00m
root@ubuntu:~# lvconvert -m 1 –corelog vg00/lvol1
vg00/lvol1: Converted: 0.0%
vg00/lvol1: Converted: 100.0%
lvs 커맨드로 mirror 상태 확인
root@ubuntu:~# lvs -a
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lvol1 vg00 mwi-ao 188.00m 100.00
[lvol1_mimage_0] vg00 iwi-ao 188.00m
[lvol1_mimage_1] vg00 iwi-ao 188.00m
lvol2 vg00 mwi-ao 11.18g 100.00
[lvol2_mimage_0] vg00 iwi-ao 11.18g
[lvol2_mimage_1] vg00 iwi-ao 11.18g
lvol3 vg00 -wi-ao 652.00m
root@ubuntu:~# lvconvert -m 1 –corelog ve00/lvol3
Volume group “ve00” not found
root@ubuntu:~# lvconvert -m 1 –corelog vg00/lvol3
vg00/lvol3: Converted: 0.0%
vg00/lvol3: Converted: 41.7%
vg00/lvol3: Converted: 88.3%
vg00/lvol3: Converted: 100.0%root@ubuntu:~# lvs -a -o +devices
LV VG Attr LSize Origin Snap% Move Log Copy% Convert Devices
lvol1 vg00 mwi-ao 188.00m 100.00 lvol1_mimage_0(0),lvol1_mimage_1(0)
[lvol1_mimage_0] vg00 iwi-ao 188.00m /dev/sda1(0)
[lvol1_mimage_1] vg00 iwi-ao 188.00m /dev/sdb1(2861)
lvol2 vg00 mwi-ao 11.18g 100.00 lvol2_mimage_0(0),lvol2_mimage_1(0)
[lvol2_mimage_0] vg00 iwi-ao 11.18g /dev/sda1(47)
[lvol2_mimage_1] vg00 iwi-ao 11.18g /dev/sdb1(0)
lvol3 vg00 mwi-ao 652.00m 100.00 lvol3_mimage_0(0),lvol3_mimage_1(0)
[lvol3_mimage_0] vg00 iwi-ao 652.00m /dev/sda1(2908)
[lvol3_mimage_1] vg00 iwi-ao 652.00m /dev/sdb1(2908)
root@ubuntu:~# lvs -a
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lvol1 vg00 mwi-ao 188.00m 100.00
[lvol1_mimage_0] vg00 iwi-ao 188.00m
[lvol1_mimage_1] vg00 iwi-ao 188.00m
lvol2 vg00 mwi-ao 11.18g 100.00
[lvol2_mimage_0] vg00 iwi-ao 11.18g
[lvol2_mimage_1] vg00 iwi-ao 11.18g
lvol3 vg00 mwi-ao 652.00m 100.00
[lvol3_mimage_0] vg00 iwi-ao 652.00m
[lvol3_mimage_1] vg00 iwi-ao 652.00m
root@ubuntu:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg00-lvol2 12G 1.3G 9.4G 12% /
udev 489M 4.0K 489M 1% /dev
tmpfs 200M 264K 199M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 498M 0 498M 0% /run/shm
/dev/mapper/vg00-lvol1 187M 34M 143M 20% /boot
root@ubuntu:~# lvdisplay
— Logical volume —
LV Name /dev/vg00/lvol1
VG Name vg00
LV UUID bv7tGV-VrCz-fAtn-EY3w-tj0c-B4uf-LaPueD
LV Write Access read/write
LV Status available
# open 1
LV Size 188.00 MiB
Current LE 47
Mirrored volumes 2
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 252:0— Logical volume —
LV Name /dev/vg00/lvol2
VG Name vg00
LV UUID wZ3pom-nfrA-eC24-euIy-PfER-GgZt-gcoLaE
LV Write Access read/write
LV Status available
# open 1
LV Size 11.18 GiB
Current LE 2861
Mirrored volumes 2
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 252:1— Logical volume —
LV Name /dev/vg00/lvol3
VG Name vg00
LV UUID 3fWsJw-KQo6-7M0T-vRRy-q8MT-EB1x-kM8ay7
LV Write Access read/write
LV Status available
# open 2
LV Size 652.00 MiB
Current LE 163
Mirrored volumes 2
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 252:2root@ubuntu:~# vgdisplay
— Volume group —
VG Name vg00
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 18
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 2
Act PV 2
VG Size 23.99 GiB
PE Size 4.00 MiB
Total PE 6142
Alloc PE / Size 6142 / 23.99 GiB
Free PE / Size 0 / 0
VG UUID bSxwpC-RM77-1kTu-5Lyu-jmuM-36G4-yXgS3froot@ubuntu:~# vgdisplay -v | more
Finding all volume groups
Finding volume group “vg00”
— Volume group —
VG Name vg00
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 18
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 2
Act PV 2
VG Size 23.99 GiB
PE Size 4.00 MiB
Total PE 6142
Alloc PE / Size 6142 / 23.99 GiB
Free PE / Size 0 / 0
VG UUID bSxwpC-RM77-1kTu-5Lyu-jmuM-36G4-yXgS3f— Logical volume —
LV Name /dev/vg00/lvol1
VG Name vg00
LV UUID bv7tGV-VrCz-fAtn-EY3w-tj0c-B4uf-LaPueD
LV Write Access read/write
LV Status available
# open 1
LV Size 188.00 MiB
Current LE 47
Mirrored volumes 2
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 252:0— Logical volume —
LV Name /dev/vg00/lvol2
VG Name vg00
LV UUID wZ3pom-nfrA-eC24-euIy-PfER-GgZt-gcoLaE
LV Write Access read/write
LV Status available
# open 1
LV Size 11.18 GiB
Current LE 2861
Mirrored volumes 2
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 252:1— Logical volume —
LV Name /dev/vg00/lvol3
VG Name vg00
LV UUID 3fWsJw-KQo6-7M0T-vRRy-q8MT-EB1x-kM8ay7
LV Write Access read/write
LV Status available
# open 2
LV Size 652.00 MiB
Current LE 163
Mirrored volumes 2
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 252:2— Physical volumes —
PV Name /dev/sda1
PV UUID 1Pm39W-fy23-dv05-KIeR-iuLA-6D8Q-GbnSkW
PV Status allocatable
Total PE / Free PE 3071 / 0PV Name /dev/sdb1
PV UUID wvQynG-5RQe-5o13-9XJA-olYs-HpNu-t2NqBy
PV Status allocatable
Total PE / Free PE 3071 / 0root@ubuntu:~# lvdisplay -v
Finding all logical volumes
— Logical volume —
LV Name /dev/vg00/lvol1
VG Name vg00
LV UUID bv7tGV-VrCz-fAtn-EY3w-tj0c-B4uf-LaPueD
LV Write Access read/write
LV Status available
# open 1
LV Size 188.00 MiB
Current LE 47
Mirrored volumes 2
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 252:0— Logical volume —
LV Name /dev/vg00/lvol2
VG Name vg00
LV UUID wZ3pom-nfrA-eC24-euIy-PfER-GgZt-gcoLaE
LV Write Access read/write
LV Status available
# open 1
LV Size 11.18 GiB
Current LE 2861
Mirrored volumes 2
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 252:1— Logical volume —
LV Name /dev/vg00/lvol3
VG Name vg00
LV UUID 3fWsJw-KQo6-7M0T-vRRy-q8MT-EB1x-kM8ay7
LV Write Access read/write
LV Status available
# open 2
LV Size 652.00 MiB
Current LE 163
Mirrored volumes 2
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 252:2
5. mirror 삭제하기(mirror의 역순 진행).
5.1 각 lv를 vg에서 제거한다.
# lvs -a
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lvol1 vg00 mwi-ao 188.00m 100.00
[lvol1_mimage_0] vg00 iwi-ao 188.00m
[lvol1_mimage_1] vg00 iwi-ao 188.00m
lvol2 vg00 mwi-ao 11.18g 100.00
[lvol2_mimage_0] vg00 iwi-ao 11.18g
[lvol2_mimage_1] vg00 iwi-ao 11.18g
lvol3 vg00 mwi-ao 652.00m 100.00
[lvol3_mimage_0] vg00 iwi-ao 652.00m
[lvol3_mimage_1] vg00 iwi-ao 652.00m# lvconvert -m 0 vg00/lvol1
The link /dev/vg00/lvol1_mimage_0 should had been created by udev but it was not found. Falling back to direct link creation.
The link /dev/vg00/lvol1_mimage_0 should have been removed by udev but it is still present. Falling back to direct link removal.
Logical volume lvol1 converted.
# lvs -a
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lvol1 vg00 -wi-ao 188.00m
lvol2 vg00 mwi-ao 11.18g 100.00
[lvol2_mimage_0] vg00 iwi-ao 11.18g
[lvol2_mimage_1] vg00 iwi-ao 11.18g
lvol3 vg00 mwi-ao 652.00m 100.00
[lvol3_mimage_0] vg00 iwi-ao 652.00m
[lvol3_mimage_1] vg00 iwi-ao 652.00m
같은 방법으로 lvol2, lvol3의 미러를 해제한다.
5.2 vg에서 미러에 사용한 디스크 제거.
# vgreduce vg00 /dev/sdb1
Removed “/dev/sdb1” from volume group “vg00”
5.3 pv 삭제
# pvremove /dev/sdb1
Labels on physical volume “/dev/sdb1” successfully wiped
※ 원래 OS 설치된 디스크(sda)가 고장났다면, sdb로 부팅될 것인지의 문제. 테스트환경이 kvm 가상머신이라, sda고장환경을 만들지 못했다. hpux의 경우, mirror걸때 pvcreate 시 -B 옵션을 주는것으로 해결되지만, 리눅스에는 -B 옵션이 없다. 만약 부팅이 되지 않는다면, 아래 커맨드로, sdb가 부팅가능하도록 해 주면 될것 같다. 단, 시험은 해 보지 않았다.
# parted /dev/sdb set 1 boot on
# grub-install /dev/sdb
※ 문제점. 재부팅하고 lvs 커맨드로 보면 가장 큰 lv를 rebuild하고 있다. 실제 장애 발생시 문제가 있을 수도 있겠다. 디스크(sda) 장애상황을 가정하고 sdb로 부팅시도 했으나, 부팅이 되지 않는다. 현재 상황에서는 실 사용에 문제가 있음.