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
LVL 1
farioAsked:
Who is Participating?
 
arpitsudCommented:
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.
0
 
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 ?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.