Linux系统中如何调整swap大小

Linux系统中如何调整swap大小,第1张

这里我要跟大家介绍的是Linux系统中调整swap大小的 方法 。欢迎大家阅读。

 

Linux系统中调整swap大小的方法

1、使用free命令带上m参数,查看swap文件大小,官方建议在RAM是2到4.5G时,swap是RAM的2倍如果RAM大于等于4G则swap等于RAM即可

2、也可用cat 查看etc目录下的swaps文件,如下图

3、创建一个swap文件

复制内容到剪贴板

########

dd if=/dev/zero of=/tmp/swap bs=1MB count=1024

########

以下仅供参考:不用看

Creating a swap file

First of, make sure the file system the disk you wish to swap on is properly mounted. For the purposes of this tutorial we will assume the disk is mounted as /mnt and we want to use the file /mnt/myswap.swp for swapping.

使用下面的命令创建一个1G的swap文件

复制内容到剪贴板

Use the following command to create a 1024MB file that we will use for swapping

########

dd if=/dev/zero of=/mnt/myswap.swp bs=1024MB count=1

########

4、制作一个swap文件,如果觉得繁琐,可以将mkswap文件挂载到tmp目录下,例如:

复制内容到剪贴板

########

mkswap /tmp/swap

########

以下仅供参考:不用看

Preparing the swap file

Before we enable the swap file we must first set it up. The following command accomplishes just that:

########

mkswap /mnt/myswap.swp

########

5、使用swapon 启动/tmp/swap

复制内容到剪贴板

########

swapon /tmp/swap

########

使用一个swap分区,如果已经有一个swap分区,该步骤可以省略

以下仅供参考:不用看

Using a swap partition

Setting up a swap partition is a bit more difficult, as the partition must be first created then formatted using the linux-swap file system. Once that is done, assuming the swap partition is at/dev/scsi/host0/bus0/target0/lun0/part5 (common for v24 USB drives with mutiple partitions), the only command that needs be issued is:

6、再次使用free查看增加后的swap大小

7、如果只想增加swap大小,请忽略以下的 *** 作,重要!!如果不使用刚才增加的1G的swap文件,使用下面的swapoff命令,可以关闭,这样swap文件就缩小了1G

使用swapoff关闭swap文件

复制内容到剪贴板

########

swapoff /tmp/swap

########

注意事项:如果只想增加swap大小,请忽略第7步的所有 *** 作。

已装的linux系统新建swap分区的步骤如下:\x0d\x0a1.fdisk /dev/sda\x0d\x0a2.n (新建一个分区为/dev/sda6)\x0d\x0a3.t (修改分区的id)\x0d\x0a4.82 (swap的id为82)\x0d\x0a5.w (重写分区表)\x0d\x0a6.partprobe (同步内存和分区表信息)\x0d\x0a7.mkswap /dev/sda6 (格式化成swap分区)\x0d\x0a8.swapon /dev/sda6 (打开swap分区)\x0d\x0a9.vim /etc/fstab (在fstab中增加一条记录如下)\x0d\x0a/dev/hda6 swap swap defaults 0 0\x0d\x0a10.mount -a

linux下更改swap大小方法:

以下 *** 作需要root权限,

#cd

/usr/mkdir

swap

#dd

if=/dev/zero

of=swapfile

bs=1G

count=2

这条命令从硬盘里分出一个

2×1G

大小的空间,挂在swapfile上。

#mkswap

swapfile

构建swap格式于/usr/swap/swapfile

#swapon

swapfile

激活swapfile

,加入到swap分区中。

以上 *** 作在重启系统后swap空间将会失去swapfile

,将swapfile

加入到/etc/fstab

条目将可以使得系统在init进程中调用swapon

-a

来自动挂载swapfile

,这样每次机器重启后swapfile

都处于有效的swap空间。

在/etc/fstab文件中加入下面这样一行:

/usr/swap/swapfile

swap

swap

defaults

0

0

这个dd命令很好用,可以用来把大文件分割成小的文件组,利用cat可以将那些小文件组重新组合成原来的大文件。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/7531433.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-06
下一篇 2023-04-06

发表评论

登录后才能评论

评论列表(0条)

保存