[root@caoxl /]# free -m total used free shared buff/cache available Mem: 3789111307995993435 Swap: 000
[root@caoxl /]# free -g total used free shared buff/cache available Mem: 303003 Swap: 000
创建一个文件
1 2 3 4
[root@caoxl /]# touch swap [root@caoxl /]# ls bin data download home lib64 media opt root sbin swap tmp var boot dev etc lib lost+found mnt proc run srv sys usr
使用dd命令,创建大小为2G的文件swap
1 2 3 4
[root@caoxl /]# dd if=/dev/zero of=/swap bs=1M count=2048 2048+0 records in 2048+0 records out 2147483648bytes (2.1 GB) copied, 11.7135 s, 183 MB/s
if - input_file 输入文件
of - output_file 输出文件
bs - block_size 块大小
count 表示计数
格式化交换文件
1 2 3
[root@caoxl /]# mkswap swap Setting up swapspace version 1, size = 2097148 KiB no label, UUID=f77dd6aa-0625-47e9-9eb9-bf26050a8508
[root@caoxl /]# sudo fdisk /dev/vda1 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.
Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0xc5d30913.
Command (m for help): n // 新增分区 Partition type: p primary (0 primary, 0 extended, 4 free) // 主分区 e extended // 扩展分区 Select (default p): e // 选择要创建的分区类型 Partition number (1-4, default1): 1// 分区编号 First sector (2048-83881983, default2048): // 柱面起始值,直接回车默认 Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-83881983, default83881983): +1G Partition 1 of type Extended and of size 1 GiB is set
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 22: Invalid argument. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) orkpartx(8) Syncing disks.
查看分区
1 2 3 4 5 6 7 8 9 10 11 12
Command (m for help): p
Disk /dev/vda1: 42.9 GB, 42947575808 bytes, 83881984 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: 0xc5d30913
Device Boot Start End Blocks Id System /dev/vda1p1 2048209919910485765 Extended /dev/vda1p2 2099200314777552428883 Linux