1

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
  • 59,332
luke1985
  • 159

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
  • 35,017