搜索
查看: 5156|回复: 0

Linux-添加swap分区

[复制链接]

7

主题

6

回帖

29

积分

新手开车

积分
29
发表于 2018-8-13 17:50:10 来自手机 | 显示全部楼层 |阅读模式 来自 甘肃
建立一个普通的Linux分区(主分区、逻辑分区均可)

[pre]
fdisk /dev/sdb
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
[/pre]

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

修改分区类型的十六进制编码
[pre]
//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.
[/pre]

格式化交换分区
[pre]
mkswap /dev/sdb6
Setting up swapspace version 1, size = 4194204 KiB
no label, UUID=40eff2c0-3f6b-440e-bc2a-f71d3d5581a7
[/pre]

启用交换分区
[pre]
swapon /dev/sdb6
[/pre]

查看交换分区加载状态
[pre]
free
1
             total       used       free     shared    buffers     cached
Mem:       1030108     160768     869340        264      12040      56188
-/+ buffers/cache:      92540     937568
Swap:      6291352          0    6291352
[/pre]
停用交换分区
[pre]
swapoff /dev/sdb6
[/pre]
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表