linux 添加交换区内存_如何为Linux添加基于文件的交换

linux 添加交换区内存

We may want to add some swap space for a Linux box while only find that all disk space is partitioned and mounted. Some partition has large available free space. For such cases, we may not want to change the partition allocation. The solution may be to add a file based swap for Linux as what Windows does. How to add a file based swap for Linux is introduced in this post.

我们可能想为Linux盒添加一些交换空间 ,而只是发现所有磁盘空间都已分区并挂载。 某些分区具有较大的可用空间。 在这种情况下,我们可能不想更改分区分配。 解决方案可能是像Windows一样为Linux添加基于文件的交换。 本文介绍了如何为Linux添加基于文件的交换。

We can add a file based swap to Linux following these steps. Here, we use an example to add a 26GB swap file to Linux.

我们可以按照以下步骤将基于文件的交换添加到Linux。 在这里,我们使用一个示例向Linux添加26GB交换文件。

创建用于交换的交换文件 (Create a swap file for swapping)

Command:

命令:

# dd if=/dev/zero of=/swapfile bs=1024 count=2M

You will see output like

您将看到类似的输出

2097152+0 records in
2097152+0 records out
2147483648 bytes (2.1 GB, 2.0 GiB) copied, 41.7768 s, 51.4 MB/s

Note that the common tricks to create a sparse file by adding a `seek` option to `dd` should NOT be used.

请注意,不应使用通过向dd添加“ seek”选项来创建稀疏文件的常见技巧。

It is a good idea to make the swap file only accessible to root since it will store memory content and possibly have sensitive data.

最好使交换文件只能由root用户访问,因为它将存储内存内容并可能包含敏感数据。

# chmod 700 /swapfile

在交换文件上创建交换分区 (Make a swap partition on the swap file)

By the `mkswap` command (`mkswap manual`):

通过`mkswap`命令( `mkswap manual` ):

# mkswap /swapfile

It will show output as follows

它将显示如下输出

mkswap: /swapfile: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
no label, UUID=f30730f3-eb1d-4d30-a088-a0274f3c2f3e

打开用于Linux交换的交换文件 (Turn on the swap file for Linux’s swap)

Now, use `swapon` (swapon manual):

现在,使用`swapon`( swapon manual ):

# swapon /swapfile

You can see all the swap files by

您可以通过以下方式查看所有交换文件

# swapon --show

使交换文件永久用于Linux的交换 (Make the swap file permanent for Linux’s swap)

Add this line to /etc/fstab (for the example in this post)

将此行添加到/ etc / fstab中 (对于本文中的示例)

/swapfile swap swap defaults 0 0

翻译自: https://www.systutorials.com/how-to-add-a-file-based-swap-for-linux/

linux 添加交换区内存

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值