繼上章 Oracle Linux Install Using LVM,我們談到 LVM 的好處在於可以動態放大檔案系統,接下來就來做做看,假設我們安裝 Oracle Linux 時的磁碟配置如下,Volume Group:vg0 有三個 Physical Volume 實體磁區(簡稱PV),依下圖的配置來看,vg0 還有大約 13 G 未分配的磁碟空間。

lvm_01

 

下圖是整個系統磁碟的配置情況:

lvm_02  

 

系統安裝完後,可以用指令 lvscan 來查詢 LVM 實際擁有的空間

[root@oradb12clinux ~]# lvscan
  ACTIVE            '/dev/vg0/lv_u01' [15.00 GiB] inherit
  ACTIVE            '/dev/vg0/lv_root' [10.00 GiB] inherit
  ACTIVE            '/dev/vg0/lv_swap' [4.00 GiB] inherit
  ACTIVE            '/dev/vg0/lv_opt' [8.00 GiB] inherit

 

也可以使用指令 df -h 來看各個磁碟現在的使用狀況

[root@oradb12clinux ~]# df -h
Filesystem                                             Size  Used Avail Use% Mounted on
/dev/mapper/vg0-lv_root                      9.9G  4.1G  5.4G  43%    /
tmpfs                                                    2.0G  176K  2.0G   1%    /dev/shm
/dev/sda1                                            194M   51M  134M  28%  /boot
/dev/sda2                                            811M   17M  753M   3%  /home
/dev/mapper/vg0-lv_opt                      7.9G  146M  7.4G   2%   /opt
/dev/mapper/vg0-lv_u01                       15G  166M   14G   2%  /u01

 

用指令 vgdisplay 查詢一下 Volume Group:vg0 是否有未分配的磁碟空間

[root@oradb12clinux oradb12c]# vgdisplay
  --- Volume group ---
  VG Name               vg0
  System ID             
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  7
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                4
  Open LV               4
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               49.99 GiB
  PE Size               4.00 MiB
  Total PE              12797
  Alloc PE / Size       10521 / 41.10 GiB
  Free  PE / Size       2276 / 8.89 GiB
  VG UUID               MJcTqC-prDM-v0Ys-4s2c-0Fze-vGFD-THI2Iw

 

當發生磁碟空間不足,而 vg0 仍有未分配的磁碟空間時,就可以利用指令 lvextend -L 來增大空間,這樣是不是很方便呢!!

[root@oradb12clinux ~]# lvextend -L +100M '/dev/vg0/lv_opt'
  Extending logical volume lv_opt to 8.10 GiB
  Logical volume lv_opt successfully resized

ot@oradb12clinux oradb12c]# lvextend -L +4096 '/dev/vg0/lv_root'
  Extending logical volume lv_root to 14.00 GiB
  Logical volume lv_root successfully resized


[root@oradb12clinux oradb12c]# lvscan
  ACTIVE            '/dev/vg0/lv_u01' [15.00 GiB] inherit
  ACTIVE            '/dev/vg0/lv_root' [14.00 GiB] inherit
  ACTIVE            '/dev/vg0/lv_swap' [4.00 GiB] inherit
  ACTIVE            '/dev/vg0/lv_opt' [8.10 GiB] inherit


[root@oradb12clinux oradb12c]# df -h
Filesystem                                             Size  Used Avail Use% Mounted on
/dev/mapper/vg0-lv_root                      9.9G  8.8G  644M  94% /
tmpfs                                                     2.0G  264K  2.0G   1% /dev/shm
/dev/sda1                                             194M   51M  134M  28% /boot
/dev/sda2                                             811M   17M  753M   3% /home
/dev/mapper/vg0-lv_opt                       7.9G  146M  7.4G   2% /opt
/dev/mapper/vg0-lv_u01                      15G  166M   14G   2% /u01

 

發現了沒?! Logical Volume 邏輯磁區(簡稱 LV)'/dev/vg0/lv_root' 變大了,變為 14G,但用 df -h 去看時仍為 9.9 G ,lv_opt 也是相同的情形,那是因為尚未讓系統知道磁碟空間己變大,可以使用 resize2fs 來讓系統重新分配,若出現 Cannot use resize2fs as it is online. Use ext2online instead.  訊息,則是告知您,因磁碟在online 的情況下不能使用指令 resize2fs ,需以指令 ext2online 來替代。

[root@oradb12clinux oradb12c]# resize2fs /dev/vg0/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg0/lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/vg0/lv_root to 3670016 (4k) blocks.
The filesystem on /dev/vg0/lv_root is now 3670016 blocks long.

[root@oradb12clinux oradb12c]# resize2fs /dev/vg0/lv_opt
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg0/lv_opt is mounted on /opt; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/vg0/lv_opt to 2122752 (4k) blocks.
The filesystem on /dev/vg0/lv_opt is now 2122752 blocks long.

[root@oradb12clinux oradb12c]# df -h
Filesystem                                               Size  Used Avail Use% Mounted on
/dev/mapper/vg0-lv_root                       14G  8.8G  4.4G  67% /
tmpfs                                                      2.0G  264K  2.0G   1% /dev/shm
/dev/sda1                                               194M   51M  134M  28% /boot
/dev/sda2                                               811M   17M  753M   3% /home
/dev/mapper/vg0-lv_opt                         8.0G  146M  7.5G   2% /opt
/dev/mapper/vg0-lv_u01                        15G  166M   14G   2% /u01

 

再查詢一次,看吧!! 系統也同步將空間實際放大了

 附註:若要看各個 Logical Volume 邏輯磁區(簡稱 LV)的狀態,可以用指令lvdisplay 查詢

[root@oradb12clinux oradb12c]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg0/lv_u01
  LV Name                lv_u01
  VG Name                vg0
  LV UUID                qEiPkX-e9tf-SZow-0lWO-mani-vVG5-z8z3Su
  LV Write Access        read/write
  LV Creation host, time oradb12clinux.globeunion.com, 2013-10-24 00:26:18 +0800
  LV Status              available
  # open                 1
  LV Size                15.00 GiB
  Current LE             3840
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:2
   
  --- Logical volume ---
  LV Path                /dev/vg0/lv_root
  LV Name                lv_root
  VG Name                vg0
  LV UUID                0O3A7O-Lecx-bYK8-orvi-HaG3-Wc9h-OdqZbq
  LV Write Access        read/write
  LV Creation host, time oradb12clinux.globeunion.com, 2013-10-24 00:26:26 +0800
  LV Status              available
  # open                 1
  LV Size                14.00 GiB
  Current LE             3584
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0
   
  --- Logical volume ---
  LV Path                /dev/vg0/lv_swap
  LV Name                lv_swap
  VG Name                vg0
  LV UUID                gV4fRO-FSVF-F7H2-pL9X-qJef-IfUO-mO6oLN
  LV Write Access        read/write
  LV Creation host, time oradb12clinux.globeunion.com, 2013-10-24 00:26:27 +0800
  LV Status              available
  # open                 2
  LV Size                4.00 GiB
  Current LE             1024
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1
   
  --- Logical volume ---
  LV Path                /dev/vg0/lv_opt
  LV Name                lv_opt
  VG Name                vg0
  LV UUID                18OarF-nVXJ-er3a-WsYn-lKJT-LEyJ-1YHcKr
  LV Write Access        read/write
  LV Creation host, time oradb12clinux.globeunion.com, 2013-10-24 00:26:27 +0800
  LV Status              available
  # open                 1
  LV Size                8.10 GiB
  Current LE             2073
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:3

 

參考:

http://www.dbvisit.com/forums/showthread.php?t=343

arrow
arrow
    文章標籤
    linux LVM lvscan lvextend
    全站熱搜

    MIS 發表在 痞客邦 留言(0) 人氣()