怎样添加、删除、移动Linux下的Swap空间
答案:3 悬赏:10 手机版
解决时间 2021-02-27 21:08
- 提问者网友:夢醒日落
- 2021-02-26 23:17
怎样添加、删除、移动Linux下的Swap空间
最佳答案
- 五星知识达人网友:神也偏爱
- 2021-02-26 23:59
1.内存占用情况
[root@mysql01 Downloads]# free
total used free shared buffers cached
Mem: 1922020 1691448 230572 0 49844 1252236
-/+ buffers/cache: 389368 1532652
Swap: 0 0 0
2.通过dd命令增加swap
[root@mysql01 var]# dd if=/dev/zero of=/var/swap bs=1024 count=2048000
2048000+0 records in
2048000+0 records out
2097152000 bytes (2.1 GB) copied, 5.9442 s, 353 MB/s
3.创建swap文件
[root@mysql01 var]# mkswap /var/swap
mkswap: /var/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=daa18338-0371-4848-888d-49d662dafe3f
[root@mysql01 var]# mkswap -f /var/swap
Setting up swapspace version 1, size = 2047996 KiB
no label, UUID=754e3fdf-258c-45f2-bb8e-4725862850d3
4.加载该文件:
[root@mysql01 var]# swapon /var/swap
5.看看swap是否生效
[root@mysql01 var]# free
6.查看swap当前状态:
[root@mysql01 var]# cat /proc/swaps
Filename Type Size Used Priority
/var/swap file 2047992 0 -1
7.添加至/etc/fstab
[root@mysql01 var]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Sep 23 17:58:53 2014
#
# 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
#
UUID=98f4128a-2ac6-4822-8624-300c4d818afc / ext4 defaults 1 1
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
/var/swap swap swap defaults 0 0
8.如果不再需要swap,可以清理该分区:
[root@mysql01 var]# swapoff /var/swap
[root@mysql01 Downloads]# free
total used free shared buffers cached
Mem: 1922020 1691448 230572 0 49844 1252236
-/+ buffers/cache: 389368 1532652
Swap: 0 0 0
2.通过dd命令增加swap
[root@mysql01 var]# dd if=/dev/zero of=/var/swap bs=1024 count=2048000
2048000+0 records in
2048000+0 records out
2097152000 bytes (2.1 GB) copied, 5.9442 s, 353 MB/s
3.创建swap文件
[root@mysql01 var]# mkswap /var/swap
mkswap: /var/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=daa18338-0371-4848-888d-49d662dafe3f
[root@mysql01 var]# mkswap -f /var/swap
Setting up swapspace version 1, size = 2047996 KiB
no label, UUID=754e3fdf-258c-45f2-bb8e-4725862850d3
4.加载该文件:
[root@mysql01 var]# swapon /var/swap
5.看看swap是否生效
[root@mysql01 var]# free
6.查看swap当前状态:
[root@mysql01 var]# cat /proc/swaps
Filename Type Size Used Priority
/var/swap file 2047992 0 -1
7.添加至/etc/fstab
[root@mysql01 var]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Sep 23 17:58:53 2014
#
# 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
#
UUID=98f4128a-2ac6-4822-8624-300c4d818afc / ext4 defaults 1 1
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
/var/swap swap swap defaults 0 0
8.如果不再需要swap,可以清理该分区:
[root@mysql01 var]# swapoff /var/swap
全部回答
- 1楼网友:琴狂剑也妄
- 2021-02-27 01:52
这是linux的逻辑卷设备,就是这样命名的。不像/dev/sda这样的物理设备的命名方式。
- 2楼网友:杯酒困英雄
- 2021-02-27 01:21
1.用dd生成swap文件:dd if=/dev/zero of=newswap bs=2M count=4096
2.将dd生成的文件格式化为swap类型:mkswap newswap
3.启用swap:swapon newswap
4.卸载swap:swapoff newswap
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯