CentOS7スワップパーティション管理(パーティションまたはファイル)
1は、スワップはオペレーティングシステムのインストール時に作成された別々のパーティションに分割することができ、あなたが作成するために、残りの良いドライブにオペレーティングシステムをインストールすることができ、スワップパーティションを使用しているときにも、ファイルを作成することができます
図2に示すように、また便利な小型、携帯に変更する自由かのように行動するスワップファイルを使用して、あなたはそれがソリッドステートハードドライブ上のファイルに最善である場合に、ファイルとスワップパーティションを使用したい場合は、スワップ使用などの新しいパーティションを作成することをお勧めしますが、パフォーマンスれます良くないパーティション
スワップを分割するパーティションを作成します。
まず、自由-hを使用すると、現在のスワップを表示するには
スワップ空間4Gの現在のシステム
[root@centos7 ~]# free -h
total used free shared buff/cache available
Mem: 1.9G 180M 1.2G 19M 545M 1.6G
Swap: 4.0G 12M 4.0G
スワップの現在のシステムを表示する-sはswaponを使用します
[root@centos7 ~]# swapon -s
Filename Type Size Used Priority
/dev/dm-0 partition 419430012676 -2
第二に、使用lsblkは、現行のハード・ディスク・システムを表示します
あなたは、今、150以上のGに分け200GのSDAの合計を、見ることができる、の余地があるかもしれません
[root@centos7 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 100G 0 part /
├─sda3 8:3 0 50G 0 part /data
├─sda4 8:4 0 1K 0 part
└─sda5 8:5 0 4G 0 part
└─centos-swap
253:0 0 4G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
└─sdb2 8:18 0 2G 0 part
作成された第三に、fdiskのは/ dev / sdaにを使用すると、ハードディスクのパーティション操作
[root@centos7 ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
All primary partitions are in use
Adding logical partition 6
First sector (325072896-419430399, default 325072896):
Using default value 325072896
Last sector, +sectors or +size{K,M,G} (325072896-419430399, default 419430399): +2G
Partition 6 of type Linux and of size 2 GiB is set
Command (m for help): p
Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 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 label type: dos
Disk identifier: 0x000f14f7
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 211814399 104857600 83 Linux
/dev/sda3 211814400 316671999 52428800 83 Linux
/dev/sda4 316672000 419430399 51379200 5 Extended
/dev/sda5 316674048 325070847 4198400 8e Linux LVM
/dev/sda6 325072896 329267199 2097152 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
第四に、(CentOS6実行部は/ dev / sdaに-a)を2回partprobeを行いました
[root@centos7 ~]# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
Error: Invalid partition table - recursive partition on /dev/sr0.
Warning: Unable to open /dev/sr1 read-write (Read-only file system). /dev/sr1 has been opened read-only.
[root@centos7 ~]# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
Error: Invalid partition table - recursive partition on /dev/sr0.
Warning: Unable to open /dev/sr1 read-write (Read-only file system). /dev/sr1 has been opened read-only.
第五に、ファイルシステムを作成
[root@centos7 ~]# ls /dev/sda6
/dev/sda6
[root@centos7 ~]# mkswap /dev/sda6
Setting up swapspace version 1, size = 2097148 KiB
no label, UUID=b98996a2-a548-4266-b636-b2cb75cd0626
第六に、書き込みの/ etc / fstabに、そして-aテストをマウント
[root@centos7 ~]# blkid /dev/sda6
/dev/sda6: UUID="b98996a2-a548-4266-b636-b2cb75cd0626" TYPE="swap"
[root@centos7 ~]# vim /etc/fstab
[root@centos7 ~]# tail -1 /etc/fstab
UUID=b98996a2-a548-4266-b636-b2cb75cd0626 swap swap defaults 0 0
# 被挂载的设备名 挂载点 文件系统类型 挂载选项 转储频率 系统自检选项
[root@centos7 ~]# mount -a
七、swapon -a
すべてのスワップを有効にするには、swaponを-aを実行し、スワップパーティションが表示されていない、自由-hを実行します
[root@centos7 ~]# free -h
total used free shared buff/cache available
Mem: 1.9G 176M 1.2G 19M 547M 1.6G
Swap: 4.0G 12M 4.0G
# 执行swapon -a
[root@centos7 ~]# swapon -a
[root@centos7 ~]# free -h
total used free shared buff/cache available
Mem: 1.9G 178M 1.2G 19M 547M 1.6G
Swap: 6.0G 12M 6.0G
八、スワップをアンインストールします
# 使用swapoff关闭/dev/sda6这个swap分区
[root@centos7 ~]# swapoff /dev/sda6
# 使用sed删除fstab最后加的一行
[root@centos7 ~]# sed -ri '$d' /etc/fstab
# mount -a
[root@centos7 ~]# mount -a
# 此时swap已变成原来的4G
スワップパーティションとしてファイルの行為を作成します。
まず、スワップと、ファイル100Mを作成するためには、ddコマンドを使用します
[root@centos7 data]# dd if=/dev/zero of=/data/swapfile bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 2.74665 s, 38.2 MB/s
# swap文件权限修改为600,安全
[root@centos7 data]# chmod 600 swapfile
第二に、ファイルシステム上のファイルを作成
[root@centos7 data]# mkswap swapfile
Setting up swapspace version 1, size = 102396 KiB
no label, UUID=a16538e7-685e-4141-aaeb-e1b7896cffdf
第三に、書き込みの/ etc / fstabに、(ここでは、UUIDを書くことができないデバイスをマウント、ファイル名のみを記述することに注意してください)マウント
[root@centos7 data]# tail -1 /etc/fstab
/data/swapfile swap swap defaults 0 0
[root@centos7 data]# mount -a
第四に、実装にswaponは、すべてのスワップを開き-a
[root@centos7 data]# swapon -a
[root@centos7 data]# swapon -s
Filename Type Size Used Priority
/dev/dm-0 partition 4194300 12672 -2
/data/swapfile file 102396 0 -3
[root@centos7 data]# free -h
total used free shared buff/cache available
Mem: 1.9G 176M 1.1G 19M 650M 1.6G
Swap: 4.1G 12M 4.1G
第五に、スワップを増やすには、アンマウントする必要があります
# 必须先卸载,不然报错了
[root@centos7 data]# dd if=/dev/zero of=/data/swapfile bs=1M count=200
dd: failed to open ‘/data/swapfile’: Text file busy
# 卸载
[root@centos7 data]# swapoff /data/swapfile
[root@centos7 data]# dd if=/dev/zero of=/data/swapfile bs=1M count=200
200+0 records in
200+0 records out
209715200 bytes (210 MB) copied, 3.23377 s, 64.9 MB/s
# 创建文件系统
[root@centos7 data]# mkswap swapfile
Setting up swapspace version 1, size = 204796 KiB
no label, UUID=79d0f287-c998-42d3-aabc-b3b2d60b9cb2
# 执行swapon -a启用所有swap
[root@centos7 data]# swapon -a
[root@centos7 data]# free -h
total used free shared buff/cache available
Mem: 1.9G 176M 1.0G 19M 752M 1.6G
Swap: 4.2G 12M 4.2G
第六に、アンインストール
# 取消挂载
[root@centos7 data]# swapoff /data/swapfile
[root@centos7 data]# sed -ri '$d' /etc/fstab
[root@centos7 data]# mount -a
[root@centos7 data]# rm -f swapfile
[root@centos7 data]# free -h
total used free shared buff/cache available
Mem: 1.9G 176M 1.2G 19M 547M 1.6G
Swap: 4.0G 12M 4.0G