Need to move the swap partition to another disk

My ubuntu installation and swap file are on the same disk (160.0 GB).

I would like to move the swap file on the little disk /dev/sda
Thank you for your help

linux@linux-desktop:~$ sudo fdisk -l
[sudo] password for linux:

Disco /dev/sda: 40.0 GB, 40020664320 byte
240 testine, 63 settori/tracce, 5169 cilindri
Unità = cilindri di 15120 * 512 = 7741440 byte
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Identificativo disco: 0x28f128f0

Dispositivo Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        5169    39077608+   7  HPFS/NTFS

Disco /dev/sdb: 160.0 GB, 160041885696 byte
255 testine, 63 settori/tracce, 19457 cilindri
Unità = cilindri di 16065 * 512 = 8225280 byte
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Identificativo disco: 0x6540b330

Dispositivo Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1       17643   141717366    7  HPFS/NTFS
/dev/sdb2           17644       19458    14569473    5  Esteso
La partizione 2 non termina al limite del cilindro.
/dev/sdb5           17644       19376    13911040   83  Linux
/dev/sdb6           19376       19458      657408   82  Linux swap / Solaris
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

1. sudo swapoff

2. gksudo gedit /etc/fstab
Delete the line related to the swap partition i.e. /dev/sdb6
Save and close.

3. sudo fdisk /dev/sda
Create the swap partition on this drive( say the partition is /dev/sda2 ). Please note that if you delete the existing partition & create new ones on /dev/sda, you will lose existing data!

4. sudo mkswap /dev/sda2
(Replace /dev/sda2 with the partition you created in step 3 )

5. gksudo gedit /etc/fstab
Add a line at the end of this file, as below:
/dev/sda2  none  swap  sw  0 0
Save and close.

6. Now run the command
sudo swapon -a

Everything should work fine.
Please note:
a. Replace /dev/sda2 in steps 4 and 5 with the partition you created in step 3
b. Changing partitions may sometimes cause your computer to stop booting, so be very careful while modifying partitions.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
farioAuthor Commented:
So the first step is to shrink the /dev/sda partition to create unallocated free space (i don't want to delete existing partition) ?
That's not a linux boot partition but it is the XP boot disk; Linux is on /dev/sdb

i have grub2 at boot. do you think that changing the partitions setup will compromise my system ?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux Distributions

From novice to tech pro — start learning today.