增加操作系统上的交换文件

新的这一点,我想弄清楚什么是最好的方式继续下去。 我有一个系统,我需要增加它的交换文件,我意识到交换分区不是lvm,所以这是一种。 但是,我目前的交换分区是8Gb,但需要在16GB。

# swapon -s Filename Type Size Used Priority /swapfile file 8191996 6341008 -1 

我想我的问题是,这是一个交换文件,而不是一个分区(至less是我的问题:(…)我在线阅读我可以使用DD创build一个交换文件,但我不知道我明白实际上增加的大小,或者如果我需要创build一个新的分区。

/ etc / fstab看起来像这样:

 /swapfile swap swap defaults 0 0 

任何关于如何进行的build议?

如上所述,您可以调整交换文件的大小以获得所需的效果。 但我build议添加另一个交换文件,具有相同的优先级,所以你不需要交换掉交换的数据的GB。

 # Create another swapfile, mind the filename! sudo dd if=/dev/zero of=/swapfile2 bs=1M count=8192 # Make the new file a swapfile sudo mkswap /swapfile2 # Enable it sudo swapon /swapfile2 # Change its priority sudo swapon /swapfile2 -p -1 # Or anything you want 

然后将/swapfile2 swap swap defaults 0 0/etc/fstab

一个交换文件实际上就是这样,一个实际的文件用作交换。 有几种方法可以解决这个问题,最好是删除它并创build一个新的。

 # this disables ALL swap, you can target with swapoff /swapfile sudo swapoff -a # delete old swap file sudo rm /swapfile # create new swap file. dd takes /dev/zero which always returns.. 0 then it # writes that data into the file under 'of'. So it is just a file full of 0s # bs is blocksize and count is number of blocks, so bs=1M and count=16284 # will create a 16284 MByte file. Adjust count to make a bigger file. sudo dd if=/dev/zero of=/swapfile bs=1M count=16384 # make file a swapfile sudo mkswap /swapfile # enable swapfile sudo swapon /swapfile # you already have swapfile of the same name in fstab, so no need to edit it