创建交换分区

来源:互联网 发布:python中文手册 编辑:程序博客网 时间:2024/06/05 21:52
使用命令可以查看在硬盘上哪个分区作为交换分区使用。

       Fdisk –l      

 

     [root@zheng root]#fdisk –l 

       Disk /dev/had:8589 MB,858990124 bytes

       16 heads,63 sectors/track,16644 cylinders

       Units = culinders of 1008 * 512 = 516096 bytes 

           Device    Boot     Start         End               Blocks           Id           System

        /dev/hda1       *             1            203                102280+        83           Linux

        /dev/hda2                         204        14564            7237944         83          Linux

        /dev/hda3                         14565    16644            1048320         82          Linux swap

       [root@zheng root]#

       其中/dev/hda3是正在使用的交换分区,分区号82才是swap分区,为了添加新的交换分区,需要将现用的交换分区删除掉,然后再添加新的交换分区。 

 

删除:

 

当我们通过 fdisk 设备,进入相应设备的操作时,会发现有如下的提示;以 fdisk /dev/sda 设备为例,以下同;

[root@localhost beinan]# fdisk /dev/sda

Command (m for help): 在这里按m ,就会输出帮助;
Command action

d delete a partition 注:这是删除一个分区的动作;
l list known partition types 注:l是列出分区类型,以供我们设置相应分区的类型;
m print this menu 注:m 是列出帮助信息;
n add a new partition 注:添加一个分区;
p print the partition table 注:p列出分区表;
q quit without saving changes 注:不保存退出;
t change a partition's system id 注:t 改变分区类型;
w write table to disk and exit 注:把分区表写入硬盘并退出;

列出当前操作硬盘的分区情况,用p

Command (m for help): p
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)
/dev/sda2 26 125 806400 5 Extended
/dev/sda5 26 50 201568+ 83 Linux
/dev/sda6 51 76 200781 83 Linux

通过fdisk的d指令来删除一个分区


Command (m for help): p 注:列出分区情况;
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)
/dev/sda2 26 125 806400 5 Extended
/dev/sda5 26 50 201568+ 83 Linux
/dev/sda6 51 76 200781 83 Linux
Command (m for help): d 注:执行删除分区指定;
Partition number (1-6): 6 注:我想删除 sda6 ,就在这里输入 6 ;
Command (m for help): p 注:再查看一下硬盘分区情况,看是否删除了?
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 25 201568+ c W95 FAT32 (LBA)
/dev/sda2 26 125 806400 5 Extended
/dev/sda5 26 50 201568+ 83 Linux
Command (m for help):

  w口令即可保存。警告:删除分区时要小心,请看好分区的序号,如果您删除了扩展分区,扩展分区之下的逻辑分区都会删除;所以操作时一定要小心;如果知道自己操作错了,请不要惊慌,用q不保存退出;切记切记!!!!在分区操作错了之时,千万不要输入w保存退出!!!

     

2、n  新建一个分区,新建分区要求硬盘上还有空闲空间可用

注意:分出一个区做为交换分区,分区类型应为primary,extend不能做为交换分区。

3、 修改该分区的类型为交换分区(交换分区id为82)

4、w 保存分区表

 

5、使更改后的分区表立即生效 partprobe

6、将sda5分区格式化为交换分区 mkswap /dev/sda5

7、查看交换分区大小 free

8、挂载交换分区 swapon /dev/sda5

9、用free命令查看新的交换分区大小,发现交换分区已经增加了。

10、卸载交换分区:swapoff /dev/sda5

 

 

 

0 0
原创粉丝点击