Linux:LVM扩容
在前面的文章里已经介绍过了Linux中LVM的创建与分区、挂载:http://d-prototype.com/archives/650
这里,本文呈现关于Linux中LVM扩容的相关技术细节。
首先,查看当前的系统状态:
1 2 3 4 5 6 7 8 9 |
[root@rhel5u10 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 18G 2.8G 14G 17% / /dev/sda1 289M 17M 258M 7% /boot tmpfs 500M 0 500M 0% /dev/shm /dev/sr0 4.1G 4.1G 0 100% /iso /dev/mapper/vg_oracle-lv_oracle 3.6G 2.9G 566M 84% /u01 [root@rhel5u10 ~]# |
可以看到,当前挂载的分区中,有一个逻辑卷。
关于逻辑卷的具体状态:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
[root@rhel5u10 ~]# lvdisplay --- Logical volume --- LV Name /dev/vg_oracle/lv_oracle VG Name vg_oracle LV UUID P7h2qI-eEz1-SIQ2-MfSe-zRcD-mEG9-rUW0mm LV Write Access read/write LV Status available # open 1 LV Size 3.63 GB Current LE 930 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [root@rhel5u10 ~]# [root@rhel5u10 ~]# vgdisplay --- Volume group --- VG Name vg_oracle System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 1 Act PV 1 VG Size 3.73 GB PE Size 4.00 MB Total PE 954 Alloc PE / Size 930 / 3.63 GB Free PE / Size 24 / 96.00 MB VG UUID 35JT2d-dZfQ-GINh-ILiA-yy2B-2STI-IjlOTW [root@rhel5u10 ~]# [root@rhel5u10 ~]# pvdisplay --- Physical volume --- PV Name /dev/sdb1 VG Name vg_oracle PV Size 3.73 GB / not usable 4.11 MB Allocatable yes PE Size (KByte) 4096 Total PE 954 Free PE 24 Allocated PE 930 PV UUID m8I6BK-nN1F-WYx1-GxEI-xSgY-SxjG-M2iaot [root@rhel5u10 ~]# [root@rhel5u10 ~]# |
查看存储的状态:
1 2 3 4 5 6 7 8 9 |
[root@rhel5u10 ~]# fdisk -l /dev/sdb Disk /dev/sdb: 32.2 GB, 32212254720 bytes 255 heads, 63 sectors/track, 3916 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 487 3911796 83 Linux [root@rhel5u10 ~]# |
可以看到,存储还有扩展的空间。
首先,在存储上划分新的空间:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
[root@rhel5u10 ~]# fdisk /dev/sdb The number of cylinders for this disk is set to 3916. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Command (m for help): p Disk /dev/sdb: 32.2 GB, 32212254720 bytes 255 heads, 63 sectors/track, 3916 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 487 3911796 83 Linux Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (488-3916, default 488): Using default value 488 Last cylinder or +size or +sizeM or +sizeK (488-3916, default 3916): +8G Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot. Syncing disks. [root@rhel5u10 ~]# [root@rhel5u10 ~]# partprobe /dev/sdb [root@rhel5u10 ~]# [root@rhel5u10 ~]# fdisk -l /dev/sdb Disk /dev/sdb: 32.2 GB, 32212254720 bytes 255 heads, 63 sectors/track, 3916 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 487 3911796 83 Linux /dev/sdb2 488 1461 7823655 83 Linux [root@rhel5u10 ~]# [root@rhel5u10 ~]# |
创建新的PV:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
[root@rhel5u10 ~]# ll /dev/ | grep --color sdb brw-r----- 1 root disk 8, 16 Oct 5 23:38 sdb brw-r----- 1 root disk 8, 17 Oct 5 22:07 sdb1 brw-r----- 1 root disk 8, 18 Oct 5 23:38 sdb2 [root@rhel5u10 ~]# [root@rhel5u10 ~]# pvcreate /dev/sdb2 Writing physical volume data to disk "/dev/sdb2" Physical volume "/dev/sdb2" successfully created [root@rhel5u10 ~]# [root@rhel5u10 ~]# pvdisplay --- Physical volume --- PV Name /dev/sdb1 VG Name vg_oracle PV Size 3.73 GB / not usable 4.11 MB Allocatable yes PE Size (KByte) 4096 Total PE 954 Free PE 24 Allocated PE 930 PV UUID m8I6BK-nN1F-WYx1-GxEI-xSgY-SxjG-M2iaot "/dev/sdb2" is a new physical volume of "7.46 GB" --- NEW Physical volume --- PV Name /dev/sdb2 VG Name PV Size 7.46 GB Allocatable NO PE Size (KByte) 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID QtcwyR-gQ4g-x3dk-aX2w-4M7K-AURA-26jTjV [root@rhel5u10 ~]# |
扩展VG:vg_oracle。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
[root@rhel5u10 ~]# vgextend vg_oracle /dev/sdb2 Volume group "vg_oracle" successfully extended [root@rhel5u10 ~]# [root@rhel5u10 ~]# vgdisplay --- Volume group --- VG Name vg_oracle System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 2 Act PV 2 VG Size 11.19 GB PE Size 4.00 MB Total PE 2864 Alloc PE / Size 930 / 3.63 GB Free PE / Size 1934 / 7.55 GB VG UUID 35JT2d-dZfQ-GINh-ILiA-yy2B-2STI-IjlOTW [root@rhel5u10 ~]# |
扩展LV:lv_oracle。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
[root@rhel5u10 ~]# lvdisplay --- Logical volume --- LV Name /dev/vg_oracle/lv_oracle VG Name vg_oracle LV UUID P7h2qI-eEz1-SIQ2-MfSe-zRcD-mEG9-rUW0mm LV Write Access read/write LV Status available # open 1 LV Size 3.63 GB Current LE 930 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [root@rhel5u10 ~]# [root@rhel5u10 ~]# lvextend -L +7G /dev/vg_oracle/lv_oracle Extending logical volume lv_oracle to 10.63 GB Logical volume lv_oracle successfully resized [root@rhel5u10 ~]# [root@rhel5u10 ~]# lvdisplay --- Logical volume --- LV Name /dev/vg_oracle/lv_oracle VG Name vg_oracle LV UUID P7h2qI-eEz1-SIQ2-MfSe-zRcD-mEG9-rUW0mm LV Write Access read/write LV Status available # open 1 LV Size 10.63 GB Current LE 2722 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [root@rhel5u10 ~]# |
应用扩容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
[root@rhel5u10 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 18G 2.8G 14G 17% / /dev/sda1 289M 17M 258M 7% /boot tmpfs 500M 0 500M 0% /dev/shm /dev/sr0 4.1G 4.1G 0 100% /iso /dev/mapper/vg_oracle-lv_oracle 3.6G 2.9G 566M 84% /u01 [root@rhel5u10 ~]# [root@rhel5u10 ~]# resize2fs /dev/vg_oracle/lv_oracle resize2fs 1.39 (29-May-2006) Filesystem at /dev/vg_oracle/lv_oracle is mounted on /u01; on-line resizing required Performing an on-line resize of /dev/vg_oracle/lv_oracle to 2787328 (4k) blocks. The filesystem on /dev/vg_oracle/lv_oracle is now 2787328 blocks long. [root@rhel5u10 ~]# [root@rhel5u10 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 18G 2.8G 14G 17% / /dev/sda1 289M 17M 258M 7% /boot tmpfs 500M 0 500M 0% /dev/shm /dev/sr0 4.1G 4.1G 0 100% /iso /dev/mapper/vg_oracle-lv_oracle 11G 2.9G 7.1G 29% /u01 [root@rhel5u10 ~]# |
至此,LVM扩容完成。
——————————————————————
Ending。