[administrative][lvm] lvm 分区修改

 

默认安装的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              238341
  Free PE               0
  Allocated PE          238341
  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, 2017-06-12 23:52:42 +0000
  LV Status              available
  # open                 0
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:0
   
  --- 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, 2017-06-12 23:52:50 +0000
  LV Status              available
  # open                 0
  LV Size                849.51 GiB
  Current LE             217475
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:1
   
  --- 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, 2017-06-12 23:55:01 +0000
  LV Status              available
  # open                 0
  LV Size                31.51 GiB
  Current LE             8066
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:2
   

 

root@archiso ~ # vgdisplay 
  --- Volume group ---
  VG Name               vg_t185
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               931.02 GiB
  PE Size               4.00 MiB
  Total PE              238341
  Alloc PE / Size       238341 / 931.02 GiB
  Free  PE / Size       0 / 0   
  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, 2017-06-12 23:52:42 +0000
  LV Status              available
  # open                 0
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:0
   
  --- 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, 2017-06-12 23:55:01 +0000
  LV Status              available
  # open                 0
  LV Size                31.51 GiB
  Current LE             8066
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:2
   
root@archiso ~ # vgdisplay 
  --- Volume group ---
  VG Name               vg_t185
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               931.02 GiB
  PE Size               4.00 MiB
  Total PE              238341
  Alloc PE / Size       20866 / 81.51 GiB
  Free  PE / Size       217475 / 849.51 GiB
  VG UUID               DKq4iJ-p00S-PMji-zkgc-nip2-Y7gY-extOPT
   
root@archiso ~ # 

 

扩充:

root@archiso ~ # lvextend -l +100%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 (12800 extents) to 899.51 GiB (230275 extents).
  Logical volume lv_root successfully resized.
root@archiso ~ # lvextend -l +100%FREE /dev/vg_t185/lv_root /dev/sdb2 
  Size of logical volume vg_t185/lv_root changed from 50.00 GiB (12800 extents) to 899.51 GiB (230275 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, 2017-06-12 23:52:42 +0000
  LV Status              available
  # open                 0
  LV Size                899.51 GiB
  Current LE             230275
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:0
   
  --- 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, 2017-06-12 23:55:01 +0000
  LV Status              available
  # open                 0
  LV Size                31.51 GiB
  Current LE             8066
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:2
   
root@archiso ~ # 

 

修改fstab

1 root@archiso ~/mnt # diff etc/fstab fstab.bak    
10a11
> /dev/mapper/vg_t185-lv_home /home                   ext4    defaults        1 2
1 root@archiso ~/mnt #           

 

reboot

 

二, 新增一块硬盘来扩充。

为硬盘创建分区:

parted /dev/vdb
mklabel gpt
mkpart primary 1MiB 100%

创建物理卷

pvcreate /dev/vdb1

将新卷加入卷组

vgextend vg_t209 /dev/vdb1

逻辑卷扩充

lvextend -l +100%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

 

posted on 2017-06-07 20:23  toong  阅读(328)  评论(0编辑  收藏  举报