怎样添加、删除、移动Linux下的 Swap 空间

 
怎样添加、删除、移动Linux下的 Swap 空间
Redhat Linux Space ,add ,delete and move(如果操作步骤,看红颜色的部分就可以了,详细可以看Redhat相关的指南书)
?
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):

1.?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 Red Hat Linux Manuals 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.

2. ?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.

3.?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

4.?To enable the swap partition immediately, type the following command:
swapon /dev/hdb2

5.?To enable it at boot time, edit /etc/fstab to include:

/dev/hdb2?????????????? swap??????????????????? swap??? defaults??????? 0 0

6. ?The next time the system boots, it will enable the new swap partition.

7.?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:

1.?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 .

2.?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


4.?To enable the swap file immediately but not automatically at boot time:
swapon /swapfile


6. ?The next time the system boots, it will enable the new swap file.

7.?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. ?
?
Removing Swap Space

To remove a swap partition:
1.?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 Red Hat Linux Manuals 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.

2. ?At a shell prompt as root, execute the following command to make sure the swap partition is disabled (where /dev/hdb2 is the swap partition):
swapoff /dev/hdb2

3.? Remove its entry from /etc/fstab.

4.?Remove the partition using parted or fdisk. Only parted will be discussed. To remove the 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 determine the minor number of the swap partition you wish to delete.
?*?At the (parted) prompt, type rm MINOR, where MINOR is the minor number of the partition you want to remove.
?
Warning
??Changes take effect immediately; you must type the correct minor number.
?*?Type quit to exit parted.

To remove a swap file:
1.?At a shell prompt as root, execute the following command to disable the swap file (where /swapfile is the swap file):
swapoff /swapfile
2.?Remove its entry from /etc/fstab.
3.?Remove the actual file:
rm /swapfile
?
Moving Swap Space
To move swap space from one location to another, follow the steps for removing swap space, and then follow the steps for adding swap space.
5.?To enable it at boot time, edit /etc/fstab to include:
/swapfile?????????????? swap??????????????????? swap??? defaults??????? 0 0
3.?Setup the swap file with the command:
mkswap /swapfile
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Re: 《 Linux磁盘与文件系统管理命令 》   ---------------------------------------内容提要: 01/16)命令fdisk           :磁盘分区工具02/16)命令partprobe  :更新内核的硬盘分区表信息(即分区即刻生效)03/16)命令 tune2fs     :调整 ext2/ext3/ext4 文件系统参数04/16)命令 parted       :磁盘分区工具(大小通吃)05/16)命令 mkfs          :创建Linux文件系统06/16)命令 dumpe2fs :导出ext2/ext3/ext4文件系统信息07/16)命令 resize2fs   :调整ext2/ext3/ext4文件系统大小08/16)命令 fsck           :检查并修复Linux文件系统09/16)命令 dd             :转换或复制文件10/16)命令 mount       :挂载文件系统11/16)命令 umount     :卸载文件系统12/16)命令 df              :报告文件系统磁盘空间的使用情况13/16)命令 mkswap    :创建交换分区14/16)命令 swapon     :激活交换分区15/16)命令 swapoff     :关闭交换分区16/16)命令 sync           :刷新文件系统缓冲区17/17)附录                   :NFS 网络文件服务器到安装;客户端的挂载 -t nfs;及新分区的权限测试  本人在教学和实战过程中发现,即便是有一定运维经验的人,可能已经能够搭建一定复杂度的Linux架构,但是在来来回回的具体操作中,还是体现出CLI(命令界面)功底不够扎实,甚至操作的非常‘拙’、处处露‘怯’。 对一个士兵来说,枪就是他的武器,对于一个程序员来说,各种library(工具库)就是他的武器;而对于Linux运维人员来说,无疑命令行工具CLI(命令界面)就是他们的武器;高手和小白之间的差距往往就体现在对于这些“武器”的掌握和熟练程度上。有时候一个参数就能够解决的事情,小白们可能要写一个复杂的Shell脚本才能搞定,这就是对CLI(命令界面)没有理解参悟透彻导致。 研磨每一个命令就是擦拭手中的作战武器,平时不保养不理解,等到作战的时候,一定不能够将手中的武器发挥到最好,所以我们要平心、静气和专注,甘坐冷板凳一段时间,才能练就一身非凡的内功! 本教程从实战出发,结合当下流行或最新的Linux(v6/7/8 版本)同时演示,将命令行结合到解决企业实战问题中来,体现出教学注重实战的务实精神,希望从事或未来从事运维的同学,能够认真仔细的学完Linux核心命令的整套课程。 本课程系列将逐步推出,看看我教学的进度和您学习的步伐,孰占鳌头! 注:关于教学环境搭建,可以参考本人其它课程系列,本教学中就不再赘述! 《参透 VMware 桌面级虚拟化》 《在虚拟机中安装模版机(包括应用软件等)》 《SecureCRT 连接 GNS3/Linux 的安全精密工具》 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值