增加虚拟内存的两种方法

#查看当前虚拟内存信息

[/var/ftp/ks]#swapon -s 
Filename                                Type            Size    Used    Priority 
/dev/sda2                               partition       2096472 92      -1 

 

#添加虚拟内存
#1.通过分区增加

[/var/ftp/ks]#fdisk -l 

Disk /dev/sda: 21.4 GB, 21474836480 bytes 
255 heads, 63 sectors/track, 2610 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes 

   Device Boot      Start         End      Blocks   Id  System 
/dev/sda1   *           1        2349    18868311   83  Linux 
/dev/sda2            2350        2610     2096482+  82  Linux swap / Solaris 

Disk /dev/sdb: 21.4 GB, 21474836480 bytes 
255 heads, 63 sectors/track, 2610 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes 

   Device Boot      Start         End      Blocks   Id  System 
/dev/sdb1               1         123      987966   8e  Linux LVM 
/dev/sdb2             124         246      987997+  8e  Linux LVM 
/dev/sdb3             247         369      987997+  8e  Linux LVM 
/dev/sdb4             370        2610    18000832+   5  Extended 
/dev/sdb5             370         492      987966   8e  Linux LVM 

 

[/var/ftp/ks]#fdisk /dev/sdb 

The number of cylinders for this disk is set to 2610. 
There is nothing wrong with that, but this is larger than 1024, 
and could in certain setups cause problems with: 
1) software that runs at boot time (e.g., old versions of LILO) 
2) booting and partitioning software from other OSs 
   (e.g., DOS FDISK, OS/2 FDISK) 

Command (m for help): p 

Disk /dev/sdb: 21.4 GB, 21474836480 bytes 
255 heads, 63 sectors/track, 2610 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes 

   Device Boot      Start         End      Blocks   Id  System 
/dev/sdb1               1         123      987966   8e  Linux LVM 
/dev/sdb2             124         246      987997+  8e  Linux LVM 
/dev/sdb3             247         369      987997+  8e  Linux LVM 
/dev/sdb4             370        2610    18000832+   5  Extended 
/dev/sdb5             370         492      987966   8e  Linux LVM 

Command (m for help): n 
First cylinder (493-2610, default 493): 
Using default value 493 
Last cylinder or +size or +sizeM or +sizeK (493-2610, default 2610): +500M 

Command (m for help): p 

Disk /dev/sdb: 21.4 GB, 21474836480 bytes 
255 heads, 63 sectors/track, 2610 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes 

   Device Boot      Start         End      Blocks   Id  System 
/dev/sdb1               1         123      987966   8e  Linux LVM 
/dev/sdb2             124         246      987997+  8e  Linux LVM 
/dev/sdb3             247         369      987997+  8e  Linux LVM 
/dev/sdb4             370        2610    18000832+   5  Extended 
/dev/sdb5             370         492      987966   8e  Linux LVM 
/dev/sdb6             493         554      497983+  83  Linux 

#修改标签为82,即交换分区标示 
Command (m for help): t 
Partition number (1-6): 6 
Hex code (type L to list codes): 82 
Changed system type of partition 6 to 82 (Linux swap / Solaris) 

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. 

 #刷新分区信息

[/var/ftp/ks]#partprobe /dev/sdb 
[/var/ftp/ks]#mkswap /dev/sdb6 
Setting up swaace version 1, size = 509927 kB 

 

#增加分区为交换

[/var/ftp/ks]#swapon /dev/sdb6 
[/var/ftp/ks]#swapon -s 
Filename                                Type            Size    Used    Priority 
/dev/sda2                               partition       2096472 76      -1 
/dev/sdb6                               partition       497972  0       -2 

 

#修改优先级,-p指定优先级范围0-32767,越大越优先。

[/var/ftp/ks]#swapoff /dev/sdb6 
[/var/ftp/ks]#swapon -p 5 /dev/sdb6 
[/var/ftp/ks]#swapon -s 
Filename                                Type            Size    Used    Priority 
/dev/sda2                               partition       2096472 76      -1 
/dev/sdb6                               partition       497972  0       5 
[/var/ftp/ks]#vi /etc/fstab 
LABEL=/                 /                       ext3    defaults        1 1 
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 
LABEL=SWAP-sda2         swap                    swap    defaults        0 0 
"/etc/fstab" 8L, 598C written                                     

 

#2.通过文件增加

#创建一个文件,格式化为swap格式

[/var/ftp/ks]#dd if=/dev/zero of=/home/swapfile bs=1024 count=1024 
1024+0 records in 
1024+0 records out 
1048576 bytes (1.0 MB) copied, 0.00702343 seconds, 149 MB/s 
[/var/ftp/ks]#mkswap /home/swapfile 
Setting up swaace version 1, size = 1044 kB 

 

#启用文件作为swap

[/var/ftp/ks]#swapon /home/swapfile 
[/var/ftp/ks]#swapon -s 
Filename                                Type            Size    Used    Priority 
/dev/sda2                               partition       2096472 76      -1 
/dev/sdb6                               partition       497972  0       5 
/home/swapfile                          file            1016    0       -3

 

你可能感兴趣的:(linux,Solaris,dos,OS,UP)