0

My question is related to a problem that occurs with SSD drives: it's commonly known that these drives wear out quickly; they have a limited amount of write cycles. So writing a few Gigabytes large file to it every time the system is hibernating is not what I want.

A question that arises is - is it possible to force the system to write that file to a different drive?

For those in doubt I would like to know how to achieve this without moving the swap data to a different partition. I want the swap data to stay on SSD to benefit from the higher performance during runtime and move/set the hibernation data/file only to HDD to avoid writing to SSD when hibernating.

Seth
  • 58,122
luke1985
  • 149
  • 1
  • 2
  • 9
  • Uhm, sure that's possible. Ubuntu hibernates to its swap file/partition. So if you have that partition or the partition containing the files on a HDD and not you SSD, it will be written there. Look into general partitioning/installing guides. – Byte Commander Oct 31 '15 at 16:01
  • @ByteCommander I know this - the problem is I want to keep the swap data separated from the hibernation data. – luke1985 Oct 31 '15 at 16:07
  • Then please [edit] your question and ask for that. Or delete it and ask a new one to get rid of the negative score. That's actually a pretty interesting question, I think. – Byte Commander Oct 31 '15 at 16:09
  • @ByteCommander Do you perhaps have an idea how should I entitle a new question? – luke1985 Oct 31 '15 at 16:22
  • @ThomasW. Pretty good idea. Actually I cant ask a new question so I've edited current one. Perhaps someone will be able to shine some light on the topic,. – luke1985 Oct 31 '15 at 16:36
  • But swap wears your SSD drive out much faster than hibernation would do. Better get another RAM brick and put the swap and hibernation onto the HDD. SSDs are still significantly slower than RAM. – Byte Commander Oct 31 '15 at 16:53

1 Answers1

1

What you're asking for is impossible using your current setup:

You have a swap partition and that's where the hibernation goes. Ubuntu is not Windows with a separate Hibernation file that takes up additional space on your hard disk.

However, if you change your set-up and start using 2 swap files instead of just one swap partition, you can fool the system to swap to HDD instead of SSD just prior to hibernation by activating the HDD swap and deactivating the SSD swap file.

Is this a good idea? No, because using the swap file on your SSD will wear out the SSD much more then the simple fact of hibernation...

But anyway, that's what you asked for and that's what you'll get:

  1. Create 2 new swap files. Have a look here for the size if you've got more then 1GB of RAM. In the below example sda is the SSD and sdb the HDD.

    dd if=/dev/zero of=/dev/sda/szMountPoint/SSDSwapFile bs=1024 count=iSizeInKBytes
    dd if=/dev/zero of=/dev/sdb/szMountPoint/HDDSwapFile bs=1024 count=iSizeInKBytes
    

    where szMountPoint is the string denominating the mount point you want the file to be and iSizeInKBytes is the size.

  2. Now activate both swaps:

    mkswap --check --label SSDSwap /dev/sda/szMountPoint/SSDSwapFile
    mkswap --check --label HDDSwap /dev/sdb/szMountPoint/HDDSwapFile
    
  3. Remove your existing swap partition from fstab

  4. Reboot.

Now you have 2 swap files that you can activate/deactivate with the commands swapon and swapoff and you can control everything you want including hibernating to the HDD!

Freebie

Have a look here on how to optimise your SSD to have it wear out less (example is for a USB stick, but the parameters are good for an SSD as well)

Fabby
  • 34,259
  • 1
    Thank you for the answer. Actually yesterday I've figured out that I wont use swap for applications (by setting the swappines to 0 and not going beyond my 4GB RAM) so just setting swap to HDD will solve the problem, not to mention that the hibernation doesn't work on my PC in Ubuntu - in the first place. – luke1985 Nov 01 '15 at 08:28
  • @luke1985 By setting the swappines to 0, it'll take a lot of time to actually swap out by the time the kernel needs the swap an it'll look like your computer is freezing. Read again items 4 and 5 in the other answer... Highly optimized! ;-) – Fabby Nov 01 '15 at 09:22
  • Yes, but only If I go beyond the RAM capacity, and I wont. – luke1985 Nov 01 '15 at 12:23
  • 1
    @luke1985 I normally don't either but it's happened twice in the first six months I set the swappiness to 0. Since I set it to 10 together with the other parameters, I haven't noticed yet! – Fabby Nov 01 '15 at 23:20