微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

centos7.0下增加swap分区大小

承接上篇文章扩容磁盘空间后增加根分区的大小后,来扩容swap分区的空间

检查当前的swap分区情况

# free -m

# free -g

[[email protected] ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           3776         130        3487           8         158        3461
Swap:          2047           0        2047
[[email protected] ~]# 
[[email protected] ~]# free -g
              total        used        free      shared  buff/cache   available
Mem:              3           0           3           0           0           3
Swap:             1           0           1

 查看磁盘分区挂载情况:

# cat /etc/fstab

[[email protected] ~]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Fri Feb 15 20:30:13 2019
#
# 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/centos-root /                       xfs     defaults        0 0
UUID=a3983c4b-cce5-47b8-b1f7-f9c7d177d034 /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
[[email protected] ~]# 

 

查看交换分区大小

# fdisk -l /dev/mapper/centos-swap 

[[email protected] ~]# fdisk -l /dev/mapper/c
centos-root  centos-swap  control      
[[email protected] ~]# fdisk -l /dev/mapper/centos-swap 

disk /dev/mapper/centos-swap: 2147 MB,2147483648 bytes,4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

 

 查看逻辑卷

# lvdisplay

[[email protected] ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                hw5xxY-pk8O-tFdd-RWXj-Kjzd-YlXG-55aifc
  LV Write Access        read/write
  LV Creation host,time localhost.localdomain,2019-02-15 20:30:11 +0800
  LV Status              available
  # open                 1
  LV Size                115.00 GiB
  Current LE             29440
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                Gjc4kX-XGS5-0H42-WVIJ-jllu-W9Ql-TQ7Je8
  LV Write Access        read/write
  LV Creation host,2019-02-15 20:30:11 +0800
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
[[email protected] ~]# 

 

 新增分区

#fdisk /dev/sda

需要重启才能生效

#reboot

重启后查看硬盘信息

# lsblk

[[email protected] ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  150G  0 disk 
├─sda1            8:1    0  200M  0 part /boot
├─sda2            8:2    0   17G  0 part 
│ ├─centos-root 253:0    0  115G  0 lvm  /
│ └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
├─sda3            8:3    0  100G  0 part 
│ └─centos-root 253:0    0  115G  0 lvm  /
└─sda4            8:4    0 32.8G  0 part 
sr0              11:0    1    4G  0 rom  

 

分区格式化

# mkfs -t ext4 /dev/sda4

[[email protected] ~]# mkfs -t ext4 /dev/sda4
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks,Stripe width=0 blocks
2150288 inodes,8597248 blocks
429862 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2157969408
263 block groups
32768 blocks per group,32768 fragments per group
8176 inodes per group
Superblock backups stored on blocks: 
        32768,98304,163840,229376,294912,819200,884736,1605632,2654208,4096000,7962624

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done 

 

创建物理卷

# pvcreate /dev/sda4

[[email protected] ~]# pvcreate /dev/sda4
WARNING: ext4 signature detected on /dev/sda4 at offset 1080. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/sda4.
  Physical volume "/dev/sda4" successfully created

加入根分区的逻辑卷组

# vgextend centos /dev/sda3

查看确认

# vgdisplay

[[email protected] ~]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        3
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                3
  Act PV                3
  VG Size               149.79 GiB
  PE Size               4.00 MiB
  Total PE              38347
  Alloc PE / Size       29952 / 117.00 GiB
  Free  PE / Size       8395 / 32.79 GiB
  VG UUID               a27Boi-C0ue-9PCo-1rPZ-BsjW-9IRg-Woh4uX

卸载swap分区

# swapoff /dev/mapper/centos-swap

扩展swap逻辑卷

# lvextend  -L +2G /dev/mapper/centos-swap

[[email protected] ~]# swapoff /dev/mapper/centos-swap
[[email protected] ~]# 
[[email protected] ~]# lvextend  -L +2G /dev/mapper/centos-swap
  Size of logical volume centos/swap changed from 2.00 GiB (512 extents) to 4.00 GiB (1024 extents).
  Logical volume swap successfully resized.
[[email protected] ~]# 
[[email protected] ~]# fdisk -l /dev/mapper/centos-swap 

disk /dev/mapper/centos-swap: 4294 MB,4294967296 bytes,8388608 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[[email protected] ~]# 

 

 格式化新swap分区

# mkswap /dev/mapper/centos-swap

[[email protected] ~]# mkswap /dev/mapper/centos-swap
mkswap: /dev/mapper/centos-swap: warning: wiping old swap signature.
Setting up swapspace version 1,size = 4194300 KiB
no label,UUID=05ed5220-b350-4bb1-8483-f75dbe35b0ba

重新挂载swap分区

# swapon /dev/mapper/centos-swap

[[email protected] ~]# swapon /dev/mapper/centos-swap
[[email protected] ~]# 
[[email protected] ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           3776         142        3475           8         158        3449
Swap:          4095           0        4095

 

重启系统验证

#reboot

# free -m

[[email protected] ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           3776         133        3487           8         155        3460
Swap:          4095           0        4095
[[email protected] ~]# 

 

至此swap分区扩容完毕

 

 

 

 

 参考博客

Linux swap扩容

https://www.cnblogs.com/rangle/p/9075370.html

 

 

end

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。