Linux 新增 lvm 硬碟 (調整硬碟大小)
本範例以 VirtualBOX 本機硬碟空間 8G,並新增新硬碟 100G為例
# 檢查新增硬碟空間
fdisk -l
# 規劃同一個 disk (volumn)
fdisk /dev/sdc
Command (m for help): p
Command (m for help): m
Command (m for help): n
p
Partition number (1-4): 1(非常重要該步驟是選擇磁區編號,最多到4,linux磁區會分為sda"sda1、sda2"、sdb、sdc,依序編號下去)
First cylinder (1-39162, default 1):
Command (m for help): p
Command (m for help): w
#再次檢查新增硬碟資訊
fdisk -l
會發現新的硬碟磁區 /dev/sdc1
# 新增 lvm 磁碟空間
pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created
# 延伸磁碟空間
vgdisplay
vgextend VolGroup /dev/sdc1
Volume group "VolGroup" successfully extended
# 顯示磁區
pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup
PV Size 7.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 1922
Free PE 0
Allocated PE 1922
PV UUID pVkbTq-hAQd-tOUw-T3OL-TpMg-d56t-sHJSiL
--- Physical volume ---
PV Name /dev/sdc1
VG Name VolGroup
PV Size 100.00 GiB / not usable 2.66 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 25599
Free PE 25599
Allocated PE 0
PV UUID TrGTub-QPZm-0aC3-hiEJ-RKU3-RNPs-HvOaMY
# 檢查現有 lvm free 空間
pvscan
PV /dev/sda2 VG VolGroup lvm2 [7.51 GiB / 0 free]
PV /dev/sdc1 VG VolGroup lvm2 [100.00 GiB / 100.00 GiB free]
Total: 2 [107.50 GiB] / in use: 2 [107.50 GiB] / in no VG: 0 [0 ]
# 查看 vg 還有多少 PE 未使用
vgdisplay
# 顯示 lv
lvdisplay
# 將 PE 都給 /dev/VolGroup/lv_root
lvresize -l +21760 /dev/VolGroup/lv_root
# 格式化 /dev/VolGroup/lv_root 讓新增的空間生效
resize2fs /dev/VolGroup/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/VolGroup/lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 7
Performing an on-line resize of /dev/VolGroup/lv_root to 27972608 (4k) blocks.
The filesystem on /dev/VolGroup/lv_root is now 27972608 blocks long.
# 再次檢查硬碟空間,會發現 /根目錄已經增加 100G
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
105G 840M 99G 1% /
tmpfs 499M 0 499M 0% /dev/shm
/dev/sda1 477M 30M 422M 7% /boot
/dev/sdb 1008G 73M 957G 1% /mnt/newdisk
# 檢查新增硬碟空間
fdisk -l
# 規劃同一個 disk (volumn)
fdisk /dev/sdc
Command (m for help): p
Command (m for help): m
Command (m for help): n
p
Partition number (1-4): 1(非常重要該步驟是選擇磁區編號,最多到4,linux磁區會分為sda"sda1、sda2"、sdb、sdc,依序編號下去)
First cylinder (1-39162, default 1):
Command (m for help): p
Command (m for help): w
#再次檢查新增硬碟資訊
fdisk -l
會發現新的硬碟磁區 /dev/sdc1
# 新增 lvm 磁碟空間
pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created
# 延伸磁碟空間
# 檢查 vg 名稱vgdisplay
vgextend VolGroup /dev/sdc1
Volume group "VolGroup" successfully extended
# 顯示磁區
pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup
PV Size 7.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 1922
Free PE 0
Allocated PE 1922
PV UUID pVkbTq-hAQd-tOUw-T3OL-TpMg-d56t-sHJSiL
--- Physical volume ---
PV Name /dev/sdc1
VG Name VolGroup
PV Size 100.00 GiB / not usable 2.66 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 25599
Free PE 25599
Allocated PE 0
PV UUID TrGTub-QPZm-0aC3-hiEJ-RKU3-RNPs-HvOaMY
# 檢查現有 lvm free 空間
pvscan
PV /dev/sda2 VG VolGroup lvm2 [7.51 GiB / 0 free]
PV /dev/sdc1 VG VolGroup lvm2 [100.00 GiB / 100.00 GiB free]
Total: 2 [107.50 GiB] / in use: 2 [107.50 GiB] / in no VG: 0 [0 ]
# 查看 vg 還有多少 PE 未使用
vgdisplay
# 顯示 lv
lvdisplay
# 將 PE 都給 /dev/VolGroup/lv_root
lvresize -l +21760 /dev/VolGroup/lv_root
# 格式化 /dev/VolGroup/lv_root 讓新增的空間生效
resize2fs /dev/VolGroup/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/VolGroup/lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 7
Performing an on-line resize of /dev/VolGroup/lv_root to 27972608 (4k) blocks.
The filesystem on /dev/VolGroup/lv_root is now 27972608 blocks long.
# 再次檢查硬碟空間,會發現 /根目錄已經增加 100G
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
105G 840M 99G 1% /
tmpfs 499M 0 499M 0% /dev/shm
/dev/sda1 477M 30M 422M 7% /boot
/dev/sdb 1008G 73M 957G 1% /mnt/newdisk
留言
張貼留言