Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set swap in ubuntu

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

In this issue, the editor will bring you about how to set up swap in ubuntu. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Add swap

Use free to view swap partition size

Free-m

Create a swap folder

Mkdir swapcd swapsudo dd if=/dev/zero of=swapfile bs=1024 count=100000

The size of count corresponds to the size of swap. As shown in the above code, count=100000 is about 100m.

Note: when setting the count value, it should be noted that if you set the swap size to exceed the hard disk size, it will cause the graphical interface of the virtual machine ubuntu to be unable to enter after the restart.

Convert the generated file to a swap file

Mkswap swapfile

Activate the swap file

Swapon swapfile

If you need to start automatically every time you enter, you need to modify / etc/fstab auto mount:

Add to the file

/ disk2/swap swap defaults 0 0

(because I created the swap file in disk2, the path is / disk2/swap)

If it does not start automatically, then after each restart, enter the swap folder and activate it with the swapon swapfile command

Check the swap partition size again to make sure that the swap setting is successful

Free-m

Delete swap

Delete the exchange area after you finish using it.

Go to the swap folder and close swap

Cd swapswapoff swapfile

Turn off auto mount (skip this step if / etc/fstab has not been modified)

Vi / etc/fstab

Add # or delete before the previously added statement

Note: if you do not have the permission to modify / etc/fstab, you will be prompted that the file is read-only and cannot be modified. Solution: save with the following statement

: w! Sudo tee%

Delete

Rm-r swapfile

The problems I encountered when configuring:

When setting the swap size, the size of the virtual machine hard disk is exceeded, so that the ubuntu graphical interface of the virtual machine cannot be accessed after restart. The following methods are adopted:

Ctrl+alt+F1 enters text mode

Check the disk space to see if it is unable to enter the graphical interface because the disk space is full

Df-h

Found that the disk space is full and some files need to be deleted.

You can use the rm-r statement to delete some files, or you can delete swap and reconfigure it using the method mentioned above.

The above is the editor for you to share how to set up swap in ubuntu, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report