仮想メモリを追加する2つの方法


#現在の仮想メモリ情報の表示
[/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