新建swap分区的规划、挂载和自动挂载示例
注:来自Linux系统管理_磁盘分区和格式化的扩展
Linux系统管理_磁盘分区和格式化:http://murongqingqqq.blog.51cto.com/2902694/1361918
思路:
第一步:首先查看当前swap分区的大小:free -m
第二步:新建磁盘分区指定状态为82,即为swap分区格式:fdisk命令
第三步:重读磁盘分区:partprobe命令
第四步:格式化swap分区:mkswap命令
第五步:手动挂载和卸载swap分区:swapon/off
第六步:设置开机自动挂载swap分区:swapon -a
具体操作:
第一步:首先查看当前swap分区的大小:free -m
[root@localhost ~]# free -m total used free shared buffers cached Mem: -/+ buffers/cache: Swap: [root@localhost ~]# fdisk -l /dev/sda Disk /dev/sda: 64.4 GB, bytes heads, sectors/track, cylinders Units = cylinders of * = bytes Device Boot Start End Blocks Id System /dev/sda1 * Linux /dev/sda2 Linux /dev/sda3 + Linux /dev/sda4 Extended /dev/sda5 Linux swap / Solaris
第二步:新建磁盘分区指定状态为82,即为swap分区格式:fdisk命令
[root@localhost ~]# fdisk /dev/sda The number of cylinders for this disk is set to . There is nothing wrong with that, but this is larger than , and could in certain setups cause problems with: ) software that runs at boot time (e.g., old versions of LILO) ) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/ FDISK) Command (m for help): n First cylinder (-, default ): Using default value Last cylinder or +size or +sizeM or +sizeK (-, default ): +1G Command (m for help): p Disk /dev/sda: 64.4 GB, bytes heads, sectors/track, cylinders Units = cylinders of * = bytes Device Boot Start End Blocks Id System /dev/sda1 * Linux /dev/sda2 Linux /dev/sda3 + Linux /dev/sda4 Extended /dev/sda5 Linux swap / Solaris /dev/sda6 Linux Command (m for help): t Partition number (-): Hex code (type L to list codes): Changed system type of partition to (Linux swap / Solaris) Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error : 设备或资源忙. The kernel still uses the old table. The new table will be used at the next reboot. Syncing disks. [root@localhost ~]# ls /dev/sd* /dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sda4 /dev/sda5
第三步:重读磁盘分区:partprobe命令
[root@localhost ~]# partprobe [root@localhost ~]# ls /dev/sd* /dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sda4 /dev/sda5 /dev/sda6
第四步:格式化swap分区:mkswap命令
[root@localhost ~]# mkswap /dev/sda6 Setting up swapspace version , size = kB
第五步:手动挂载和卸载swap分区:swapon/off
[root@localhost ~]# free -m total used free shared buffers cached Mem: -/+ buffers/cache: Swap: [root@localhost ~]# swapon /dev/sda6 [root@localhost ~]# free -m total used free shared buffers cached Mem: -/+ buffers/cache: Swap: [root@localhost ~]# swapon -s //查看都有哪些交换分区挂载 Filename Type Size Used Priority /dev/sda5 partition - /dev/sda6 partition - [root@localhost ~]# swapoff /dev/sda6 //卸载swap分区 [root@localhost ~]# swapon -s Filename Type Size Used Priority /dev/sda5 partition -
第六步:设置开机自动挂载swap分区
[root@localhost ~]# cat /etc/fstab LABEL=/ / ext3 defaults LABEL=/data /data ext3 defaults LABEL=/boot /boot ext3 defaults tmpfs /dev/shm tmpfs defaults devpts /dev/pts devpts gid=,mode= sysfs /sys sysfs defaults proc /proc proc defaults LABEL=SWAP-sda5 swap swap defaults [root@localhost ~]# vim /etc/fstab //编辑/etc/fstab文件,增加下面内容 [root@localhost ~]# cat /etc/fstab | grep sda6 //将下面的信息添加到/etc/fstab文件 /dev/sda6 swap swap defaults [root@localhost ~]# swapon -s Filename Type Size Used Priority /dev/sda5 partition - [root@localhost ~]# swapon -a //用swapon -a来重读/etc/fstab文件,使新swap分区挂载 [root@localhost ~]# swapon -s //再次用swapon -s查看的时候,新的swap分区sda6成功挂载 Filename Type Size Used Priority /dev/sda5 partition - /dev/sda6 partition - [root@localhost ~]#
扩展:swap分区开机自动挂载的第二种方式:
第一步:修改/etc/rc.d/rc.local文件
第二步:将swapon /dev/sda6写入这个脚本当中,那么开机就可以自动挂载交换分区/dev/sda6了!!!
注:用swapon -a和reboot命令来实现重读/etc/fstab文件,实现开机自动挂载。
普通分区重读/etc/fstab文件的时候用mount -a,swap分区重读/etc/fstab文件的时候,
使用swapon -a
新建swap分区的规划、挂载和自动挂载示例的更多相关文章
- 新建swap分区
1.在一块新盘上创建一个主分区,大小为1G大小. 2.将该硬盘数据变更为82(swap),并进行保存 3.查看是否已经将新建分区更改成了swap分区 4.将/dev/sdb2的标签设置为swap-sd ...
- RHEL6p5下ntfs分区的挂载及自动挂载
No.1: #uname -a //查看你的Linux内核版本的命令 No.2:去http://www.atrpms.net/dist/el5/fuse/下载与内核接近的三个东西 fuse-libs- ...
- Ubuntu 新建swap分区及启用
个人电脑配置:500G机械硬盘+16G NGFF SSD+8G Physical Memory 之前安装Ubuntu16.04,默认装到NGFF的SSD里,/和swap分区一共才16G,于是删除swa ...
- 实现nfs持久挂载+autofs自动挂载
实验环境: 两台主机 node4:192.168.37.44 NFS服务器 node2:192.168.37.22 客户端 在nfs服务器,先安装nfs和rpcbind [root@node4 fen ...
- 为linux扩展swap分区
1.查看当前swap分区使用情况 [root@localhost ~]# swapon -s Filename Type Size Used Priority /dev/sda2 ...
- 第8章 文件系统管理(2)_挂载、fdisk分区及分配swap分区
3. fdisk分区 3.1 fdisk命令分区过程 (1)添加新硬盘 (2)查看新硬盘#fdisk –l (3)使用fdisk命令分区:#fdisk /dev/sdb Fdisk交互指令说明 命令 ...
- 给虚拟机添加新硬盘并分区,fdisk查看分区,分区,重新读取分区表信息partprobe,格式化,挂载,查看分区挂载信息,自动挂载文件/etc/fstab,/etc/fstab文件错误导致重启崩溃后的修复
1.虚拟机关机断电 2.添加硬盘 2.开机 3.fdisk -l查看刚才新添加的硬盘 [root@localhost ~]# fdisk -l 磁盘 /dev/sda:21.5 GB, 2147483 ...
- swap分区的扩展
Linux中Swap(即:交换分区),类似于Windows的虚拟内存,就是当内存不足的时候,把一部分硬盘空间虚拟成内存使用,从而解决内存容量不足的情况.swap分区在非高内存的服务器上必不可少,但是s ...
- 分配swap分区
1.free命令 用来查看swap分区的使用情况[root@localhost ~]#free#查看内存与swap分区使用状况◆cached(缓存):是指把读取出来的数据保存在内存当中,当再次 读取时 ...
随机推荐
- 设计模式java实现合集
http://www.cnblogs.com/maowang1991/archive/2013/04/15/3023236.html 桥接模式:http://blog.csdn.net/jason05 ...
- 命令行分析组件IKende.CLI
IKende.CLI是一款开源的命令行分解组件,它可以简地把命令行字符转换成命令对象.在编写CLI应用的时候经常要对命令字符进行繁锁的分解和转换工作,而IKende.CLI的存也是为了解决以上问题而产 ...
- Chapter 4 Invitations——14
"Hi, Bella." “你好,Bella” "What's up?" I said as I was unlocking the door. “怎么了?” ...
- 第48章 UserInfo端点(UserInfo Endpoint) - Identity Server 4 中文文档(v1.0.0)
UserInfo端点可用于检索有关用户的身份信息(请参阅规范). 调用者需要发送代表用户的有效访问令牌.根据授予的范围,UserInfo端点将返回映射的声明(至少需要openid作用域). 示例 GE ...
- C# asp.net mvc 通过 HttpClient 访问 Web_API
//MVC 具体方法 //API地址 通过 WebConfig配置 private static string apiAdds = ConfigurationManager.AppSettings[& ...
- Java集合类:"随机访问" 的RandomAccess接口
引出RandomAccess接口 如果我们用Java做开发的话,最常用的容器之一就是List集合了,而List集合中用的较多的就是ArrayList 和 LinkedList 两个类,这两者也常被用来 ...
- mybatis报错:Caused by: java.lang.IllegalArgumentException: Caches collection already contains value for com.crm.dao.PaperUserMapper
一.问题 eclipse启动时报下面的错误: Caused by: java.lang.IllegalArgumentException: Caches collection already cont ...
- Android Studio 学习(七)通知
导入support- -v4 1.进入 file-project structure 2.左边选择app 3.右边选择dependencies 4.左下角可以看到一个加号,点击选择Library de ...
- JavaScript知识点 思维导图
javascript变量 javascript数据类型 javascript运算符 javascript流程语句 javascript数组 javascript字符串函数 javascript函数基础 ...
- Shell基础命令(二)
查看Linux的发行版 cat /etc/redhat-release cat /etc/os-release 查看系统用户的id信息 id 用户名 id root id 创建系统用户的命令 user ...