GRUB recreate a partition before booting a certain OS

1

I am having a problem of managing the swap areas on my hard drive.

Side story:

Due to having only a few GiBs free on my C:\ partition, Windows regularly shrinks the pagefile (even though it is set to a fixed size in settings), which really annoys me. Especially because Windows complains about going out of memory, something it did on its own without asking me first or me allowing it...

I am having a question on this "side topic" here in case you have a few things to say about that.

I have the following setup:

  • sda1: C:\ - Windows 7, boot partition, pagefile, etc.
  • sda5: swap for linux
  • sda6: / - Linux's root
  • sda7: D:\ - Data and whatelse

Now the problem is that I have a 4 GiB swap partition and a 4 GiB page file, so in practice, 8 GiBs are allocated from my already-not-big-enough hard drive for mere swapping.

What I am searching for, and I couldn't find anything on this topic in the manuals, is a way to tell GRUB to somehow, essentially format a partition all the time I am booting an operating system.

So if I boot Linux, sda5 becomes a swap, and if I'm booting Windows, sda5 becomes an NTFS partition. In each cases, the booted operating system should allocate its swap area on the "newly created" partition.

And thus I'll end up only using the really used 4 GiB from my hard drive's space, because only one system runs at a time.

Before someone tries to suggest alternative options or possible errors, I would like to prompt a few things:

  • Upgrading my system is not an option (due to finances)
  • I have no problems with the boot becoming much slower due to this extra operation (slower boot is a great compromise if I finally get rid of the "out of memory" warnings)
  • I know that as we move to the outer edge of the disc, the peripheral velocity becomes smaller. I can reorder my partitions any time I want, regular backups are made.

The only fear I have is that noone ever before had such voluminous issue and that GRUB won't be capable of handling this.

Whisperity

Posted 2013-10-24T17:47:01.947

Reputation: 243

Answers

0

The short answer to your question is no.

What you can do is sacrifice a bit of speed to use a swap file instead of a partition. This will dynamically allocate space as needed.

A good guide for setting it up can be found here.

http://www.cyberciti.biz/faq/linux-add-a-swap-file-howto/

ChasingLogic

Posted 2013-10-24T17:47:01.947

Reputation: 126