Operating System - Linux
1828788 Members
2811 Online
109985 Solutions
New Discussion

Re: how to create a new swap partition on a new hdisk

 
SOLVED
Go to solution
Anh-Thu Tran
Frequent Advisor

how to create a new swap partition on a new hdisk

We are running out the swap space in our box, but no more space to create addition swap partition. Therefore, we added the new hdisk for more space. How I create additional swap partition on the new hdisk? Should I leave the current swap partition un-touch? Thansk.
9 REPLIES 9
George Liu_4
Trusted Contributor

Re: how to create a new swap partition on a new hdisk

Yes. You can leave the original swap device as it is.

You need to set up the second swap device on the new added disk. Usually use fdisk to complete this step
Next add the new swap partition on /etc/fstab

The new swap should be seen after the system is rebooted
Alexander Chuzhoy
Honored Contributor
Solution

Re: how to create a new swap partition on a new hdisk

After creating the partition with fdisk you need to make sure that its type is swap (id 82).
Then (if for example the created partition is /dev/sdb1) you need to do:
mkswap /dev/sdb1

and to activate:
add respective entry to /etc/fstab and
swapon -a or simply reboot
Stuart Browne
Honored Contributor

Re: how to create a new swap partition on a new hdisk

My question is.. Running out of swap ?!

How much memory is in that machine that you're running out of swap ?!?
One long-haired git at your service...
Andrew Cowan
Honored Contributor

Re: how to create a new swap partition on a new hdisk

Anh-Thu,

Make sure that you do NOT create a second swap partition on the same physical hard disk as this will cause the disk to thrash, greatly reduce performance, and possibly damage the disk.
Heironimus
Honored Contributor

Re: how to create a new swap partition on a new hdisk

Actually it's fine to create multiple swap partitions on the same physical drives, but you would want to explicitly set them all to different priorities so they'll be used sequentially. If they're all the same priority the OS tries to round-robin across them, which does cause thrashing and increased wear on a single drive.
Ivan Ferreira
Honored Contributor

Re: how to create a new swap partition on a new hdisk

I disagree with Andrew.

>>> Make sure that you do NOT create a second swap partition on the same physical hard disk as this will cause the disk to thrash, greatly reduce performance, and possibly damage the disk.

In the past, Linux was not able to handle swap partitions larger than 2 GB and you have to create several partitions of 2 GB on the same disk for the swap to be accroding with your RAM.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Andrew Cowan
Honored Contributor

Re: how to create a new swap partition on a new hdisk

I think I should have clarified (thanks to Heironimus) as you can indeed set priority, however as he correctly points out the default behaviour is to round-robin/stripe, and this is what causes the disk thrashing.

As for the paging space limitation I think that there are two separate points there and I would still recommend putting them on multiple disks, since, correct me if I'm wrong, even a lower priority swap device could be in use at the same time as another, if it were to be fully utilised.

Where possible for Windows, Linux, et al, I would always recommend if possible that you use more than one physical disk. One for the OS, and another for paging and data.

in any event I'm always happy when somebody disagrees, but we can all learn something :)
Alpha977
Valued Contributor

Re: how to create a new swap partition on a new hdisk

Hello!

In the past, i have installed Fedora and Debian on the same computer but in two different disks.
I have created the swap partition of one linux distro on the disk of other distro.

This only for the performance.
So, i used GParted, a free Linux LiveCD distro.
http://gparted.sourceforge.net/
It work like Partition Magic.
Good for work the partitions.

Regards
Heironimus
Honored Contributor

Re: how to create a new swap partition on a new hdisk

Yes, a lower priority swap device can be used at the same time as a higher-priority device if the higher-priority device is (or was at a previous time) full. The first block of a device can also be in use at the same time as the last block. All you can really do is try to reduce the chances of that type of contention.

Is it better to spread things across multiple drives? Usually. Is it necessary? Usually not. That means the real question becomes: is it practical? My experience has been that it usually isn't, for one simple reason - most of the systems large enough for me to worry about it have used some kind of array storage that distributed the I/O better than I could have.