您的位置:首页 > 运维架构 > Linux

CentOS 6.2下删除逻辑卷和增加根目录空间

2012-10-24 15:21 381 查看
转自:http://kicklinux.com/lvm-manage-create-extend/

CentOS使用逻辑卷对磁盘空间进行管理,大大方便管理人员对空间的调整。很多童鞋安装系统时,分区使用默认设置,CentOS自动分配的home空间很大。因为我们生产环境中基本不使用home空间,所以决定把home挂载到lv_root逻辑卷上,把腾出的空间增加给lv_root逻辑卷。

查看系统目录的挂载情况:

[root@message1 /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_message1-lv_root
50G  2.3G   45G   5% /
tmpfs                1003M     0 1003M   0% /dev/shm
/dev/cciss/c0d0p1     485M   32M  428M   7% /boot
/dev/mapper/vg_message1-lv_home
14G  163M   13G   2% /home

[root@message1 /]# pvdisplay
--- Physical volume ---
PV Name               /dev/cciss/c0d0p2
VG Name               vg_message1
PV Size               67.84 GiB / not usable 4.00 MiB
Allocatable           yes (but full)
PE Size               4.00 MiB
Total PE              17367
Free PE               0
Allocated PE          17367
PV UUID               yKXnTp-6cWG-1MCG-FpHc-6QCX-nK1H-otKaMf

[root@message1 /]# vgdisplay
--- Volume group ---
VG Name               vg_message1
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               3
Max PV                0
Cur PV                1
Act PV                1
VG Size               67.84 GiB
PE Size               4.00 MiB
Total PE              17367
Alloc PE / Size       17367 / 67.84 GiB
Free  PE / Size       0 / 0
VG UUID               pDMn2R-tV0b-AL0Y-BRgV-focH-hpym-yoakDa

[root@message1 /]# lvdisplay
--- Logical volume ---
LV Name                /dev/vg_message1/lv_root
VG Name                vg_message1
LV UUID                SAOoO3-Fwtk-wPYg-yi2X-6SXu-qgVZ-lVDz75
LV Write Access        read/write
LV Status              available
# open                 1
LV Size                50.00 GiB
Current LE             12800
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:0

--- Logical volume ---
LV Name                /dev/vg_message1/lv_home
VG Name                vg_message1
LV UUID                xcjRkh-gSR3-ykfu-LRtV-RA47-3c7q-ZsqqBf
LV Write Access        read/write
LV Status              available
# open                 1
LV Size                13.90 GiB
Current LE             3559
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:2

--- Logical volume ---
LV Name                /dev/vg_message1/lv_swap
VG Name                vg_message1
LV UUID                bJcLZE-uG1l-KNpU-OgNH-VceH-ib4d-gGOuKO
LV Write Access        read/write
LV Status              available
# open                 1
LV Size                3.94 GiB
Current LE             1008
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:1

确认home目录下没有数据后,将home目录卸载,这时home目录将使用lv_root逻辑卷进行存储。

[root@message1 /]# umount /home
[root@message1 /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_message1-lv_root
50G  2.3G   45G   5% /
tmpfs                1003M     0 1003M   0% /dev/shm
/dev/cciss/c0d0p1     485M   32M  428M   7% /boot

这时就可以删除lv_home

[root@message1 /]# lvremove /dev/vg_message1/lv_home
Do you really want to remove active logical volume lv_home? [y/n]: y
Logical volume "lv_home" successfully removed

查看逻辑卷信息,发现lv_home已经删除

[root@message1 /]# lvdisplay
--- Logical volume ---
LV Name                /dev/vg_message1/lv_root
VG Name                vg_message1
LV UUID                SAOoO3-Fwtk-wPYg-yi2X-6SXu-qgVZ-lVDz75
LV Write Access        read/write
LV Status              available
# open                 1
LV Size                50.00 GiB
Current LE             12800
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:0

--- Logical volume ---
LV Name                /dev/vg_message1/lv_swap
VG Name                vg_message1
LV UUID                bJcLZE-uG1l-KNpU-OgNH-VceH-ib4d-gGOuKO
LV Write Access        read/write
LV Status              available
# open                 1
LV Size                3.94 GiB
Current LE             1008
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:1

发现逻辑卷组已经有13.9G的空间空闲

[root@message1 /]# vgdisplay
--- Volume group ---
VG Name               vg_message1
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               2
Max PV                0
Cur PV                1
Act PV                1
VG Size               67.84 GiB
PE Size               4.00 MiB
Total PE              17367
Alloc PE / Size       13808 / 53.94 GiB
Free  PE / Size       3559 / 13.90 GiB
VG UUID               pDMn2R-tV0b-AL0Y-BRgV-focH-hpym-yoakDa

将所有空闲空间增加给逻辑卷lv_root

[root@message1 ~]# lvextend -L +13.9G /dev/vg_message1/lv_root
Rounding up size to full physical extent 13.90 GiB
Extending logical volume lv_root to 63.90 GiB
Logical volume lv_root successfully resized

查看当前系统逻辑卷信息,发现lv_root的空间大小发生变化

[root@message1 ~]# lvdisplay
--- Logical volume ---
LV Name                /dev/vg_message1/lv_root
VG Name                vg_message1
LV UUID                SAOoO3-Fwtk-wPYg-yi2X-6SXu-qgVZ-lVDz75
LV Write Access        read/write
LV Status              available
# open                 1
LV Size                63.90 GiB
Current LE             16359
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:0

--- Logical volume ---
LV Name                /dev/vg_message1/lv_swap
VG Name                vg_message1
LV UUID                bJcLZE-uG1l-KNpU-OgNH-VceH-ib4d-gGOuKO
LV Write Access        read/write
LV Status              available
# open                 1
LV Size                3.94 GiB
Current LE             1008
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           253:1

此时查看文件系统的根目录空间并没有发生变化

[root@message1 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_message1-lv_root
50G  2.3G   45G   5% /
tmpfs                1003M     0 1003M   0% /dev/shm
/dev/cciss/c0d0p1     485M   32M  428M   7% /boot

调整文件系统空间

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

查看文件系统空间大小,发现根目录由50G增加到63G,到此文件系统空间调整完成。

[root@message1 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_message1-lv_root
63G  2.3G   58G   4% /
tmpfs                1003M     0 1003M   0% /dev/shm
/dev/cciss/c0d0p1     485M   32M  428M   7% /boot

修改操作系统挂载目录的配置文件/etc/fstab,注释掉home挂载,注意一定要操作这一步哦,不然下次重启系统就无法启动啦。

[root@message1 ~]# more /etc/fstab

#
# /etc/fstab
# Created by anaconda on Tue Jul 10 19:51:36 2012
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_message1-lv_root /                       ext4    defaults        1 1
UUID=cfe0f4a9-5a71-4089-8258-e1c0105de411 /boot                   ext4    defaults        1 2
#/dev/mapper/vg_message1-lv_home /home                   ext4    defaults        1 2
/dev/mapper/vg_message1-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0

看了以后是不是觉得逻辑卷管理简单而且方便啊!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: