LVM修改swap交换分区大小

为了更好的感受CentOS,我决定把虚拟机的内存从512减少到256,哈哈~~~

关机,修改,重启。

然后再检查一下,没必要的服务全关掉,进程kill掉。

发现交换分区比较碍眼,然后发现是LVM的,然后就是改这里了。。。

   

先找到交换分区,fdisk里没有,google了一下只有到/etc/fstab找了。

   

[root@centos01 ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/VolGroup00-LogVol00 19G 4.0G 14G 23% /

/dev/sda1 99M 12M 82M 13% /boot

tmpfs 125M 0 125M 0% /dev/shm

.host:/ 193G 6.1G 187G 4% /mnt/hgfs

[root@centos01 ~]# cat /etc/fstab

/dev/VolGroup00/LogVol00 / ext3 defaults 1 1

LABEL=/boot /boot ext3 defaults 1 2

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

/dev/VolGroup00/LogVol01 swap swap defaults 0 0

   

其实这里也有。。

[root@centos01 ~]# cat /proc/swaps

Filename Type Size Used Priority

/dev/mapper/VolGroup00-LogVol01 partition 1048568 0 -1

   

   

这里只有一个卷组,2个卷,一个是根分区,一个是swap分区。

   

[root@centos01 ~]# vgdisplay -v

Finding all volume groups

Finding volume group "VolGroup00"

--- 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 19.88 GB

PE Size 32.00 MB

Total PE 636

Alloc PE / Size 636 / 19.88 GB

Free PE / Size 0 / 0

VG UUID ASOZ1Q-lv3w-Mp8e-NbrI-KJyT-Z0fo-L5XsB2

 

--- Logical volume ---

LV Name /dev/VolGroup00/LogVol00

VG Name VolGroup00

LV UUID eavv3T-mYNr-UZSO-rgUS-RqAb-fwQT-FfK3fT

LV Write Access read/write

LV Status available

# open 1

LV Size 18.88 GB

Current LE 604

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 zbtJp1-THIO-XHRQ-qpv1-PRRp-Wuqt-Ls4RFO

LV Write Access read/write

LV Status available

# open 1

LV Size 1.00 GB

Current LE 32

Segments 1

Allocation inherit

Read ahead sectors auto

- currently set to 256

Block device 253:1

 

--- Physical volumes ---

PV Name /dev/sda2

PV UUID LUO0ND-cQIi-N60M-GlnC-CDsa-7JMn-NQrBNL

PV Status allocatable

Total PE / Free PE 636 / 0

   

   

目标找到了,开工!!

这里分几部:

1、停掉swap分区

2、缩小swap对应卷的大小,同时增加根分区卷大小(资源不能浪费了!!)

3、同步卷

4、重做swap分区

5、DONE

   

[root@centos01 ~]# free

total used free shared buffers cached

Mem: 255444 143904 111540 0 14088 107696

-/+ buffers/cache: 22120 233324

Swap: 1048568 0 1048568

[root@centos01 ~]# swapoff -a

[root@centos01 ~]# free

total used free shared buffers cached

Mem: 255444 143432 112012 0 14100 107696

-/+ buffers/cache: 21636 233808

Swap: 0 0 0

[root@centos01 ~]# lvreduce /dev/VolGroup00/LogVol01 -L -512M

WARNING: Reducing active logical volume to 512.00 MB

THIS MAY DESTROY YOUR DATA (filesystem etc.)

Do you really want to reduce LogVol01? [y/n]: y

Reducing logical volume LogVol01 to 512.00 MB

Logical volume LogVol01 successfully resized

[root@centos01 ~]# lvextend /dev/VolGroup00/LogVol00 -L +512M

Extending logical volume LogVol00 to 19.38 GB

Logical volume LogVol00 successfully resized

[root@centos01 ~]#

[root@centos01 ~]# vgdisplay -v

Finding all volume groups

Finding volume group "VolGroup00"

--- Volume group ---

VG Name VolGroup00

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 1

Max PV 0

Cur PV 1

Act PV 1

VG Size 19.88 GB

PE Size 32.00 MB

Total PE 636

Alloc PE / Size 636 / 19.88 GB

Free PE / Size 0 / 0

VG UUID ASOZ1Q-lv3w-Mp8e-NbrI-KJyT-Z0fo-L5XsB2

 

--- Logical volume ---

LV Name /dev/VolGroup00/LogVol00

VG Name VolGroup00

LV UUID eavv3T-mYNr-UZSO-rgUS-RqAb-fwQT-FfK3fT

LV Write Access read/write

LV Status available

# open 1

LV Size 19.38 GB

Current LE 620

Segments 2

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 zbtJp1-THIO-XHRQ-qpv1-PRRp-Wuqt-Ls4RFO

LV Write Access read/write

LV Status available

# open 0

LV Size 512.00 MB

Current LE 16

Segments 1

Allocation inherit

Read ahead sectors auto

- currently set to 256

Block device 253:1

 

--- Physical volumes ---

PV Name /dev/sda2

PV UUID LUO0ND-cQIi-N60M-GlnC-CDsa-7JMn-NQrBNL

PV Status allocatable

Total PE / Free PE 636 / 0

   

已经改变了,但是还需要同步卷上的文件系统。

[root@centos01 ~]# 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 5079040 (4k) blocks.

The filesystem on /dev/VolGroup00/LogVol00 is now 5079040 blocks long.

   

[root@centos01 ~]# resize2fs /dev/VolGroup00/LogVol01

resize2fs 1.39 (29-May-2006)

resize2fs: Bad magic number in super-block while trying to open /dev/VolGroup00/LogVol01

Couldn't find valid filesystem superblock.

   

交换分区不包含有效的文件系统,不能被同步,需要重建。

   

[root@centos01 ~]# mkswap /dev/VolGroup00/LogVol01

Setting up swapspace version 1, size = 536866 kB

[root@centos01 ~]# swapon -a

[root@centos01 ~]# free

total used free shared buffers cached

Mem: 255444 165340 90104 0 33768 109300

-/+ buffers/cache: 22272 233172

Swap: 524280 0 524280

   

   

DONE

   

博客园用起来感觉也很不爽!!!OneNote发布居然告诉我不支持图片!!!!

   

posted @ 2011-12-24 18:48  鸡蛋的冬天  阅读(5817)  评论(0编辑  收藏  举报