睇到篇文章,介紹加大Linux的swap space的方法,試左,work!

以我的電腦為例,ram(7.5GB)及swap space volume(0.5GB)將滿,要加大swap space,恰好/media/DC0C1CAB0C1C82A6/有多餘的空間(遠超25GB),於是用指令

create a new file named swapfile1
dd if=/dev/zero of=/media/DC0C1CAB0C1C82A6/swapfile1 bs=1024 count=26214400

make it as a swap
mkswap /media/DC0C1CAB0C1C82A6/swapfile1

turn it on
swapon /media/DC0C1CAB0C1C82A6/swapfile1

check it out
free -m

注:
由於我用root terminal,不需在指令前加sudo

文章鏈結:http://xx3d2ybnf.pixnet.net/blog/post/143381208-在linux系統中動態增加swap檔案空間的方法

turn it off
swapoff /media/DC0C1CAB0C1C82A6/swapfile1

remove it
rm /media/DC0C1CAB0C1C82A6/swapfile1

遺憾的是,用這種方式加大的swap space不能用於hibernate,例如,作業系統已使用5GB記憶體(ram、swap space volume及用文章方法加大的swap space三者的總和),電腦不能進入hibernate狀態,只能進入standby狀態,因為swap space volume容量只有0.5GB

實例:

root@debian:/home/debian# dd if=/dev/zero of=/media/DC0C1CAB0C1C82A6/swapfile1 bs=1024 count=26214400
26214400+0 records in
26214400+0 records out
26843545600 bytes (27 GB) copied, 570.604 s, 47.0 MB/s
root@debian:/home/debian# mkswap /media/DC0C1CAB0C1C82A6/swapfile1
Setting up swapspace version 1, size = 26214396 KiB
no label, UUID=3528ea2f-a266-4d38-9454-12aecb06b007
root@debian:/home/debian# swapon /media/DC0C1CAB0C1C82A6/swapfile1
root@debian:/home/debian# dd if=/dev/zero of=/media/4E663CD3663CBD91/swapfile2 bs=1024 count=2097152
2097152+0 records in
2097152+0 records out
2147483648 bytes (2.1 GB) copied, 63.2928 s, 33.9 MB/s
root@debian:/home/debian# mkswap /media/4E663CD3663CBD91/swapfile2
Setting up swapspace version 1, size = 2097148 KiB
no label, UUID=e4a2057a-5d18-4279-a525-fe12bff7ed18
root@debian:/home/debian# swapon /media/4E663CD3663CBD91/swapfile2
root@debian:/home/debian# dd if=/dev/zero of=/swapfile3 bs=1024 count=1048576
1048576+0 records in
1048576+0 records out
1073741824 bytes (1.1 GB) copied, 10.8342 s, 99.1 MB/s
root@debian:/home/debian# mkswap /swapfile3
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=b5bacde2-c6d1-4766-87d8-39649f42a3df
root@debian:/home/debian# swapon /swapfile3

/media/DC0C1CAB0C1C82A6/swapfile1 25GB
/media/4E663CD3663CBD91/swapfile2 2GB
/swapfile3 1GB
原有的swap space volume /dev/sda 0.5GB
total 28.5GB