`
yangzhiyong77
  • 浏览: 969038 次
文章分类
社区版块
存档分类
最新评论

swap配置小结

阅读更多

1. 通过新增分区扩展swap:

1.01 查看swap大小

[root@rhel6-server pub]# free -m

total used free shared buffers cached
Mem: 487 422 65 0 21 109
-/+ buffers/cache: 291 196

Swap: 499 0 499

1.02 查看当前swap使用了哪些设备

[root@rhel6-server pub]# swapon -s
Filename Type Size Used Priority

/dev/sda5 partition 511992 608 -1

1.03 创建一个新的分区用来扩充swap

[root@rhel6-server pub]# fdisk -cu /dev/sda

Command (m for help): p

Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders, total 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000cb393

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 41371647 20480000 83 Linux
/dev/sda3 41371648 45467647 2048000 83 Linux
/dev/sda4 45467648 209715199 82123776 5 Extended
/dev/sda5 45469696 46493695 512000 82 Linux swap / Solaris

Command (m for help): n
First sector (46495744-209715199, default 46495744):
Using default value 46495744
Last sector, +sectors or +size{K,M,G} (46495744-209715199, default 209715199): +100M

Command (m for help): p

Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders, total 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000cb393

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 41371647 20480000 83 Linux
/dev/sda3 41371648 45467647 2048000 83 Linux
/dev/sda4 45467648 209715199 82123776 5 Extended
/dev/sda5 45469696 46493695 512000 82 Linux swap / Solaris
/dev/sda6 46495744 46700543 102400 83 Linux

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): p

Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders, total 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000cb393

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 41371647 20480000 83 Linux
/dev/sda3 41371648 45467647 2048000 83 Linux
/dev/sda4 45467648 209715199 82123776 5 Extended
/dev/sda5 45469696 46493695 512000 82 Linux swap / Solaris
/dev/sda6 46495744 46700543 102400 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 or after you run partprobe(8) or kpartx(8)

Syncing disks.

1.04 激活分区

[root@rhel6-server pub]# partx -a /dev/sda
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
BLKPG: Device or resource busy
error adding partition 4
BLKPG: Device or resource busy
error adding partition 5
[root@rhel6-server pub]# cat /proc/partitions
major minor #blocks name

8 0 104857600 sda
8 1 204800 sda1
8 2 20480000 sda2
8 3 2048000 sda3
8 4 1 sda4
8 5 512000 sda5

8 6 102400 sda6

1.05 格式化成swap分区

[root@rhel6-server pub]# mkswap /dev/sda6
Setting up swapspace version 1, size = 102396 KiB

no label, UUID=46bdaf51-2f2a-4a98-a0b7-fd023f54195a

1.06 启用swap分区

[root@rhel6-server pub]# swapon /dev/sda6

1.07 验证swap容量是否扩展

[root@rhel6-server pub]# free -m
total used free shared buffers cached
Mem: 487 426 60 0 22 111
-/+ buffers/cache: 292 195

Swap: 599 0 599

1.08 验证扩展的swap设备

[root@rhel6-server pub]# swapon -s
Filename Type Size Used Priority
/dev/sda5 partition 511992 596 -1

/dev/sda6 partition 102392 0 -2

1.09 调整swap设备的优先级(数值越大越优先,可以通过man swapon搜pri验证),swap优先级只能在挂载时指定

[root@rhel6-server pub]# swapon -p 1 /dev/sda6
swapon: /dev/sda6: swapon failed: Device or resource busy
[root@rhel6-server pub]# swapoff /dev/sda6
[root@rhel6-server pub]# swapon -p 1 /dev/sda6
[root@rhel6-server pub]# swapon -s
Filename Type Size Used Priority
/dev/sda5 partition 511992 596 -1
/dev/sda6 partition 102392 0 1
1.10 添加到fstab实现启动自动挂载

[root@rhel6-server pub]# vim /etc/fstab
/dev/sda6 swap swap defaults,pri=1 0 0
[root@rhel6-server pub]# swapoff /dev/sda6
[root@rhel6-server pub]# swapon -s

Filename Type Size Used Priority
/dev/sda5 partition 511992 584 -1
[root@rhel6-server pub]# swapon -a
[root@rhel6-server pub]# swapon -s
Filename Type Size Used Priority
/dev/sda5 partition 511992 584 -1
/dev/sda6 partition 102392 0 1



2. 通过文件扩展swap

与通过分区扩展swap相比,不用创建分区,以文件代之

dd if=/dev/zero of=/swap.img bs=1M count=100

mkswap /swap.img

其他步骤完全与分区扩swap一致。


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics