加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

LVM增加与缩小Swap分区操作

(2013-07-24 13:51:52)
标签:

lvm缩减swap

lvm扩容swap

it

分类: linux文档记录

LVM作为linux系统平台容量管理还是比较方便的一个开源工具

 

下面针对系统Swap分区扩容与缩减做说明:

 

[root@server10 ~]# free -g
             total       used       free     shared    buffers     cached
Mem:            62         62                                 60
-/+ buffers/cache:                 60
Swap:          127                127
[root@server10 ~]# df -h
[root@server10 ~]# cat /etc/fstab
/dev/VolGroup00/LogVol01 swap                    swap    defaults        0 0
[root@server10 ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                oZ7rEm-hphT-MsGk-fNaD-RC5X-INgZ-oCJdml
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                150.84 GB
  Current LE             4827
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
  
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                pCpqVB-cwXV-MunF-OtBQ-usYA-hFxt-l07IJc
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                127.91 GB
  Current LE             4093
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
  
[root@server10 ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup00
  System ID            
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  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               278.75 GB
  PE Size               32.00 MB
  Total PE              8920
  Alloc PE / Size       8920 / 278.75 GB
  Free  PE / Size       0 / 0  

  VG UUID               9hHRZZ-VUd4-bMwc-rnhK-wiyq-sPZw-dtJREo  
[root@server10 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:         64449      64129        320                327      61494
-/+ buffers/cache:       2307      62142
Swap:       130975             130975
[root@server10 ~]# swapoff -a
[root@server10 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:         64449      64065        384                327      61494
-/+ buffers/cache:       2243      62206
Swap:                            0
[root@server10 ~]# lvreduce /dev/VolGroup00/LogVol01 -L -64G
  WARNING: Reducing active logical volume to 63.91 GB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce LogVol01? [y/n]: y
  Reducing logical volume LogVol01 to 63.91 GB
  Logical volume LogVol01 successfully resized
[root@server10 ~]# mkswap /dev/VolGroup00/LogVol01
Setting up swapspace version 1, size = 68618809 kB
[root@server10 ~]# swapon /dev/VolGroup00/LogVol01
[root@server10 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:         64449      64150        299                327      61549
-/+ buffers/cache:       2273      62175
Swap:        65439              65439
[root@server10 ~]# free -g
             total       used       free     shared    buffers     cached
Mem:            62         62                                 60
-/+ buffers/cache:                 60
Swap:           63                 63
[root@server10 ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup00
  System ID            
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  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               278.75 GB
  PE Size               32.00 MB
  Total PE              8920
  Alloc PE / Size       6872 / 214.75 GB
  Free  PE / Size       2048 / 64.00 GB

  VG UUID               9hHRZZ-VUd4-bMwc-rnhK-wiyq-sPZw-dtJREo
  
[root@server10 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      147G   74G   65G  54% /

/dev/sda1              99M   13M   81M  14% /boot
tmpfs                  32G      32G   0% /dev/shm
[root@server10 ~]# mount
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
[root@server10 ~]# lvextend /dev/VolGroup00/LogVol00 -l +100%FREE
  Extending logical volume LogVol00 to 214.84 GB
  Logical volume LogVol00 successfully resized

[root@server10 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      147G   74G   65G  54% /

/dev/sda1              99M   13M   81M  14% /boot
tmpfs                  32G      32G   0% /dev/shm
[root@server10 ~]# resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 56320000 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 56320000 blocks long.


[root@server10 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      209G   74G  124G  38% /

/dev/sda1              99M   13M   81M  14% /boot
tmpfs                  32G      32G   0% /dev/shm
[root@server10 ~]# 

------------------------------------------------------------------

 

 

以上是减容量,下面针对增加容量做一下命令解析:

 

1.swapoff -a   //关闭swap分区
2. lvresize -L +480M /dev/VolGroup00/LogVol00 //增加swap卷480mb空间
 注意:此步骤以自己的实际情况为准本人的lvm剩余空间只有480mb了
3.resize2fs /dev/VolGroup00/LogVol00 //让添加的空间生效
4.mkswap /dev/VolGroup00/LogVol00 //建立swap分区
5.swapon /dev/VolGroup00/LogVol00//启用swap分区
6.ok

 

 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有