pengranxiang 发表于 2013-1-28 18:39:24

增加虚拟内存的两种方法

#查看当前虚拟内存信息
#swapon -s Filename                              Type            Size    Used    Priority /dev/sda2                               partition       2096472 92      -1  
#添加虚拟内存
#1.通过分区增加
#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   IdSystem /dev/sda1   *         1      2349    18868311   83Linux /dev/sda2            2350      2610   2096482+82Linux 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   IdSystem /dev/sdb1               1         123      987966   8eLinux LVM /dev/sdb2             124         246      987997+8eLinux LVM /dev/sdb3             247         369      987997+8eLinux LVM /dev/sdb4             370      2610    18000832+   5Extended /dev/sdb5             370         492      987966   8eLinux LVM  
#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   IdSystem /dev/sdb1               1         123      987966   8eLinux LVM /dev/sdb2             124         246      987997+8eLinux LVM /dev/sdb3             247         369      987997+8eLinux LVM /dev/sdb4             370      2610    18000832+   5Extended /dev/sdb5             370         492      987966   8eLinux 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   IdSystem /dev/sdb1               1         123      987966   8eLinux LVM /dev/sdb2             124         246      987997+8eLinux LVM /dev/sdb3             247         369      987997+8eLinux LVM /dev/sdb4             370      2610    18000832+   5Extended /dev/sdb5             370         492      987966   8eLinux LVM /dev/sdb6             493         554      497983+83Linux #修改标签为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.  #刷新分区信息
#partprobe /dev/sdb #mkswap /dev/sdb6 Setting up swaace version 1, size = 509927 kB  
#增加分区为交换
#swapon /dev/sdb6 #swapon -s Filename                              Type            Size    Used    Priority /dev/sda2                               partition       2096472 76      -1 /dev/sdb6                               partition       4979720       -2  
#修改优先级,-p指定优先级范围0-32767,越大越优先。
#swapoff /dev/sdb6 #swapon -p 5 /dev/sdb6 #swapon -s Filename                              Type            Size    Used    Priority /dev/sda2                               partition       2096472 76      -1 /dev/sdb6                               partition       4979720       5 #vi /etc/fstab LABEL=/               /                     ext3    defaults      1 1 tmpfs                   /dev/shm                tmpfs   defaults      0 0 devpts                  /dev/pts                devptsgid=5,mode=6200 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格式
#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 #mkswap /home/swapfile Setting up swaace version 1, size = 1044 kB  
#启用文件作为swap
#swapon /home/swapfile #swapon -s Filename                              Type            Size    Used    Priority /dev/sda2                               partition       2096472 76      -1 /dev/sdb6                               partition       4979720       5 /home/swapfile                        file            1016    0       -3 
页: [1]
查看完整版本: 增加虚拟内存的两种方法