LVM 管理减少swap分区空间增加到根分区(2)

[root@localhost ~]# free -m
            total      used      free    shared    buffers    cached
Mem:          1877        140      1737          0          6        39
-/+ buffers/cache:        93      1783
Swap:        4143          0      4143
[root@localhost ~]# swapoff -a
[root@localhost ~]# free -m
            total      used      free    shared    buffers    cached
Mem:          1877        136      1740          0          6        39
-/+ buffers/cache:        91      1786
Swap:            0          0          0

使用 lvreduce -L -xxx filename 或 lvreduce -L xxx filename 来减少swap分区空间,“-”代表减多少,不加“-”代表减剩多少。下图表示给swap分区留512M。

使用 mke2fs filename 格式化分区

使用 resize2fs filename 重写分区空间

[root@localhost ~]# lvreduce -L 512M /dev/VolGroup/LogVol01
  WARNING: Reducing active and open logical volume to 512.00 MiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce LogVol01? [y/n]: y
  Reducing logical volume LogVol01 to 512.00 MiB
  Logical volume LogVol01 successfully resized
[root@localhost ~]# mke2fs /dev/VolGroup/LogVol01
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
32768 inodes, 131072 blocks
6553 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=134217728
4 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
    32768, 98304

Writing inode tables: done                           
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@localhost ~]# resize2fs /dev/VolGroup/LogVol01
resize2fs 1.41.12 (17-May-2010)
The filesystem is already 131072 blocks long.  Nothing to do!

使用 lvextend -L +1G filename 为根分区增加空闲空间,用法同上。空闲空间可以使用vgdisplay查看,增加空间不需要格式化。

[root@localhost ~]# lvextend -L +3.54G /dev/VolGroup/LogVol00
  Rounding size to boundary between physical extents: 3.54 GiB
  Extending logical volume LogVol00 to 18.00 GiB
  Logical volume LogVol00 successfully resized
[root@localhost ~]# resize2fs /dev/VolGroup/LogVol00
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/VolGroup/LogVol00 is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/VolGroup/LogVol00 to 4719616 (4k) blocks.
The filesystem on /dev/VolGroup/LogVol00 is now 4719616 blocks long.

swap文件

新建2G的swap文件,挂载到swap,添加到开机启动项。

[root@localhost ~]# dd if=/dev/zero of=/www/swap bs=1024 count=2048000
2048000+0 records in
2048000+0 records out
2097152000 bytes (2.1 GB) copied, 12.0018 s, 175 MB/s
[root@localhost ~]# mkswap /www/swap
mkswap: /www/swap: warning: don't erase bootbits sectors
        on whole disk. Use -f to force.
Setting up swapspace version 1, size = 2047996 KiB
no label, UUID=92ab4ed5-f301-4ba4-970f-9e5600610522
[root@localhost ~]# swapon /www/swap
[root@localhost ~]# free -m
            total      used      free    shared    buffers    cached
Mem:          1877      1796        80          0          7      1647
-/+ buffers/cache:        142      1735
Swap:        1999          0      1999
[root@localhost ~]# swapon -s
Filename                Type        Size    Used    Priority
/www/swap                              file        2047992    0    -1

修改启动项

编辑 /etc/fstab文件,去掉之前的swap分区挂载,在最末行增加swap文件的挂载

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

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/16185.html