免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1014 | 回复: 0
打印 上一主题 下一主题

add swap in linux [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-05-27 15:29 |只看该作者 |倒序浏览

Adding Swap Space Sometimes it is necessary to add more swap space after installation. For example, you may upgrade the amount of RAM in your system from 64 MB to 128 MB, but there is only 128 MB of swap space. It might be advantageous to increase the amount of swap space to 256 MB if you perform memory-intense operations or run applications that require a large amount of memory. You have two options: add a swap partition or add a swap file. It is recommended that you add a swap partition, but sometimes that is not easy if you do not have any free space available. To add a swap partition (assuming /dev/hdb2 is the swap 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 easiest way to achieve this it to boot your system in rescue mode. Refer to Chapter 8 for instructions on booting into rescue mode. When prompted to mount the filesystem, 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 or fdisk. Using parted is easier than fdisk; thus, only parted will be explained. To create a swap partition with 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, type mkpartfs part-type linux-swap start end, where part-type is one of primary, extended, or logical, start is the starting point of the partition, and end is the end point of the partition.  Warning   Changes take place immediately; be careful when you type.   Exit parted by typing quit. Now that you have the swap partition, use the command mkswap to setup the swap partition. At a shell prompt as root, type the following: mkswap /dev/hdb2   To enable the swap partition immediately, type the following command: swapon /dev/hdb2   To enable it at boot time, edit /etc/fstab to include: /dev/hdb2               swap                    swap    defaults        0 0   The next time the system boots, it will enable the new swap partition. After adding the new swap partition and enabling it, make sure 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 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   add 8G: dd if=/dev/zero of=/swapfile2 bs=1024 count=8388608Setup the swap file with the command: mkswap /swapfile   To enable the swap file immediately but not automatically at boot time: swapon /swapfile   To enable it at boot time, edit /etc/fstab to include: /swapfile               swap                    swap    defaults        0 0   The next time the system boots, it will enable the new swap file. After adding the new swap file and enabling it, make sure it is enabled by viewing the output of the command cat /proc/swaps or free.  
[ Back ]



本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/43994/showart_708807.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP