2.3減少LV的大小
2.3.1 查看/dev/sda5的PE數
[root@localhost ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda5
VG Name faqvg
PV Size 1.87 GB / not usable 9.96 MB
Allocatable yes (but full)
PE Size (KByte) 16384
Total PE 119
Free PE 0
Allocated PE 119
PV UUID gXmwpU-0oP0-YSmt-rpSd-qj5H-cEYf-1xBcky
2.3.2 降低LV的容量,已知/dev/sda5的PE數為119
[root@localhost ~]# lvresize -l -119 /dev/faqvg/faqlv
/dev/cdrom: open failed: Read-only file system
WARNING: Reducing active and open logical volume to 9.30 GB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce faqlv? [y/n]: y
Reducing logical volume faqlv to 9.30 GB
Logical volume faqlv successfully resized
#會提示說實際資料量比9.30GB小,此部份就輸入y繼續吧。
2.3.3 查看LV總容量是否有變小
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Name /dev/faqvg/faqlv
VG Name faqvg
LV UUID QMOpsQ-3k87-BHSx-7crB-Wrlh-Zx11-Hn332K
LV Write Access read/write
LV Status available
# open 1
LV Size 9.30 GB
Current LE 595
Segments 5
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
2.4將PV移除VG之外
2.4.1 確認/dev/sda5的PE沒被使用才可移除
[root@localhost ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda5
VG Name faqvg
PV Size 1.87 GB / not usable 9.96 MB
Allocatable yes (but full)
PE Size (KByte) 16384
Total PE 119
Free PE 0
Allocated PE 119
PV UUID gXmwpU-0oP0-YSmt-rpSd-qj5H-cEYf-1xBcky
--- Physical volume ---
PV Name /dev/sda9
VG Name faqvg
PV Size 3.73 GB / not usable 12.11 MB
Allocatable yes
PE Size (KByte) 16384
Total PE 238
Free PE 119
Allocated PE 119
PV UUID yxprOa-Gcvb-BHe8-LbOu-3Qxi-1sbC-WN3I4l
#發現到空閒的PE都在/dev/sda9,而/dev/sda5的PE都有在使用。因為要先搬移PE才可移除
2.4.2 搬移PE
[root@localhost ~]# pvmove /dev/sda5 /dev/sda9
/dev/sda5: Moved: 1.7%
/dev/sda5: Moved: 100.0%
[root@localhost ~]# pvdisplay #再次確PE數
--- Physical volume ---
PV Name /dev/sda5
VG Name faqvg
PV Size 1.87 GB / not usable 9.96 MB
Allocatable yes
PE Size (KByte) 16384
Total PE 119
Free PE 119
Allocated PE 0
PV UUID gXmwpU-0oP0-YSmt-rpSd-qj5H-cEYf-1xBcky
--- Physical volume ---
PV Name /dev/sda9
VG Name faqvg
PV Size 3.73 GB / not usable 12.11 MB
Allocatable yes (but full)
PE Size (KByte) 16384
Total PE 238
Free PE 0
Allocated PE 238
PV UUID yxprOa-Gcvb-BHe8-LbOu-3Qxi-1sbC-WN3I4l
2.4.3 從faqvg中移除/dev/sda5
[root@localhost ~]# vgreduce faqvg /dev/sda5
/dev/cdrom: open failed: Read-only file system
Removed "/dev/sda5" from volume group "faqvg"
[root@localhost ~]# pvscan
PV /dev/sda6 VG faqvg lvm2 [1.86 GB / 0 free]
PV /dev/sda7 VG faqvg lvm2 [1.86 GB / 0 free]
PV /dev/sda8 VG faqvg lvm2 [1.86 GB / 0 free]
PV /dev/sda9 VG faqvg lvm2 [3.72 GB / 0 free]
PV /dev/sda5 lvm2 [1.87 GB]
Total: 5 [11.17 GB] / in use: 4 [9.30 GB] / in no VG: 1 [1.87 GB]
2.5從PV中移除partition
[root@localhost ~]# pvremove /dev/sda5
/dev/cdrom: open failed: Read-only file system
Labels on physical volume "/dev/sda5" successfully wiped
[root@localhost ~]# pvscan #查看PV會發現/dev/sda5已經被移除了。
PV /dev/sda6 VG faqvg lvm2 [1.86 GB / 0 free]
PV /dev/sda7 VG faqvg lvm2 [1.86 GB / 0 free]
PV /dev/sda8 VG faqvg lvm2 [1.86 GB / 0 free]
PV /dev/sda9 VG faqvg lvm2 [3.72 GB / 0 free]
Total: 4 [9.30 GB] / in use: 4 [9.30 GB] / in no VG: 0 [0 ]
2.6刪除一個partition
[root@localhost ~]# fdisk -l
/dev/sda5 798 1041 1959898+ 83 Linux
#先查詢看看此partition是否存在
[root@localhost ~]# fdisk /dev/sda
Command (m for help): d
Partition number (1-9): 5
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.
#提示設定需要重開機後才生效,若不想重開幾可使用partprobe(強制生效)
[root@localhost ~]# partprobe
[root@localhost ~]# fdisk -l
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 666 5245222+ 83 Linux
/dev/sda3 667 797 1052257+ 82 Linux swap / Solaris
/dev/sda4 798 2610 14562922+ 5 Extended
/dev/sda6 1042 1285 1959898+ 83 Linux
/dev/sda7 1286 1529 1959898+ 83 Linux
/dev/sda8 1530 1773 1959898+ 83 Linux
/dev/sda9 1774 2260 3911796 83 Linux
#生效之後在查看一下會發現/dev/sda5已經完全被移除了。
LVM-LV的容量增減設定(上)
全文同步於FAQ-BOOK
IT鐵人文章分享