Ubuntu
Swap File
There are several reasons why you would need swap.
If your system has RAM less than 1 GB, you must use swap as most applications would exhaust the RAM soon.
If your system uses resource heavy applications like video editors, it would be a good idea to use some swap space as your RAM may be exhausted here.
If you use hibernation, then you must add swap because the content of the RAM will be written to the swap partition. This also means that the swap size should be at least the size of RAM.
Avoid strange events like a program going nuts and eating RAM.
How much should be the swap size?
256MB
256MB
512MB
512MB
512MB
1GB
1GB
1GB
2GB
2GB
1GB
3GB
3GB
2GB
5GB
4GB
2GB
6GB
6GB
2GB
8GB
8GB
3GB
11GB
12GB
3GB
15GB
16GB
4GB
20GB
24GB
5GB
29GB
32GB
6GB
38GB
64GB
8GB
72GB
128GB
11GB
139GB
Check swap space in Linux
Show swap file partition path
Make a new swap file
It is recommended to allow only root to read and write to the swap file. You’ll even see warning like “insecure permissions 0644, 0600 suggested” when you try to use this file for swap area.
Do note that the name of the swap file could be anything. If you need multiple swap spaces, you can give it any appropriate name like swap_file_1, swap_file_2 etc. It’s just a file with a predefined size.
Mark the new file as swap space
Your need to tell the Linux system that this file will be used as swap space. You can do that with mkswap tool.
Enable the swap file
Now if you check the swap space, you should see that your Linux system recognizes and uses it as the swap area:
Make the changes permanent
Whatever you have done so far is temporary. Reboot your system and all the changes will disappear.
You can make the changes permanent by adding the newly created swap file to /etc/fstab
file.
It’s always a good idea to make a backup before you make any changes to the /etc/fstab
file.
Now you can add the following line to the end of /etc/fstab
file:
You can do it manually using a command line text editor or you just use the following command:
Now you have everything in place. Your swap file will be used even after you reboot your Linux system.
Adjust swappiness
數值越高代表交換的越頻繁,[0~100] Default: 60
永久化,將 vm.swappiness=25
寫入到 /etc/sysctl.conf
Resizing swap space on Linux
較好的方式先建立另一個新的 swap file 並啟用,在 swap 舊的時,會將資料移過去
如果記憶體有足夠的空間時
Removing swap file in Linux
如果記憶體有足夠的空間時
查詢目前正在使用的 PORT 號
sudo lsof -i -n -P|grep LISTEN sudo netstat -lpn |grep {port}
硬碟效能
hdparm
is a good place to start.
sudo hdparm -v /dev/sda
will give information as well.
dd will give you information on write speed.
If the drive doesn't have a file system (and only then), use of=/dev/sda
.
Otherwise, mount it on /tmp and write then delete the test output file.
更新 hostname
把主機名稱修改成 ubuntu-vm-x64:
sudo hostnamectl set-hostname ubuntu-vm-x64
說用 hostnamectl status
檢查有沒有修改成功:
Daemon 註冊
新增服務檔案
sudo nano /etc/systemd/system/openfortivpn.service
設定
註冊及啟用
查看 log
Last updated