Ubuntu 16.04 extended swap partition

background

The Linux ubuntu system is newly installed, but when the web page Dingding and WeChat are hanging, and a few more web pages are opened, the ubuntu system will crash in one or two hours. no response.

Tried some solutions:

  1. Enter the TTY terminal
    Ctrl+Alt+F1 to enter the TTY1 terminal character interface, enter the user name and password to log in

Enter the top command, find the process that may cause suspended animation, and use the kill command to end the process. Then Ctrl+Alt+F7 to return to the desktop

  1. Directly log out the user
    Ctrl+Alt+F1 to enter the TTY1 terminal character interface, enter the user name and password to log in.

Then execute any of the following commands to log out of the desktop and log in again.

sudo pkill Xorgorsudo restart lightdm

  1. The Low- Level Approach alt + ctrl + Print Screen
    Next comes the action: as you'll see right away, pressing <Alt>+<SysRq> at the same time doesn't work at all! Only a screenshot window will pop up. So, the real approach should be:
  • 1. Extend your left hand, press and hold the <Ctrl>+<Alt> keys at the same time, don't release
    2. Press <SysRq> with your right hand first, don't release your left hand, wait for 1 second
    3. Press R with your right hand, don't let go Release, wait for 1 second
    4. Press E with your right hand, don't let go with your left hand. At this time, all programs including the desktop will be terminated, and you will see a black screen. Wait for a while.
    5. Press I, S, U, B in turn with your right hand, and don't let go of your left hand. Wait a few seconds for each press, and you will find that the information on the screen changes with each press. When you finally press B, the screen displays reset, and your left hand can be released. After a few seconds, the computer will restart safely.

However, the system is indifferent to the commands of the keyboard, so the above three methods have failed, and the computer can only be restarted with the reset key.

After restarting, I searched for related articles about ubuntu crash, and found that there may be no swap partition when installing the system, resulting in the system swap space being too small. In this way, hanging on WeChat for a while will crash chrome, and then crash the system. . After referring to the tutorial, the size of the swap partition has been expanded perfectly, and it will never crash again.

Process

View the current space size

$ free

Create a swap file

$ cd /
$ sudo mkdir swap
$ cd swap/
$ sudo dd if=/dev/zero of=swapfile bs=1M count=2048#创建2G的swap,大小为bs*count
记录了2048+0 的读入
记录了2048+0 的写出
2147483648 bytes (2.1 GB, 2.0 GiB) copied, 4.89824 s, 438 MB/s

Convert the generated file to a Swap file

$ sudo mkswap swapfile
Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
无标签, UUID=ceab0529-be6f-4955-a6c0-fe7380f71954

Activate the Swap file.

$ sudo swapon swapfile
swapon: /swap/swapfile:不安全的权限 0644,建议使用 0600

Set the swap partition to automatically mount at startup

Backup the file /etc/fstab first

$ sudo cp /etc/fstab /etc/fstab.bak
$ echo '/swap/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Check swap space size

$ free
perfect~~

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325810582&siteId=291194637