Wednesday, June 8, 2011

Creating Swap

Creating swap thru disk partition

[root@rhel02 ~]# free -m
total used free shared buffers cached
Mem: 997 254 743 0 2 114
-/+ buffers/cache: 137 859
Swap: 2015 0 2015

Create the disk partition
[root@rhel02 ~]# parted /dev/sdb
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mkpart
Partition type? primary/extended? primary
File system type? [ext2]? linux-swap
Start? 0
End? 200
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? Ignore
(parted) pr
Model: VBOX HARDDISK (scsi)
Disk /dev/sdb: 524MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number Start End Size Type File system Flags
1 512B 200MB 200MB primary linux-swap(v1)

Initialize the disk partion
[root@rhel02 ~]# mkswap /dev/sdb1
Setting up swapspace version 1, size = 195308 KiB
no label, UUID=364ca39e-dc67-4f8d-9790-e2715425d248


Add the newly created swap
[root@rhel02 ~]# swapon /dev/sdb1
[root@rhel02 ~]# swapon -s
Filename Type Size Used Priority
/dev/dm-1 partition 2064376 0 -1
/dev/sdb1 partition 195304 0 -2
[root@rhel02 ~]# free -m
total used free shared buffers cached
Mem: 997 262 735 0 6 115
-/+ buffers/cache: 140 856
Swap: 2206 0 2206


Creating swap thru a swapfile(example 200mb of swapfile)
[root@rhel02 ~]# dd if=/dev/zero of=/tmp_swap/swapfile bs=1024 count=204800
204800+0 records in
204800+0 records out
209715200 bytes (210 MB) copied, 29.5354 s, 7.1 MB/sd

[root@rhel02 ~]# mkswap /tmp_swap/swapfile
mkswap: /tmp_swap/swapfile: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 204796 KiB
no label, UUID=5d77de02-b28f-43a1-9410-fed6d05172c4d

[root@rhel02 ~]# swapon /tmp_swap/swapfile
[root@rhel02 ~]# swapon -s
Filename Type Size Used Priority
/dev/dm-1 partition 2064376 0 -1
/dev/sdb1 partition 195304 0 -2
/tmp_swap/swapfile file 202288 0 -3
[root@rhel02 ~]# free -m
total used free shared buffers cached
Mem: 997 491 505 0 11 315
-/+ buffers/cache: 164 833
Swap: 2404 0 2404

Remove swap
[root@rhel02 ~]# swapoff /tmp_swap/swapfile
[root@rhel02 ~]# swapoff /dev/sdb1
[root@rhel02 ~]# swapon -s
Filename Type Size Used Priority
/dev/dm-1 partition 2064376 0 -

No comments:

Post a Comment