Linux系统配置交换分区
生活随笔
收集整理的這篇文章主要介紹了
Linux系统配置交换分区
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Linux系統配置交換分區
- 一、交換分區理解
- 二、交換分區調整大小建議
- 三、配置交換分區
- 1.磁盤分區
- 2.格式化swap分區
- 3.永久掛載swap分區
- 四、查看swap分區
一、交換分區理解
交換分區:內核使用交換分區,保存內存中暫不活動的數據,當內核重新需要訪問這部分數據,將會把這部分重新寫入內存中讀取。
二、交換分區調整大小建議
| 2G或者以下 | 兩倍的內存 |
| 2G~8G | 同等內存 |
| 8~64G | 至少4G |
| 64G以上 | 至少4G |
三、配置交換分區
1.磁盤分區
[root@node1 ~]# fdisk /dev/sdbWelcome to fdisk (util-linux 2.32.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.Command (m for help): print Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 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 Disklabel type: gpt Disk identifier: 054D4516-ACE2-4C1A-BB38-1B93407B26A9Device Start End Sectors Size Type /dev/sdb1 2048 12584959 12582912 6G Linux filesystemCommand (m for help): n Partition number (2-128, default 2): First sector (12584960-41943006, default 12584960): Last sector, +sectors or +size{K,M,G,T,P} (12584960-41943006, default 41943006): +2GCreated a new partition 2 of type 'Linux filesystem' and of size 2 GiB.Command (m for help): wThe partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.2.格式化swap分區
[root@node1 ~]# mkswap /dev/sdb2 Setting up swapspace version 1, size = 2 GiB (2147479552 bytes) no label, UUID=7b7937af-408b-4370-9bd9-baa0cb5d1c6b3.永久掛載swap分區
# vim /etc/fstab UUID=b7190d80-906f-4b9d-9ab4-5a503ecaea2c / xfs defaults 0 0 UUID=525a30a7-d484-4ed5-9f38-f827f54e29ff /boot xfs defaults 0 0 UUID=e6cf8733-5eec-4942-9429-c3e9087b6ff0 swap swap defaults 0 0 UUID="deff8218-3389-4245-a6bf-1716010fd6d4" /mnt/lv01 xfs defaults 0 0 UUID=7b7937af-408b-4370-9bd9-baa0cb5d1c6b swap swap defaults 0 0 [root@node1 ~]# swapon -a [root@node1 ~]# swapon -s Filename Type Size Used Priority /dev/nvme0n1p2 partition 2097148 0 -2 /dev/sdb2 partition 2097148 0 -3 [root@node1 ~]#四、查看swap分區
[root@node1 ~]# swapon -s Filename Type Size Used Priority /dev/nvme0n1p2 partition 2097148 0 -2 /dev/sdb2 partition 2097148 0 -3 [root@node1 ~]# [root@node1 ~]# free -mtotal used free shared buff/cache available Mem: 1966 648 831 9 485 1142 Swap: 4095 0 4095 [root@node1 ~]#總結
以上是生活随笔為你收集整理的Linux系统配置交换分区的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux系统之高级用户组和权限管理
- 下一篇: Linux下的硬链接和软链接