【原创】linux交换空间管理--交换分区

来源:互联网 发布:面向接口编程实例 编辑:程序博客网 时间:2024/06/08 01:25

要求:以交换分区的方式给系统增加100MB的交换空间

操作系统:FC6

//查看当前系统硬盘空间的使用情况 

[root@localhost ~]# fdisk -l

Disk /dev/hda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1         255     2048256    7  HPFS/NTFS
/dev/hda2             256        1044     6337642+   f  W95 Ext'd (LBA)
/dev/hda5             256         766     4104544+  83  Linux
/dev/hda6             767         829      506016   82  Linux swap / Solaris

//创建一个交换分区,命名为/hda7(具体命名视实际情况而定)

[root@localhost ~]# fdisk /dev/hda

The number of cylinders for this disk is set to 1044.
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/hda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1         255     2048256    7  HPFS/NTFS
/dev/hda2             256        1044     6337642+   f  W95 Ext'd (LBA)
/dev/hda5             256         766     4104544+  83  Linux
/dev/hda6             767         829      506016   82  Linux swap / Solaris

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (830-1044, default 830):
Using default value 830
Last cylinder or +size or +sizeM or +sizeK (830-1044, default 1044): +100M

Command (m for help): t
Partition number (1-7): 7
Hex code (type L to list codes): L
 0  Empty           1e  Hidden W95 FAT1 80  Old Minix       be  Solaris boot
 1  FAT12           24  NEC DOS         81  Minix / old Lin bf  Solaris
 2  XENIX root      39  Plan 9          82  Linux swap / So c1  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  83  Linux           c4  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 5  Extended        41  PPC PReP Boot   85  Linux extended  c7  Syrinx
 6  FAT16           42  SFS             86  NTFS volume set da  Non-FS data
 7  HPFS/NTFS       4d  QNX4.x          87  NTFS volume set db  CP/M / CTOS / .
 8  AIX             4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility
 9  AIX bootable    4f  QNX4.x 3rd part 8e  Linux LVM       df  BootIt
 a  OS/2 Boot Manag 50  OnTrack DM      93  Amoeba          e1  DOS access
 b  W95 FAT32       51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O
 c  W95 FAT32 (LBA) 52  CP/M            9f  BSD/OS          e4  SpeedStor
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a5  FreeBSD         ee  EFI GPT
10  OPUS            55  EZ-Drive        a6  OpenBSD         ef  EFI (FAT-12/16/
11  Hidden FAT12    56  Golden Bow      a7  NeXTSTEP        f0  Linux/PA-RISC b
12  Compaq diagnost 5c  Priam Edisk     a8  Darwin UFS      f1  SpeedStor
14  Hidden FAT16 <3 61  SpeedStor       a9  NetBSD          f4  SpeedStor
16  Hidden FAT16    63  GNU HURD or Sys ab  Darwin boot     f2  DOS secondary
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fd  Linux raid auto
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fe  LANstep
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid ff  BBT
1c  Hidden W95 FAT3 75  PC/IX
Hex code (type L to list codes): 82
Changed system type of partition 7 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: 设备或资æºå¿™.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

//格式化该分区

[root@localhost ~]# mkswap /dev/hda7
Setting up swapspace version 1, size = 100237 kB

//查看系统当前交换空间的大小


[root@localhost ~]# free
             total       used       free     shared    buffers     cached
Mem:        252036     135724     116312          0      10452      59016
-/+ buffers/cache:      66256     185780
Swap:         8184          0       8184

//激活该交换空间

[root@localhost ~]# swapon /dev/hda7

//再查看系统中交换空间的大小是否有变法

[root@localhost ~]# free
             total       used       free     shared    buffers     cached
Mem:        252036     135864     116172          0      10492      59016
-/+ buffers/cache:      66356     185680
Swap:       106068          0     106068

//交换分区加入/etc/fstab文件中,使其自动加载

[root@localhost ~]# vi /etc/fstab
LABEL=/                 /                       ext3    defaults        1 1
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
sysfs                   /sys                    sysfs   defaults        0 0
LABEL=SWAP-hda7         swap                    swap    defaults        0 0
/dev/hda7               swap                    swap    defaults        0 0

 

ps:此帖绝对是本人原创...

转载时..
请注明:
转至http://blog.csdn.net/Kipen/   作者:flyshitou(石の頭丶)
请尊重他人的劳动果实..
谢谢..

 --by flyshitou (石の頭丶)

 

原创粉丝点击