1830225 Members
1699 Online
109999 Solutions
New Discussion

Swap file

 
SOLVED
Go to solution
Ian Derringer
Regular Advisor

Swap file

Hi,
I've created this huge swap file for my Itanium server (24GB) and now I read that you were only supposed to create a 2GB swap file. I was wondering if I can create another 2GB swap file out on the SANs and delete the original swap file?? Please help!!

Thank you in advance.
Ian
10 REPLIES 10
Gopi Sekar
Honored Contributor
Solution

Re: Swap file


You can create any number of Swap files as long as there is hard disk space.

Create a new swap file by:
* dd if=/dev/zero of= bs=1m count=2048 (I believe it should work:)
* Make a swap file system out of it, 'mkswap '
* Add this swap to the kernel by 'swapon '

Now subsequent check to the memory (/proc/meminfo) should have this new swap memory also added to it.

Now coming to deleting the old swap file:
You have to unmount the swap file before that can be deleted, 'swapoff '. This will work only if that particular swap-file is not yet used by the kernel to swap.

Otherwise simply you can replace this swap-file entry in /etc/fstab with the new swap file (2GB swap file) and reboot the server, next time kernel will use only this new swap file and you can safely remove the old one.

Hope this helps,
Gopi
Never Never Never Giveup
Ivan Ferreira
Honored Contributor

Re: Swap file

See also my last recomendation here:

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=961656

And a swap file is different from a swap partition. You can have both.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Ian Derringer
Regular Advisor

Re: Swap file

Thanks so much for your replies. Fortunate for me, I do have a SAN attched to this server, which I will create another swap file and spread across the SAN for better IO. Please let me know if that's acceptable to your standard.

Again, thanks!!
Ivan Ferreira
Honored Contributor

Re: Swap file

You won't have another choice unless you are using LVM, or repartition the current disk, but that may involve backup and restore the filesystems on the partitions after the swap partition.

In Tru64 Unix Administration manual, the "recommendation" is to have swap devices locally, not in the SAN. (Will apply to Linux too).

But as swap space is almost never used, and should not be used, I think that won't be a problem.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Ivan Ferreira
Honored Contributor

Re: Swap file

Another choice is to convert that one big partition that you currently have for swap in a physical volume (LVM), in that pv create a volume group (VG), in the volume gropup create severales 2GB logical volumes (LV), use these logical volumes as swap.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Ian Derringer
Regular Advisor

Re: Swap file

You lost me there. How do I create a new swap partition within the Linux Gui interface?? Here are my steps or recommnded by previous users;
1. Create the new swap partition
2. Change the priority with the FSTAB
3. Reboot the server

Now, the server should be seeing the new swap partition by running a command "free" - Now, I can safely unmount the old swap partition as my heart desire.

I am correct on these steps??

Thank you you guys for all the help!!
John
Ivan Ferreira
Honored Contributor

Re: Swap file

I don't know a gui tool for configuring swap space. All I know is commands to do that.

First, partition the disk using fdisk or parted.

Then, set the partition type to swap.

Then use mkswap device

Activate the swap

swapon device

Edit fstab and add the new swap device.

If you tellme the device name, I can give you a more detailed instructions.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Ian Derringer
Regular Advisor

Re: Swap file

Unfortunately, I do not have any space on the hard drive to create another swap partition. Would you recommend creating a swap file on /var and then redo the original swap partition with smaller size?? The server attached to the SAN but I hate to put the swap partition out there permanantly. I also hate to have to create a swap file vs. swap partition, because the file can be easily corrupted.

What do I do?

Thanks!!
Ivan Ferreira
Honored Contributor

Re: Swap file

The option you proposed is valid. If your Linux version supports LVM, you have this choise also.

I will give you an example:

You currently have a swap partition right? Let's assume the following:

/dev/sda1 - boot
/dev/sda2 - 24GB swap (current)
/dev/sda3 - /
/dev/sda4 - /var

Create a new temporary swap in the SAN.

Create a new disk in the SAN, present to the host and configure as swap.

Set this new swap are in the fstab and remove the current. Reboot.

The old swap wont be used after reboot, so, do the following:

pvcreate /dev/sda2
vgcreate swapvg /dev/sda2
lvcreate -n swap1lv -L 2048M
lvcreate -n swap2lv -L 2048M
lvcreate -n swap3lv -L 2048M
lvcreate -n swap4lv -L 2048M
and so forth

Then run:

mkswap /dev/swapvg/swap1lv
mkswap /dev/swapvg/swap2lv
mkswap /dev/swapvg/swap3lv
mkswap /dev/swapvg/swap4lv
and so forth

Then edit fstab, remove the temporary swap area created in the san, and add the /dev/swapvg/swap*lv devices as swap devices.

Reboot.

In this way, using your current partition, you can create various partitions (logical volumes) without destroying any data.

Hope this helps.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Ivan Ferreira
Honored Contributor

Re: Swap file

Of course, if you have enough maintenance time, you can disable the actual swap by removing the entry from the fstab and rebooting the server, then issue the commands above. You don't really need a new temp swap partition.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?