通过在硬盘中划定一部分空间,将内存中暂时不用的数据临时放到硬盘中。
1、查看系统所有硬盘信息
[root@linuxprobe /]# fdisk -l |grep /dev
Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 sectors
/dev/sdb1 2048 4196351 2097152 83 Linux
/dev/sdb2 4196352 8390655 2097152 83 Linux
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 41943039 20458496 8e Linux LVM
Disk /dev/sdc: 2147 MB, 2147483648 bytes, 4194304 sectors
/dev/sdc1 2048 2099199 1048576 83 Linux
/dev/sdc2 2099200 3123199 512000 83 Linux
Disk /dev/sde: 1073 MB, 1073741824 bytes, 2097152 sectors
Disk /dev/sdd: 1073 MB, 1073741824 bytes, 2097152 sectors
Disk /dev/sdf: 1073 MB, 1073741824 bytes, 2097152 sectors
Disk /dev/sdg: 1073 MB, 1073741824 bytes, 2097152 sectors
Disk /dev/mapper/rhel_linuxprobe-swap: 2147 MB, 2147483648 bytes,
4194304 sectors
Disk /dev/mapper/rhel_linuxprobe-root: 18.8 GB, 18798870528 bytes,
36716544 sectors
2、在实验中将第三块硬盘的第二个分区作为swap空间
3、将第三块硬盘(2G)sdc
分个sdc2 500M 作为虚拟缓存。
[root@linuxprobe /]# fdisk
/dev/sdc
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
Partition type:
p
primary (1 primary, 0 extended, 3 free)
e
extended
Select (default p):p
Partition number (2-4, default 2):
First sector (2099200-4194303, default
2099200):
Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-4194303,
default 4194303): +500M
Partition 2 of type Linux and of size 500 MiB is
set
Command (m for help): P
Disk /dev/sdc: 2147 MB, 2147483648 bytes, 4194304
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: 0xb777c8c2
Device Boot
Start
End
Blocks
Id
System
/dev/sdc1
2048
2099199
1048576
83
Linux
/dev/sdc2
2099200
3123199
512000
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.
4、使用swap分区的专用格式化命令mkswap
[root@linuxprobe /]# mkswap
/dev/sdc2
Setting up swapspace version 1, size = 511996
KiB
no label,
UUID=941fd777-4b5f-4f6d-85cf-9ba711032306
5、使用free
–m 命令查看原来的内存大小
[root@linuxprobe /]# free -m
total
used
free
shared
buffers
cached
Mem:
1826
1414
412
9
0
307
-/+ buffers/cache:
1105
721
Swap:
2047
0
2047
6、将前面500M硬盘空间用命令swapon挂载到系统中
[root@linuxprobe /]# swapon
/dev/sdc2
7、再次查看内存大小
[root@linuxprobe /]# free -m
total
used
free
shared
buffers
cached
Mem:
1826
1441
385
9
0
311
-/+ buffers/cache:
1128
698
Swap:
2547
0
2547
//已经由原来的2047增加到2547