1.创建swap分区
例如: # fdisk /dev/sdb Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-13054, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-13054, default 13054): +100M
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 82
Changed system type of partition 1 to 82 (Linux swap / Solaris)
Command (m for help): w
The partition table has been altered!
2.同步分区表
# partprobe
3.设置交换区
# mkswap /dev/sdb1
4.编辑/etc/fstab文件
添加如下内容:
/dev/sdb1 swap swap defaults 0 0
5.启用swap分区
# swapon -a
6.验证swap分区是否启用
# swapon -s
Filename Type Size Used Priority
/dev/sdb1 partition 104380 0 -2
二、文件方式
1.创建文件
# dd if=/dev/zero of=/swapfile bs=1024 count=100
if=文件名:输入文件名,缺省为标准输入。即指定源文件。< if=input file >
of=文件名:输出文件名,缺省为标准输出。即指定目的文件。< of=output file >
bs=bytes:同时设置读入/输出的块大小为bytes个字节
count=blocks:仅拷贝blocks个块,块大小等于bs指定的字节数。
1G=1024mb
1mb=1024kb
1kb=1024bytes
2.查看文件属性
# ls -lh /swapfile -rw-r--r-- 1 root root 100K Apr 24 16:54 /swapfile
3.设置swap
# mkswap /swapfile
4.编辑/etc/fstab文件
添加如下内容:
/swapfile swap swap defaults 0 0
5.启用swap
# swapon /swapfile
6.验证swap是否启用
# swapon -s
Filename Type Size Used Priority
/swapfile file 92 0 -3
例如: # fdisk /dev/sdb Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-13054, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-13054, default 13054): +100M
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 82
Changed system type of partition 1 to 82 (Linux swap / Solaris)
Command (m for help): w
The partition table has been altered!
2.同步分区表
# partprobe
3.设置交换区
# mkswap /dev/sdb1
4.编辑/etc/fstab文件
添加如下内容:
/dev/sdb1 swap swap defaults 0 0
5.启用swap分区
# swapon -a
6.验证swap分区是否启用
# swapon -s
Filename Type Size Used Priority
/dev/sdb1 partition 104380 0 -2
二、文件方式
1.创建文件
# dd if=/dev/zero of=/swapfile bs=1024 count=100
if=文件名:输入文件名,缺省为标准输入。即指定源文件。< if=input file >
of=文件名:输出文件名,缺省为标准输出。即指定目的文件。< of=output file >
bs=bytes:同时设置读入/输出的块大小为bytes个字节
count=blocks:仅拷贝blocks个块,块大小等于bs指定的字节数。
1G=1024mb
1mb=1024kb
1kb=1024bytes
2.查看文件属性
# ls -lh /swapfile -rw-r--r-- 1 root root 100K Apr 24 16:54 /swapfile
3.设置swap
# mkswap /swapfile
4.编辑/etc/fstab文件
添加如下内容:
/swapfile swap swap defaults 0 0
5.启用swap
# swapon /swapfile
6.验证swap是否启用
# swapon -s
Filename Type Size Used Priority
/swapfile file 92 0 -3
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28282660/viewspace-1473313/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/28282660/viewspace-1473313/
本文详细介绍如何通过分区和文件两种方式在Linux系统中配置Swap交换空间。包括创建Swap分区及文件的具体步骤,设置Swap属性,以及如何验证Swap是否成功启用。

被折叠的 条评论
为什么被折叠?



