千家信息网

怎么在Linux中添加swap分区

发表于:2025-02-02 作者:千家信息网编辑
千家信息网最后更新 2025年02月02日,这篇文章给大家介绍怎么在Linux中添加swap分区,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。建立一个普通的Linux分区(主分区、逻辑分区均可)fdisk /dev/sdb
千家信息网最后更新 2025年02月02日怎么在Linux中添加swap分区

这篇文章给大家介绍怎么在Linux中添加swap分区,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

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

fdisk /dev/sdbCommand (m for help): pDisk /dev/sdb: 8589 MB, 8589934592 bytes255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk 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分区。

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

//t命令:改写分区十六进制编码Command (m for help): t Partition number (1-6): 6//L命令可以查看不同分区的十六进制编码,交换分区为82Hex code (type L to list codes): 82Changed system type of partition 6 to 82 (Linux swap / Solaris)Command (m for help): pDisk /dev/sdb: 8589 MB, 8589934592 bytes255 heads, 63 sectors/track, 1044 cylinders, total 16777216 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk 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): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.

格式化交换分区

mkswap /dev/sdb6Setting up swapspace version 1, size = 4194204 KiBno label, UUID=40eff2c0-3f6b-440e-bc2a-f71d3d5581a7

启用交换分区

swapon /dev/sdb6

查看交换分区加载状态

free       total    used    free   shared  buffers   cachedMem:    1030108   160768   869340    264   12040   56188-/+ buffers/cache:   92540   937568Swap:   6291352     0  6291352

停用交换分区

swapoff /dev/sdb6

p.s.

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

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

/dev/sdb6        swap          swap  defaults    0 0//查看交换分区 swapon -sFilename        Type    Size  Used  Priority/dev/sda2                partition  2097148 0  -1/dev/sdb6                partition  4194204 0  -2

什么是Linux系统

Linux是一种免费使用和自由传播的类UNIX操作系统,是一个基于POSIX的多用户、多任务、支持多线程和多CPU的操作系统,使用Linux能运行主要的Unix工具软件、应用程序和网络协议。

关于怎么在Linux中添加swap分区就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

0