这种情况可以针对没有建立swap或者swap空间比较小。
1、对硬盘进行分区。
#fdisk
Command (m for help): p
Disk /dev/sda: 69.7 GB, 69793218560 bytes
255 heads, 63 sectors/track, 8485 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
/dev/sda1
/dev/sda2
/dev/sda3
Partition table entries are not in disk order
Command (m for help): n
Command action
p
Selected partition 4
First cylinder (1828-8485, default 1828): 5222
Last cylinder or +size or +sizeM or +sizeK (5222-8485, default8485): 7309
Command (m for help): t
Partition number (1-4): 4
Hex code (type L to list codes): 82
Changed system type of partition 4 to 82 (Linux swap / Solaris)
Command (m for help): p
Disk /dev/sda: 69.7 GB, 69793218560 bytes
255 heads, 63 sectors/track, 8485 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
/dev/sda1
/dev/sda2
/dev/sda3
/dev/sda4
Partition table entries are not in disk order
Command (m for help): m
Command action
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.
Syncing disks.
[root@ENGtest sbin]# df -k
Filesystem
/dev/sda1
/dev/sda3
/dev/sda2
tmpfs
/dev/sdb
/dev/sdc
/dev/sdd
[root@ENGtest sbin]# fdisk -l /dev/sda
Disk /dev/sda: 69.7 GB, 69793218560 bytes
255 heads, 63 sectors/track, 8485 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
/dev/sda1
/dev/sda2
/dev/sda3
/dev/sda4
Partition table entries are not in disk order
2、建立swap分区,并且进行加载。
[root@ENGtest /]#
[root@ENGtest /]# fdisk -l /dev/sda
Disk /dev/sda: 69.7 GB, 69793218560 bytes
255 heads, 63 sectors/track, 8485 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
/dev/sda1
/dev/sda2
/dev/sda3
/dev/sda4
Partition table entries are not in disk order
[root@ENGtest /]# ls -l
total 392
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x 100 root
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwx------
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
dr-xr-xr-x 150 root
drwxr-x---
drwxr-xr-x
-rw-r--r--
drwxr-xr-x
drwxr-xr-x
drwxrwxrwx
drwxr-xr-x
drwxrwxrwt
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
[root@ENGtest /]# rmdir swap
[root@ENGtest /]# ls -l
total 384
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x 100 root
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwx------
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
dr-xr-xr-x 150 root
drwxr-x---
drwxr-xr-x
-rw-r--r--
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
drwxrwxrwt
drwxr-xr-x
drwxr-xr-x
drwxr-xr-x
[root@ENGtest /]# mkswap /dev/sda4
Setting up swapspace version 1, size = 17174380 kB
[root@ENGtest /]# swapon /dev/swap
swapon: cannot stat /dev/swap: No such file or directory
[root@ENGtest /]# swapon /dev/sda4
[root@ENGtest /]# top
top - 16:33:00 up 10 min,
Tasks: 135 total,
Cpu(s):
Mem:
Swap: 16771852ktotal,
[3]+
[root@ENGtest /]# df -k
Filesystem
/dev/sda1
/dev/sda3
/dev/sda2
tmpfs
/dev/sdb
/dev/sdc
/dev/sdd
3、修改文件 /etc/fstab或者/etc/rc.d/rc.local,是启动的时候自动加载swap
如果让swap开机就加载,应该改 /etc/fstab文件,加类似如下一行;
<code>
/dev/sda6
或者把命令行直接写入 /etc/rc.d/rc.local中也行;
swapon
[root@ENGtest /]# cd
[root@ENGtest etc]# cd
[root@ENGtest rc.d]# ls
init.d
rc
[root@ENGtest rc.d]# ls -l
total 112
drwxr-xr-x 2 root root
-rwxr-xr-x 1 root root
drwxr-xr-x 2 root root
drwxr-xr-x 2 root root
drwxr-xr-x 2 root root
drwxr-xr-x 2 root root
drwxr-xr-x 2 root root
drwxr-xr-x 2 root root
drwxr-xr-x 2 root root
-rwxr-xr-x 1 root root
-rwxr-xr-x 1 root root 26376 Jan 19
[root@ENGtest rc.d]# cp rc
rc
rc0.d/
[root@ENGtest rc.d]# cp rc.local
[root@ENGtest rc.d]# ls-l
-bash: ls-l: command not found
[root@ENGtest rc.d]# ls -l
total 120
drwxr-xr-x 2 root root
-rwxr-xr-x 1 root root
drwxr-xr-x 2 root root
drwxr-xr-x 2 root root
drwxr-xr-x 2 root root
drwxr-xr-x 2 root root
drwxr-xr-x 2 root root
drwxr-xr-x 2 root root
drwxr-xr-x 2 root root
-rwxr-xr-x 1 root root
-rwxr-xr-x 1 root root
-rwxr-xr-x 1 root root 26376 Jan 19
[root@ENGtest rc.d]# vi rc.local
#!/bin/sh
#
# This script will be executed *after* all the other initscripts.
# You can put your own initialization stuff in here if youdon't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
swapon /dev/sda4
~
"rc.local" 8L, 237C written
[root@ENGtest rc.d]# ls
init.d
rc
[root@ENGtest rc.d]# reboot
Broadcast message from root (pts/1) (Mon Feb
The system is going down for reboot NOW!
[root@ENGtest rc.d]#
[root@ENGtest rc.d]#
[root@ENGtest rc.d]# reboot