小知识:Linux添加swap分区的方法

建立一个普通的Linux分区(主分区、逻辑分区均可)

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
fdisk /dev/sdb
Command (m for help): p
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x740e36e3
Device Boot   Start     End   Blocks  Id System
/dev/sdb1       63   4194367   2097152+ 83 Linux
/dev/sdb2     4194368  16777215   6291424  5 Extended
/dev/sdb5     4194431   8388735   2097152+ 83 Linux
/dev/sdb6     8388799  16777215   4194208+ 83 Linux

以sdb6为例,可以看到分区的十六进制编码是83,即普通的Linux分区。

修改分区类型的十六进制编码

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//t命令:改写分区十六进制编码
Command (m for help): t
Partition number (1-6): 6
//L命令可以查看不同分区的十六进制编码,交换分区为82
Hex code (type L to list codes): 82
Changed system type of partition 6 to 82 (Linux swap / Solaris)
Command (m for help): p
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x740e36e3
Device Boot   Start     End   Blocks  Id System
/dev/sdb1       63   4194367   2097152+ 83 Linux
/dev/sdb2     4194368  16777215   6291424  5 Extended
/dev/sdb5     4194431   8388735   2097152+ 83 Linux
/dev/sdb6     8388799  16777215   4194208+ 82 Linux swap / Solaris
//分区表写入磁盘并退出
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

格式化交换分区

?
1
2
3
mkswap /dev/sdb6
Setting up swapspace version 1, size = 4194204 KiB
no label, UUID=40eff2c0-3f6b-440e-bc2a-f71d3d5581a7

启用交换分区

swapon /dev/sdb6

查看交换分区加载状态

?
1
2
3
4
5
free
total    used    free   shared  buffers   cached
Mem:    1030108   160768   869340    264   12040   56188
-/+ buffers/cache:   92540   937568
Swap:   6291352     0  6291352

停用交换分区

swapoff /dev/sdb6

p.s.

不能直接使用mount命令挂载swap分区,因为swap分区是没有挂载点的。

直接修改/etc/fstab配置文件,使系统启动时自动挂载:

?
1
2
3
4
5
6
/dev/sdb6        swap          swap  defaults    0 0
//查看交换分区
swapon -s
Filename        Type    Size  Used  Priority
/dev/sda2                partition  2097148 0  -1
/dev/sdb6                partition  4194204 0  -2

总结

以上所述是小编给大家介绍的Linux添加swap分区的方法,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

原文链接:https://blog.csdn.net/llllllyyy/article/details/81603010

声明: 猿站网有关资源均来自网络搜集与网友提供,任何涉及商业盈利目的的均不得使用,否则产生的一切后果将由您自己承担! 本平台资源仅供个人学习交流、测试使用 所有内容请在下载后24小时内删除,制止非法恶意传播,不对任何下载或转载者造成的危害负任何法律责任!也请大家支持、购置正版! 。本站一律禁止以任何方式发布或转载任何违法的相关信息访客发现请向站长举报,会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。本网站的资源部分来源于网络,如有侵权烦请发送邮件至:2697268773@qq.com进行处理。
建站知识

小知识:Linux分区格式化的命令

2023-3-23 7:45:08

建站知识

小知识:linux磁盘管理知识汇总

2023-3-23 8:10:05

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索