Linux- 将交换分区扩大 1G 空间

29、将你的交换分区扩大 1G 空间(通过两种方式)
第一种方式: 将逻辑卷作为交换分区
[root@virtual1 ~]# pvcreate /dev/vdb3
  Physical volume "/dev/vdb3" successfully created.
[root@virtual1 ~]# vgcreate vg01 /dev/vdb3
  Volume group "vg01" successfully created
[root@virtual1 ~]# lvcreate -L 800M -n lv01 vg01
  Logical volume "lv01" created.
[root@virtual1 ~]# mkswap /dev/vg01/lv01
Setting up swapspace version 1, size = 819196 KiB
no label, UUID=c641af39-5aa5-4d51-a72b-eecab3f3e261
[root@virtual1 ~]# swapon -s
Filename                Type        Size    Used    Priority
/dev/dm-1                                  partition    4194300    2664    -1

[root@virtual1 ~]# vim /etc/fstab    
[root@virtual1 ~]# swapon -a                    
[root@virtual1 ~]# swapon -s
Filename                Type        Size    Used    Priority
/dev/dm-1                                  partition    4194300    2660    -1
/dev/dm-6                                  partition    819196    0    -2
(2)将一个硬盘或一个分区作为交换分区
(3)将一个文件作为交换分区

[root@virtual1 ~]# touch file1
[root@virtual1 ~]# dd </dev/zero >file1 bs=1G count=1   //这里利用dd 命令自己生成一个1G大小的文件
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 12.1907 s, 88.1 MB/s
[root@virtual1 ~]# ls
anaconda-ks.cfg  file1  nginx-1.14.0.tar.gz
[root@virtual1 ~]# vim /etc/fstab
[root@virtual1 ~]# swapon -a
swapon: /root/file1: insecure permissions 0644, 0600 suggested.
swapon: /root/file1: read swap header failed: Invalid argument
[root@virtual1 ~]# swapon -s
Filename                Type        Size    Used    Priority
/dev/dm-1                                  partition    4194300    70876    -1
/dev/dm-6                                  partition    819196    0    -2
[root@virtual1 ~]# chmod 0600 file1
[root@virtual1 ~]# swapon -a
swapon: /root/file1: read swap header failed: Invalid argument
[root@virtual1 ~]# mkswap /root/file1
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=a39bf6f1-c428-4854-ac96-5344c018be77
[root@virtual1 ~]# swapon -a
[root@virtual1 ~]# swapon -s                                                                                     //查看可得到交换分区
Filename                Type        Size    Used    Priority
/dev/dm-1                                  partition    4194300    70028    -1
/dev/dm-6                                  partition    819196    0    -2
/root/file1                                file    1048572    0    -3

猜你喜欢

转载自blog.csdn.net/kerry2018/article/details/81609482