Adding swap space on linux system
2016-02-14 23:44
681 查看
2.2. Adding Swap Space
Sometimes it is necessary to add more swap space after installation. Forexample, you may upgrade the amount of RAM in your system from 64 MB to128 MB, but there is only 128 MB of swap space. It might be advantageousto increase the amount of swap space to256 MB if you performmemory-intense operations or run applications that require a largeamount of memory.
You have two options: add a swap partition or add a swap file. It isrecommended that you add a swap partition, but that can be difficult ifyou do not have any free space available.
To add a swap partition (assuming /dev/hdb2 is theswap partition you want to add):
The hard drive can not be in use (partitions can not be mounted, and swap space can not be enabled). The partition table should not be modified while in use because the kernel may not properly recognize the changes. Data could be overwitten by writing to
the wrong partition because the partition table and partitions mounted do not match. The easiest way to achieve this is to boot your system in rescue mode. Refer to
Chapter 11 Basic System Recovery for instructions on booting into rescue mode. When prompted to mount the file system, select
Skip.
Alternately, if the drive does not contain any partitions in use, you can unmount them and turn off all the swap space on the hard drive with the
swapoff command.
Create the swap partition using parted:
At a shell prompt as root, type the command parted /dev/hdb, where /dev/hdb is the device name for the hard drive with free space.
At the (parted) prompt, type print to view the existing partitions and the amount of free space. The start and end values are in megabytes. Determine how much free space is on the hard drive and how much
you want to allocate for a new swap partition.
At the (parted) prompt, typemkpartfs
part-typelinux-swap startend, wherepart-type is one of primary,extended, or logical,
start is thestarting point of the partition, andend is the end point of thepartition.
![]() | Warning |
---|---|
Changes take place immediately; be careful when you type. |
Now that you have created the swap partition, use the command
mkswap to setup the swap partition. At a shell prompt as root, type the following:
mkswap /dev/hdb2 |
swapon /dev/hdb2 |
/dev/hdb2 swap swap defaults 0 0 |
After adding the new swap partition and enabling it, verify it is enabled by viewing the output of the command
cat /proc/swaps or free.
To add a swap file:
Determine the size of the new swap file in megabytes and multiple by 1024 to determine the block size. For example, the block size of a 64 MB swap file is 65536.
At a shell prompt as root, type the following command with
count being equal to the desired block size:
dd if=/dev/zero of=/swapfile bs=1024 count=65536 |
mkswap /swapfile |
swapon /swapfile |
/swapfile swap swap defaults 0 0 |
After adding the new swap file and enabling it, verify it is enabled by viewing the output of the command
cat /proc/swaps or free.
相关文章推荐
- linux xargs详解
- Linux 学习树之基础20160214
- Linux运维初级教程(三)文件及目录权限
- Linux运维初级教程(二)账户与安全
- Centos7.0 安装VNC后链接出现黑屏
- 在GNU/Linux下使用Lilypond排版简谱
- Linux下mysql数据库的数据导入导出
- linux下awk的关联数组
- Linux 下mysql常用命令--启动、停止、重启
- Understand for Linux安装方法
- Linux中du命令:同样可以查看使用的空间,但是与df有不同
- Linux学习分享:月薪3K到13K的距离有多远?
- Linux中df命令:用来检查linux服务器的文件系统的磁盘空间占用情况
- 10K入职linux运维岗位小伙伴感谢信及面试经历分享
- linux下I2C驱动
- linux php7安装
- linux编译器之Vim入门
- linux下的source命令
- linux 技巧:使用 screen 管理你的远程会话
- (二)利用processing绘制自定义图像