ITPub博客

首页 > Linux操作系统 > Linux操作系统 > SWAP分区的重新创建

SWAP分区的重新创建

Linux操作系统 作者:kuqlan 时间:2013-11-28 20:47:02 0 删除 编辑

第一种方法:新建一个swap分区

1、对硬盘进行分区。

#fdisk  /dev/sda
Command (m for help): p

Disk /dev/sda: 69.7 GB, 69793218560 bytes
255 heads, 63 sectors/track, 8485 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
Selected partition 4
First cylinder (1828-8485, default 1828): 5222
Last cylinder or +size or +sizeM or +sizeK (5222-8485, default 8485): 7309

Command (m for help): t
Partition number (1-4): 4
Hex code (type L to list codes): 82
Changed system type of partition 4 to 82 (Linux swap / Solaris)

Command (m for help): p

Disk /dev/sda: 69.7 GB, 69793218560 bytes
255 heads, 63 sectors/track, 8485 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

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.
2.创建交换分区
mkswap /dev/hdb1
这里相当于mkfs,格式化分区并创建文件系统

3.在/etc/fstab中增加挂载条目:
/dev/hdb1   swap   swap   defaults   0 0

然后最好执行以下 partprob命令(个人经验)
4.激活交换分区
swapon -a
这里将所有/etc/fstab中的交换条目都开启

5.查看交换分区状态
swapon -s


第二种方法:
创建文件

1.构造系统文件
dd if=/dev/zero of=/swapfile bs=1024 count=102400
这里构建一个100M的系统文件

2.接下来与A中类似
mkswap /swapfile
增加交换条目:
/swapfile    swap    swap    defaults  0 0
swapon -a

3.swapon -s
此时可以看到刚刚添加的两个交换分区,其类型分别是partition和file.

所以如果你觉的你的swap不够,可以rm -rf原来的分区,然后在建个新的更大的分区
,或者是补充一个swap文件

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/18841027/viewspace-1061573/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
Oracle技术爱好者,Oracle10g OCM,网名 KUQLAN ,具有7的年Oracle数据库管理实践,曾经参加过BOSS、ERP、云计算(OpenStack+kvm)等项目的一线工作。以前写博客是为了自己,而现在是为了自己和别人。因为领会了帮助别人和分享、沉淀和积累会创造快乐和价值...

注册时间:2009-01-26

  • 博文量
    183
  • 访问量
    1681006