交换分区概念
交换分区就是在主机上拿出一部分空间来模拟成内存
管理交换分区
在本地存储上创建交换分区并将其配置为在引导时自动使用
cat/proc/swaps 查看当前计算机中的交换分区
[[email protected] tmp]# cat /proc/swaps Filename Type Size Used Priority /dev/sda2 partition 2096472 70592 -1
增加创建一个交换分区
1、拿出一个分区,变成交换分区
mkswap /dev/sda3
swapon /dev/sda3
[[email protected] ~]# fdisk -l /dev/sda Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280bytes Sector size (logical/physical): 512 bytes /512 bytes I/O size (minimum/optimal): 512 bytes / 512bytes Disk identifier: 0x00042f38 Device Boot Start End Blocks Id System /dev/sda1 * 1 26 204800 83 Linux Partition 1 does not end on cylinderboundary. /dev/sda2 26 1301 10240000 83 Linux /dev/sda3 1301 1431 1048576 82 Linux swap / Solaris /dev/sda4 1431 2610 9470425 5 Extended /dev/sda5 1431 1692 2096558+ 83 Linux [[email protected] ~]# mkswap /dev/sda5 Setting up swapspace version 1, size =2096552 KiB no label,UUID=74655c5a-c242-4069-8148-92558d762542 [[email protected] ~]# swapon /dev/sda5 [[email protected] ~]# cat /proc/swaps Filename Type Size Used Priority /dev/sda3 partition 1048568 0 -1 /dev/sda5 partition 2096548 0 -2
①fdisk –l 查看这块硬盘的信息
②列出当前这块硬盘的分区信息
③mkswap /dev/sda3 把一个分区(sda3)更式化转为swap分区
④cat /proc/swaps 查看这块硬盘的swap分区
⑤swapon/dev/sda3 启动该交换分区让其生效(临时生效)
⑥cat /proc/swaps 查看这块硬盘的swap分区
要使其新建的交换分区生效,要改更其配置文件,让它在系统启动时自动挂载
gedit /etc/fstab(要重启系统)
[[email protected] ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Fri Apr 4 00:16:06 2014 # # Accessible filesystems, by reference, aremaintained under ‘/dev/disk‘ # See man pages fstab(5), findfs(8),mount(8) and/or blkid(8) for more info # UUID=af31913f-d2d1-4753-bbee-e5a88b7d72e5/ ext4 defaults 1 1 UUID=f156c1b9-e1e6-4e24-af0b-350e38f7ef28/boot ext4 defaults 1 2 UUID=c2001c65-a625-498e-8c70-fe9eef611427swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 /dev/sda5 swap swap defaults 0 0
swapoff /dev/sda3 关闭sda3这个交换分区
修改分区别分区ID
fdisk /dev/sda [[email protected] ~]# fdisk /dev/sda WARNING: DOS-compatible mode is deprecated.It‘s strongly recommended to switch off the mode (command ‘c‘) and change display units to sectors (command ‘u‘). Command (m for help): t #改变一个分区的系统ID Partition number (1-5): 5 #选择要修改的分区编号 Hex code (type L to list codes): 28 #交换分区类型ID Changed system type of partition 5 to 28(Unknown) [[email protected] ~]# fdisk /dev/sda -l Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280bytes Sector size (logical/physical): 512 bytes /512 bytes I/O size (minimum/optimal): 512 bytes / 512bytes Disk identifier: 0x00042f38 Device Boot Start End Blocks Id System /dev/sda1 * 1 26 204800 83 Linux Partition 1 does not end on cylinderboundary. /dev/sda2 26 1301 10240000 83 Linux /dev/sda3 1301 1431 1048576 82 Linux swap / Solaris /dev/sda4 1431 2610 9470425 5 Extended /dev/sda5 1431 1692 2096558+ 82 Linux swap / Solaris
2、拿出一个空间,变成交换分区
[[email protected] ~]# dd if=/dev/zero of=testbs=1M count=1000 记录了1000+0 的读入 记录了1000+0 的写出 1048576000字节(1.0 GB)已复制,4.46818 秒,235 MB/秒 [[email protected] ~]# ls -lh test -rw-r--r--. 1 root root 1000M 4月 7 00:37 test [[email protected] ~]# mkswap test mkswap: test: warning: don‘t erase bootbitssectors on whole disk. Use -f to force. Setting up swapspace version 1, size =1023996 KiB no label,UUID=b3d5103c-8231-40c7-ae68-ee317e1b64dc [[email protected] ~]# swapon test [[email protected] ~]# cat /proc/swaps Filename Type Size Used Priority /dev/sda3 partition 1048568 0 -1 /dev/sda5 partition 2096548 0 -2 /root/test file 1023992 0 -3
①新建一个文件,命名为file大小为1000M
②ls –lh file 以人性化单位查看这个文件的属性
③mkswap file 把file这个文件所占的空间更式化转为swap分区
④swapon file 启动该交换分区让其生效(临时生效)
⑤cat/proc/swaps 查看这块硬盘的swap分区
创建后也一样要gedit /etc/fstab 打开fstab文件,在最后行添加上swap的配置让其在系统启动时自动挂载
[[email protected] ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Fri Apr 4 00:16:06 2014 # # Accessible filesystems, by reference, aremaintained under ‘/dev/disk‘ # See man pages fstab(5), findfs(8),mount(8) and/or blkid(8) for more info # UUID=af31913f-d2d1-4753-bbee-e5a88b7d72e5/ ext4 defaults 1 1 UUID=f156c1b9-e1e6-4e24-af0b-350e38f7ef28/boot ext4 defaults 1 2 UUID=c2001c65-a625-498e-8c70-fe9eef611427swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 /dev/sda5 swap swap defaults 0 0 /root/test swap swap defaults 0 0
时间: 2024-10-06 16:15:55