注:来自Linux系统管理_磁盘分区和格式化的扩展
思路:
第一步:首先查看当前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.在一块新盘上创建一个主分区,大小为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 ...
为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交互指令说明 命令 ...
swap分区的扩展
Linux中Swap(即:交换分区),类似于Windows的虚拟内存,就是当内存不足的时候,把一部分硬盘空间虚拟成内存使用,从而解决内存容量不足的情况.swap分区在非高内存的服务器上必不可少,但是s ...
分配swap分区
1.free命令 用来查看swap分区的使用情况[root@localhost ~]#free#查看内存与swap分区使用状况◆cached(缓存):是指把读取出来的数据保存在内存当中,当再次 读取时 ...
配置Linux自动挂载
使用mount命令来挂载硬件,在Linux重启后这些挂载信息会丢失,因此对应磁盘这类硬件,需要配置自动挂载来保证系统重启时进行自动挂载. 自动挂载信息保存在文件/etc/fstab文件中 查看该文件的 ...
随机推荐
jQ获取浏览器window的高宽
Window 对象Window 对象表示浏览器中打开的窗口.JavaScript 层级中的顶层对象,表示浏览器窗口.如果文档包含框架(frame 或 iframe 标签),浏览器会为 HTML 文档创 ...
在64位windows 7上安装汇编调试工具debug.exe的方法
最近我在研究汇编,书中介绍的调试工具还是基于WinXP 32bit时代中自带debug.exe进行调试,但是64bit的Windows XP.Vista.Win7.Win8都已经不自带这个工具了,网上 ...
Python 计算已经过去多少个周末
def weekends_between(d1,d2): days_between = (d2-d1).days weekends, leftover = divmod(days_between,7) ...
在项目里交叉使用Swift和OC
Swift and Objective-C in the Same Project 在项目里交叉使用Swift和OC Swift与OC的兼容性使得你能够在项目里使用Swift+OC的方式编写应用程序, ...
Oracle实战笔记(第二天)
导读 今日主要内容:表管理.表操作(增删改查).表查询(简单查询&复杂查询).创建数据库. 一.表管理 1.表命名规范 必须以字母开头: 长度不能超过30个字符: 不能使用Oracle保留字: ...
hibernate监听器的应用
这里是我看到的一个hibernate监听器的简单实现供参考 http://www.360doc.com/content/14/0623/11/8072791_389034447.shtml 设计思路 ...
Compass 更智能的搜索引擎(2)--进阶
经过了Compass 更智能的搜索引擎(1)–入门的学习,想必对于Compass的使用有了更深的认识了吧.下面谈点更加切合实际开发的东西.那就是CRUD. 面向对象的分页 dao层实现 代码释义 优点 ...
Asp.Net Core Web应用程序—探索
前言 作为一个Windows系统下的开发者,我对于Core的使用机会几乎为0,但是考虑到微软的战略规划,我觉得,Core还是有先了解起来的必要. 因为,目前微软已经搞出了两个框架了,一个是Net标准( ...
AutoCAD神器! AutoCAD自动切换中英文输入法插件(ZDSRF)
AutoCAD神器! AutoCAD自动切换中英文输入法插件 (一)功能特点: CAD命令中只能输入英文字符,不能输入中文,在文字编辑.文字输入.尺寸编辑中经常需要输入中文,此时就需要频繁的切换输入法 ...
CODEFORCES掉RATING记 #2
比赛:Codeforces Round #425 (Div. 2) 时间:2017.7.25晚 先orz zjt rank4 一场加300rating A:傻题,判断\(\lfloor\frac{n} ...