Operating System - Linux
1752557 Members
4571 Online
108788 Solutions
New Discussion юеВ

how i create swap partition

 
hany elromany
Advisor

how i create swap partition

hi
can you tell how i can create/add swap partition
for RedHat Linux for OS already install.
i need step to create
regards
hany
6 REPLIES 6
Frank de Vries
Respected Contributor

Re: how i create swap partition

use something like resize2fs to shrink a partition and add it in.

I'd suggest trying to make the space as far back in the drive as possible as things like grub may be referencing a /boot partition quite far back too, depending on where you personally placed it. IF you can shrink the end one and tg it at teh very back, even better.

This shouldn't be too much of a problem though as FC4 loves using ext2 fs labels in /etc/fstab meaning rahter than referencing a partition by it's location, it looks on all partitions on all devices for a certain name. meaning if it's partition id changes (e.g. hda6 becomes hda7) then it probably won't care anyway.

So once you have free space, create a partition with fdisk then format it with "mkswap /dev/hda{b]X[/b]" then just use "swapon" to load it. if it loads fine, stick an entry in /ets/fstab to permanntly mount it on boot.
Look before you leap
Ivan Krastev
Honored Contributor

Re: how i create swap partition

See this doc from RedHat - http://kbase.redhat.com/faq/docs/DOC-1133

regards,
ivan
Nuwan Alwis
Valued Contributor

Re: how i create swap partition

Hi Hany,
The command to do the thing is "mkswap"
you can create a swap partition on a block device(/dev/sdax) or even on a file and no need of reboot or down time is required.

if you are to use a swap file insted of raw partition use "dd" to create a file before use "mkswap" on that file
eg:
dd if=/dev/zero of=/"path & name swap file" \
bs=1024 count="how many of 1024s to file"

once this is done you can use "mkswap" on the file you crated

Most important thing is after crating a swap device or file to tell the OS to use that file or device you have to run
"swapon -a"

please read the man page for mkswap for more info

Good Luck..!

skt_skt
Honored Contributor

Re: how i create swap partition


This scenario is only applicable when LVM is supported


├в ┬в Create an LV on the appropriate VG
#lvcreate -L 5000 /dev/vg00

├в ┬в Enable the swap on the LV created
#mkswap /dev/vg00/lvol12

├в ┬в Activate the swap on the LV
#swapon /dev/vg00/lvol10

├в ┬в Update the fstab



If vg00 is comprised of only 1 disk (or 2 if you are mirrored) then spreading multiple swap areas out over the same disk is dumb. Consider that you have 4 swap volumes on the same disk at equal priority to spread the i/o evenly. As the paging activity spreads the swap across these 4 lvols, the heads will be moving like crazy because all of this is occurring on the same physical disk. If you do have multiple swap areas on the same disk then you want to assign them different priorities so that one will be completely used before the next one is used at all. Only in the case where swap is spread over multiple physical disks would you set the priorities the same.

So that is why priorities are kept different.

#swapon -s
Filename Type Size Used Priority
/dev/vg00/lvol8 (deleted) partition 2097144 2095220 -1
/dev/vg00/lvol9 (deleted) partition 2097144 1157016 -2
/dev/vg00/lvol2 (deleted) partition 2097144 0 -3
/dev/vg00/lvol12 (deleted) partition 5119992 0 -4



Taifur
Respected Contributor

Re: how i create swap partition

Hi Hany

For swap area give at least twice computer memory size, ex. +512M.

The steps are as follows,

Default partition type is LINUX native, to change a Linux partition to a swap partition with fdisk:
l # show partition
t 1 # change partition type for partition 1
Hex code: 82 # set type to Linux swap
w # write partition table
The new swap partion is set using the below listed commands to create and enable the swap partition.
# mkswap -c /dev/hda2 size_in_blocks
# swapon /dev/hda
To enable all swap partitions:
# swapon -a
Check swap space usage with /usr/bin/top, /usr/bin/free and defined partitions with /sbin/swapon (see Section 10.4) as follows:
$ /sbin/swapon -s
Filename Type Size Used Priority
/dev/hda5 partition 2048248 0 -1
/dev/hda6 partition 2048248 0 -2
Finally add the new swap partition to /etc/fstab:
/dev/hda14 / ext2 defaults 1 1
/dev/hda1 /boot ext2 defaults 1 2
/dev/hda13 /home ext2 defaults 1 2
/dev/cdrom /mnt/cdrom iso9660 noauto,owner,ro 0 0
/dev/hda5 swap swap defaults 0 0
/dev/hda6 swap swap defaults 0 0
/dev/fd0 /mnt/floppy ext2 noauto,owner 0 0
none /proc proc defaults 0 0
none /dev/pts devpts gid=5,mode=620 0 0
#
nodea:/fsa /fsa nfs rw,soft,bg 0 0
nodea:/fsb /fsb nfs ro,soft,bg 0 0

N.B. With RH7.x file systems in /etc/fstab are listed by label instead of using partition number, in the above example /etc/fstab entry /dev/hda1 for the /boot file system, is mapped to LABEL=/boot for RH7.x.

https://help.ubuntu.com/community/SwapFaq#head-75ffcb00cefe143fc380f84d7ea9203f16a596d0

RGds//
Taifur
Steven E. Protter
Exalted Contributor

Re: how i create swap partition

Shalom,

http://www.vglug.info/swap-partition-and-swap-file-rhel-4

http://forums11.itrc.hp.com/service/forums/bizsupport/questionanswer.do?threadId=1046206

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com