默认安装的CentOS6.3操作系统,使用lvm分区。root挂载了50G,home挂载了1.5T。
由于需求要求,现在需要把home的1.5T全部移动到root下。
使用archiso启动,查看lvm信息如下:
root@archiso ~ # pvdisplay
--- Physical volume ---
PV Name /dev/sdb2
VG Name vg_t185
PV Size 931.02 GiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE
Free PE
Allocated PE
PV UUID cK8ZW2-Mtcv-ry1H-7WU0-kLeD-i0M4-jipmh8
root@archiso ~ # lvdisplay
--- Logical volume ---
LV Path /dev/vg_t185/lv_root
LV Name lv_root
VG Name vg_t185
LV UUID 7IU9S2-S0cY-WG6L-7yLK-sWle-Ogtg-3bPC5y
LV Write Access read/write
LV Creation host, time T185, -- :: +
LV Status available
# open
LV Size 50.00 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : --- Logical volume ---
LV Path /dev/vg_t185/lv_home
LV Name lv_home
VG Name vg_t185
LV UUID RhQnwT-Ol18-ERl3-d2oD-O63V-IzWq-f1eTxB
LV Write Access read/write
LV Creation host, time T185, -- :: +
LV Status available
# open
LV Size 849.51 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : --- Logical volume ---
LV Path /dev/vg_t185/lv_swap
LV Name lv_swap
VG Name vg_t185
LV UUID 5noJ0H-Sz1h-Kdo0-3elo-lhLw-HcRv-8dB8GY
LV Write Access read/write
LV Creation host, time T185, -- :: +
LV Status available
# open
LV Size 31.51 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device :
root@archiso ~ # vgdisplay
--- Volume group ---
VG Name vg_t185
System ID
Format lvm2
Metadata Areas
Metadata Sequence No
VG Access read/write
VG Status resizable
MAX LV
Cur LV
Open LV
Max PV
Cur PV
Act PV
VG Size 931.02 GiB
PE Size 4.00 MiB
Total PE
Alloc PE / Size / 931.02 GiB
Free PE / Size /
VG UUID DKq4iJ-p00S-PMji-zkgc-nip2-Y7gY-extOPT
当前状态是一个pv sdb2, 一个vg vg_t185, 三个lv lv_root, lv_swap, lv_home 。
思路就是: 1. 删掉lv_home. 2. 把分区添加到lv_root. 3. 在root下创建home目录。 4. 修改fstab
删除:
root@archiso ~ # lvremove vg_t185/lv_home
Do you really want to remove active logical volume vg_t185/lv_home? [y/n]: y
Logical volume "lv_home" successfully removed
root@archiso ~ #
root@archiso ~ # lvdisplay
--- Logical volume ---
LV Path /dev/vg_t185/lv_root
LV Name lv_root
VG Name vg_t185
LV UUID 7IU9S2-S0cY-WG6L-7yLK-sWle-Ogtg-3bPC5y
LV Write Access read/write
LV Creation host, time T185, -- :: +
LV Status available
# open
LV Size 50.00 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : --- Logical volume ---
LV Path /dev/vg_t185/lv_swap
LV Name lv_swap
VG Name vg_t185
LV UUID 5noJ0H-Sz1h-Kdo0-3elo-lhLw-HcRv-8dB8GY
LV Write Access read/write
LV Creation host, time T185, -- :: +
LV Status available
# open
LV Size 31.51 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : root@archiso ~ # vgdisplay
--- Volume group ---
VG Name vg_t185
System ID
Format lvm2
Metadata Areas
Metadata Sequence No
VG Access read/write
VG Status resizable
MAX LV
Cur LV
Open LV
Max PV
Cur PV
Act PV
VG Size 931.02 GiB
PE Size 4.00 MiB
Total PE
Alloc PE / Size / 81.51 GiB
Free PE / Size / 849.51 GiB
VG UUID DKq4iJ-p00S-PMji-zkgc-nip2-Y7gY-extOPT root@archiso ~ #
扩充:
root@archiso ~ # lvextend -l +%FREE -t /dev/vg_t185/lv_root /dev/sdb2
TEST MODE: Metadata will NOT be updated and volumes will not be (de)activated.
Size of logical volume vg_t185/lv_root changed from 50.00 GiB ( extents) to 899.51 GiB ( extents).
Logical volume lv_root successfully resized.
root@archiso ~ # lvextend -l +%FREE /dev/vg_t185/lv_root /dev/sdb2
Size of logical volume vg_t185/lv_root changed from 50.00 GiB ( extents) to 899.51 GiB ( extents).
Logical volume lv_root successfully resized.
root@archiso ~ #
root@archiso ~ # lvdisplay
--- Logical volume ---
LV Path /dev/vg_t185/lv_root
LV Name lv_root
VG Name vg_t185
LV UUID 7IU9S2-S0cY-WG6L-7yLK-sWle-Ogtg-3bPC5y
LV Write Access read/write
LV Creation host, time T185, -- :: +
LV Status available
# open
LV Size 899.51 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : --- Logical volume ---
LV Path /dev/vg_t185/lv_swap
LV Name lv_swap
VG Name vg_t185
LV UUID 5noJ0H-Sz1h-Kdo0-3elo-lhLw-HcRv-8dB8GY
LV Write Access read/write
LV Creation host, time T185, -- :: +
LV Status available
# open
LV Size 31.51 GiB
Current LE
Segments
Allocation inherit
Read ahead sectors auto
- currently set to
Block device : root@archiso ~ #
修改fstab
root@archiso ~/mnt # diff etc/fstab fstab.bak
10a11
> /dev/mapper/vg_t185-lv_home /home ext4 defaults
root@archiso ~/mnt #
reboot
二, 新增一块硬盘来扩充。
为硬盘创建分区:
parted /dev/vdb
mklabel gpt
mkpart primary 1MiB %
创建物理卷
pvcreate /dev/vdb1
将新卷加入卷组
vgextend vg_t209 /dev/vdb1
逻辑卷扩充
lvextend -l +%FREE -t /dev/vg_t209/lv_root /dev/vdb1
lvextend -l +100%FREE /dev/vg_t209/lv_root /dev/vdb1
这是,在文件系统里是看不见大小变化的。
我用的是ext4文件系统,然后还应该resize ext4, 使用如下方法:
https://pubmem.wordpress.com/2010/09/16/how-to-resize-lvm-logical-volumes-with-ext4-as-filesystem/
resize2fs -f /dev/mapper/vg_t209-lv_root