注:来自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分区的规划、挂载和自动挂载示例的更多相关文章

  1. 新建swap分区

    1.在一块新盘上创建一个主分区,大小为1G大小. 2.将该硬盘数据变更为82(swap),并进行保存 3.查看是否已经将新建分区更改成了swap分区 4.将/dev/sdb2的标签设置为swap-sd ...

  2. RHEL6p5下ntfs分区的挂载及自动挂载

    No.1: #uname -a //查看你的Linux内核版本的命令 No.2:去http://www.atrpms.net/dist/el5/fuse/下载与内核接近的三个东西 fuse-libs- ...

  3. Ubuntu 新建swap分区及启用

    个人电脑配置:500G机械硬盘+16G NGFF SSD+8G Physical Memory 之前安装Ubuntu16.04,默认装到NGFF的SSD里,/和swap分区一共才16G,于是删除swa ...

  4. 实现nfs持久挂载+autofs自动挂载

    实验环境: 两台主机 node4:192.168.37.44 NFS服务器 node2:192.168.37.22 客户端 在nfs服务器,先安装nfs和rpcbind [root@node4 fen ...

  5. 为linux扩展swap分区

    1.查看当前swap分区使用情况 [root@localhost ~]# swapon -s Filename Type Size Used Priority /dev/sda2            ...

  6. 第8章 文件系统管理(2)_挂载、fdisk分区及分配swap分区

    3. fdisk分区 3.1 fdisk命令分区过程 (1)添加新硬盘 (2)查看新硬盘#fdisk –l (3)使用fdisk命令分区:#fdisk /dev/sdb Fdisk交互指令说明 命令 ...

  7. 给虚拟机添加新硬盘并分区,fdisk查看分区,分区,重新读取分区表信息partprobe,格式化,挂载,查看分区挂载信息,自动挂载文件/etc/fstab,/etc/fstab文件错误导致重启崩溃后的修复

    1.虚拟机关机断电 2.添加硬盘 2.开机 3.fdisk -l查看刚才新添加的硬盘 [root@localhost ~]# fdisk -l 磁盘 /dev/sda:21.5 GB, 2147483 ...

  8. swap分区的扩展

    Linux中Swap(即:交换分区),类似于Windows的虚拟内存,就是当内存不足的时候,把一部分硬盘空间虚拟成内存使用,从而解决内存容量不足的情况.swap分区在非高内存的服务器上必不可少,但是s ...

  9. 分配swap分区

    1.free命令 用来查看swap分区的使用情况[root@localhost ~]#free#查看内存与swap分区使用状况◆cached(缓存):是指把读取出来的数据保存在内存当中,当再次 读取时 ...

随机推荐

  1. 在Mac上使用vs-code快速上手c语言学习(入门文,老鸟退散)

    天下事,合久必分.分久必合,你肯定想不到当你逃离到Mac平台这么多年之后,有一天你会再用微软的产品来写代码 :) 其实微软的产品虽然用户体验总是做不到最好,但整体上的确拉低了行业的进入门槛,对于编程也 ...

  2. Spring 中 SQL 的存储过程

    SimpleJdbcCall 类可以被用于调用一个包含 IN 和 OUT 参数的存储过程.你可以在处理任何一个 RDBMS 时使用这个方法,就像 Apache Derby, DB2, MySQL, M ...

  3. angr初使用(1)

    angr是早在几年前就出来了的一款很好用的工具,如今也出了docker,所以想直接安个docker来跑一跑. docker pull angr/angr .下载下来以后,进入docker ,这时并没有 ...

  4. 再谈包访问权限 子类为何不能使用父类protected方法

    可见范围 权限的含义应该理解为控制范围,要把它理解成一个限制范围的空间,更为准确的说叫做可见范围 访问控制的等级,从最大权限到最小权限依次为:public.protected.包访问权限(没有关键词) ...

  5. iframe跨域通信实战

    "长时间不写文章,开头的方式总是那么出奇的相似",最近很忙,好久没写博客了啊(是不是?). 更换工作已经有三个月有余,这段三个月把过去三年没加过的班都加了一次.收获挺多,发现的问题 ...

  6. 第49章 令牌端点(Token Endpoint) - Identity Server 4 中文文档(v1.0.0)

    令牌端点可用于以编程方式请求令牌.它支持password,authorization_code,client_credentials,refresh_token和urn:ietf:params:oau ...

  7. 第35章 秘密(secrets) - Identity Server 4 中文文档(v1.0.0)

    在某些情况下,客户端需要使用身份服务器进行身份验证,例如 在令牌端点请求令牌的机密应用程序(也称为客户端) API在内省端点验证引用令牌 为此,您可以将秘密列表分配给客户端或API资源. 秘密解析和验 ...

  8. .net core mvc 区域路由设置(配置)

    写博客原因:添加了区域(用作后台)后,报错: An unhandled exception occurred while processing the request.AmbiguousActionE ...

  9. Java Scanner nextLine方法跳过

    问题描述 Scanner使用了nextInt方法的时候,如果接下来要使用nextLine,会获取不到内容 原因 因为Scanner读取用户输入数据,是先判断缓冲区是否含有数据,没有则接收用户输入的数据 ...

  10. 【Spring】Autowired原理及与Resource注解区别

    Autowired注解 Autowired顾名思义,表示自动注入,如下是Autowired注解的源代码: @Target({ElementType.CONSTRUCTOR, ElementType.M ...