4

To install various Linux distributions on the same physical machine, do I need to add a swap partition for each distribution, or one will suffice for all?

jobin
  • 27,708

3 Answers3

7

I assume you are asking about a swap partition.

Yes you can share a swap partition, but each time you install, the swap space will be reformatted. This will change the UUID of the swap partition and you will need to update /etc/fstab in each installed os.

sudo nano /etc/fstab

You will see an entry similar to:

UUID=cee15eca-5b2e-48ad-9735-eae5ac14bc90 none swap sw 0 0

List your partitions with

sudo blkid

and update fstab with the new UUID.

See https://help.ubuntu.com/community/Fstab

Panther
  • 102,067
  • 2
    If you encrypt /home or want to hibernate, then you cannot share, otherwise there should be no issue sharing one swap. – oldfred May 19 '14 at 20:49
  • 3
    Err... no, the UUID won't change. If it did I should had problems when I installed Ubuntu in my Debian system. – Braiam May 19 '14 at 23:46
  • @Braiam, indeed... the installer takes care not to change the uuid of a swap partition you reuse. – psusi May 20 '14 at 00:00
  • I suppose it depends on what OS one install then. I would not take for granted that all distros preserve the uuid. – Panther May 20 '14 at 02:46
  • @oldfred Can't see any major trouble with encryption and hibernation as long as you choose to boot the correct distribution. – bot47 May 20 '14 at 07:38
  • ... or just write the device file instead of uuid in /etc/fstab. – Jan Hudec May 20 '14 at 08:26
1

Maybe is solution to add swap like swapfile. You don't need partition for swap and each distribution have his swap.

Take space to make swap

dd if=/dev/zero of=/swapfile bs=1024 count=1048576

Count is size of swapfile

create swap file system

mkswap /swapfile

Turn on swap

swapon /swapfile

End at the end change /etc/fstab

sudo nano /etc/fstab

add line

/swapfile       none    swap    sw      0       0
2707974
  • 10,553
  • 6
  • 33
  • 45
0

Yes, but...

The big restriction if you share your swap across distros is that you will be unable to use hibernation/suspend-to-disk. This uses the swap space to store the current contents of RAM, and if you boot into one distro while another is hibernating, it'll clobber the hibernation information.

(Mixing hibernation and dual-booting is a bad idea in general, because the hibernated data may include cached information about the contents of the hard drive, and the actual contents of the drive may change if you boot into one OS while another is hibernated.)

Mark
  • 1,054
  • 1
  • 8
  • 12