新建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 -mtotal used free shared buffers cachedMem: 495 285 209 0 18 167-/+ buffers/cache: 99 395Swap: 2047 0 2047[root@localhost ~]# fdisk -l /dev/sdaDisk /dev/sda: 64.4 GB, 64424509440 bytes255 heads, 63 sectors/track, 7832 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDevice Boot Start End Blocks Id System/dev/sda1 * 1 25 200781 83 Linux/dev/sda2 26 2575 20482875 83 Linux/dev/sda3 2576 3850 10241437+ 83 Linux/dev/sda4 3851 7832 31985415 5 Extended/dev/sda5 3851 4111 2096451 82 Linux swap / Solaris
第二步:新建磁盘分区指定状态为82,即为swap分区格式:fdisk命令
[root@localhost ~]# fdisk /dev/sdaThe number of cylinders for this disk is set to 7832.There is nothing wrong with that, but this is larger than 1024,and could in certain setups cause problems with:1) software that runs at boot time (e.g., old versions of LILO)2) booting and partitioning software from other OSs(e.g., DOS FDISK, OS/2 FDISK)Command (m for help): nFirst cylinder (4112-7832, default 4112):Using default value 4112Last cylinder or +size or +sizeM or +sizeK (4112-7832, default 7832): +1GCommand (m for help): pDisk /dev/sda: 64.4 GB, 64424509440 bytes255 heads, 63 sectors/track, 7832 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDevice Boot Start End Blocks Id System/dev/sda1 * 1 25 200781 83 Linux/dev/sda2 26 2575 20482875 83 Linux/dev/sda3 2576 3850 10241437+ 83 Linux/dev/sda4 3851 7832 31985415 5 Extended/dev/sda5 3851 4111 2096451 82 Linux swap / Solaris/dev/sda6 4112 4234 987966 83 LinuxCommand (m for help): tPartition number (1-6): 6Hex code (type L to list codes): 82Changed system type of partition 6 to 82 (Linux swap / Solaris)Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.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/sda6Setting up swapspace version 1, size = 1011671 kB
第五步:手动挂载和卸载swap分区:swapon/off
[root@localhost ~]# free -mtotal used free shared buffers cachedMem: 495 287 208 0 18 168-/+ buffers/cache: 99 395Swap: 2047 0 2047[root@localhost ~]# swapon /dev/sda6[root@localhost ~]# free -mtotal used free shared buffers cachedMem: 495 287 207 0 18 168-/+ buffers/cache: 100 395Swap: 3012 0 3012[root@localhost ~]# swapon -s //查看都有哪些交换分区挂载 Filename Type Size Used Priority/dev/sda5 partition 2096440 0 -1/dev/sda6 partition 987956 0 -3[root@localhost ~]# swapoff /dev/sda6 //卸载swap分区 [root@localhost ~]# swapon -sFilename Type Size Used Priority/dev/sda5 partition 2096440 0 -1
第六步:设置开机自动挂载swap分区
[root@localhost ~]# cat /etc/fstabLABEL=/ / ext3 defaults 1 1LABEL=/data /data ext3 defaults 1 2LABEL=/boot /boot ext3 defaults 1 2tmpfs /dev/shm tmpfs defaults 0 0devpts /dev/pts devpts gid=5,mode=620 0 0sysfs /sys sysfs defaults 0 0proc /proc proc defaults 0 0LABEL=SWAP-sda5 swap swap defaults 0 0[root@localhost ~]# vim /etc/fstab //编辑/etc/fstab文件,增加下面内容 [root@localhost ~]# cat /etc/fstab | grep sda6 //将下面的信息添加到/etc/fstab文件/dev/sda6 swap swap defaults 0 0[root@localhost ~]# swapon -sFilename Type Size Used Priority/dev/sda5 partition 2096440 0 -1[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 2096440 0 -1/dev/sda6 partition 1959888 0 -5[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
转载于:https://www.cnblogs.com/felixzh/p/9238279.html
新建swap分区的规划、挂载和自动挂载示例相关推荐
- 【Linux】Linux的挂载原理 |MOUNT|挂载NAS|自动挂载
目录 零.常用挂载命令 一.Linux的挂载原理 1.概念 2.举例 3.补充 4.LINUX文件结构和WINDOWS的不同 5.挂载文件系统 6.mount结构与原理 7.mount 和umount ...
- linux自动挂载ntfs分区,Ubuntu 12.04 开机自动挂载ntfs分区
在新的64位Ubuntu 12.04版本中 ntfs写入支持程序 不能正常运行.所以想Ubuntu自动挂载ntfs分区就要手动编辑/etc/fstab 文件. /etc/fstab包含了挂在磁盘的必 ...
- linux7硬盘自动挂载,Centos7自动挂载硬盘参数详解
UUID=5b69ece8-4e15-4658-9857-8a60efbbb0fe / ext4 defaults 1 1 第一列:分区名(设备ID) 如果磁盘是SCSI/STAT接口,且有多个磁盘, ...
- 自动挂载ios_Ubuntu自动挂载iso文件 | 学步园
在Ubuntu10.10上通过Crossover装了一个Longman5,因为时.iso文件安装到,所以每次启动都要把.iso文件挂载上才能使用. $ sudo mount -o loop -t is ...
- oracle开机自动挂载,开机自动挂载 通过SSHFS/SHFS挂载远程文件
大 家可能知道并用过在linux上通过smb,nfs来进行远程文件系统的共享,可是大家是否知道我们现在还可以通过ssh来进行远程文件系统的共享.你可 能会说这有什么希奇的,不就是ssh远程登录嘛,再不 ...
- centos8共享文件夹挂载_MacOS自动挂载nfs服务器共享目录
这是一篇关于如何使用MacOS automount命令,来自动挂载远程文件系统的技巧.需要读者对OS X命令行有一定了解. 一.为什么要使用automount呢 我们看看鸟哥是怎么描述的: " ...
- 为linux扩展swap分区
1.查看当前swap分区使用情况 [root@localhost ~]# swapon -s Filename Type Size Used Priority /dev/sda2 ...
- 扩大swap分区的方法
linux下oracle部署时,对swap内存较高.若磁盘无空间创建swap分区时,可采用通过文件转化为swap分区的形式. 可通过以下6个步骤创建并检测 1.查看已有swap大小 2.创建swap文 ...
- linux如何挂载swap分区,Linux挂载新硬盘和创建Swap分区的方法
Liunx添加新硬盘其实和Windows的操作一样,但一个是图形化操作,另一个是命令行操作,不过步骤是一样,下面就动手演示和讲解 Linux挂载新硬盘 1.查看硬盘信息 命令:fdisk -l [ro ...
最新文章
- WdOS系统上samba服务的基本配置
- 【JavaScript】jQuery绑定事件
- sdut 1466 双向队列
- WireShark过滤器选项
- 【常用算法总结——最短路径四种方法】
- 现在为什么面对着人多,陌生人的时候会紧张?
- Netweaver的传输机制和SAP Cloud for Customer
- python里split_python中split()的用法
- ASP.NET Application,Session,Cookie和ViewState等对象用法和区别
- ajax中sy,黑马eesy_15 Vue:vue语法和生命周期与ajax异步请求
- visio 2013 破解工具 - KMSpico
- java种语言包在线翻译_Java 实现在线翻译功能 调用微软Bing API
- 网格搜索算法与K折交叉验证
- C++ advanced(4)make function and SFINAE
- Java笔试题含答案
- 一篇文章构建你的 NodeJS 知识体系(W字长文)
- html中的keygen元素
- 数据库将表的字段值查询为字段名
- nodejs+express搭建小程序后台服务器
- 类型转换、强制类型转换