59

In order to save disk space, I want to have two OS installations share a single swap partition (a dual-boot). Is this a good idea?

11
  • Get more ram, it's cheap, don't use swap, it'll help you with that IO issue. I realize this might not be feasible, but gone are the days where you must have swap. Jan 11, 2011 at 10:10
  • 3
    @xeno if u dont have swap, u lose Suspend ability
    – tshepang
    Jan 11, 2011 at 11:04
  • 3
    I don't use that, so... yeah I don't use that. Jan 11, 2011 at 11:11
  • 1
    @xenoterracide disks are also cheap, and oomkiller behave strangely.
    – shellholic
    Jan 11, 2011 at 11:16
  • 2
    @xenoterracide I like your optimistic point of view, but I will continue to have swap partitions because I like safety nets. Just change your swapiness to 0.
    – shellholic
    Jan 11, 2011 at 11:20

3 Answers 3

46

It's possible. In fact, you can share the swap space between completely different operating systems, as long as you initialize the swap space when you boot. It used to be relatively common to share swap space between Linux and Windows, back when it represented a significant portion of your hard disk.

Two restrictions come to mind:

  • The OSes cannot be running concurrently (which you might want to do with virtual machines).
  • You can't hibernate one of the OSes while you run another.
6
  • If you try to boot into an OS when another is hibernated, will it be not possible or will it boot but the hibernation data get corrupted? I thinking that it may refuse to boot due to some logic in grub or something like that.
    – paradroid
    Dec 18, 2020 at 16:54
  • 1
    @paradroid I don't think grub knows anything about hibernation. If you boot an OS while another OS is hibernated, it's safe provided that no filesystem is mounted by both OSes. If a filesystem is mounted by the hibernating OS and you mount it in the other OS, expect massive corruption. Dec 19, 2020 at 20:02
  • Thanks. Well I'm wondering what would happen if an ext4 disk is shared with a Linux OS and Windows WSL, as Windows actually partially hibernates when it is 'Shut Down', so I am not sure if the second disk will still be mounted in that case, but this is a Windows issue...
    – paradroid
    Dec 21, 2020 at 8:53
  • @Gilles'SO-stopbeingevil' From your above comment and answer, if I only share a Data partition between the 2 operating systems. Do you think that it can lead to corruption of data when hibernated on one OS and booted to another?
    – Porcupine
    Apr 12 at 3:02
  • @Porcupine Yes. Never use a partition that's mounted by a hibernating system. It's only safe if you unmount that partition before hibernating. Apr 12 at 8:37
25

One side effect I can think of is:

  1. Hibernate system1 (using the swap partition for hibernation).
  2. Boot system2.

You could lose data.

1
  • 11
    Murphys law suggests that if you do this, you will one day forget, you will hibernate an OS, or boot it into a VM, and you will hose your system, and possibly data. Simple truth - disk space is dirt cheap, your data and work is probably not. Unless you are needing terabyte's of swap space for each OS, just make separate ones. Jan 11, 2011 at 9:57
9

One of my friends tried this. He has installed five or six distributions in a single hard drive.

The first primary partition is for GRUB, and he is able to boot to all the distributions. The second partition is swap. The third partition is an extended partition and each of the distributions are installed into their own logical partitions.

All of the distributions are able to boot and can hibernate. I think you just need to make sure and select the correct distribution after resuming from hibernation.

So, on the basis of his experiment I should say YES this is possible, but I think it can break things. What if distribution 2 wakes up and distribution 1's resume file is using up the swap partition; what's the next thing that's going to happen?
So I, too, agree with all the above posts. Why don't you try to split the swap partitions, rather than taking this huge risk?

6
  • check the question again: "is it a good idea?" VS "is it possible"
    – tshepang
    Jan 11, 2011 at 14:39
  • this also means you are essentially repeating what @shellholic said
    – tshepang
    Jan 11, 2011 at 14:43
  • @Tshepang: I was actually thinking from the point of its possibility. Its my mistake. Will edit the answer appropriately. Jan 11, 2011 at 14:50
  • Before you respond, check the other answers, to ensure you don't repeat what they said.
    – tshepang
    Jan 11, 2011 at 14:54
  • I never actually Suspend. I really wanted to know if there were other issues I wasn't thinking of.
    – tshepang
    Jan 11, 2011 at 15:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .