ianw1974 Posted May 24, 2006 Report Share Posted May 24, 2006 What do you do if you need additional swapspace? Or you forgot to create a swap partition before you allocated it all to other Linux partitions when installing? Don't want to repartition to add the swap space? Or just have a real need for additional swap space temporarily or permanently? Well, here is how you can easily create additional swap space either temporarily or permanently without having to screw around resizing partitions or reinstalling your system: First, we need to create a file to use for the swap space: dd if=/dev/zero of=/mnt/swapfile bs=1024 count=1024000 this will create a file called /mnt/swapfile with block size of 1024 and 1GB in size for 1GB of swap. Now, after this has been created, you need to activate it: mkswap /mnt/swapfile swapon /mnt/swapfile to check it's working: free will show the swap space is now available on your system, either in addition to the swap space you had originally or will just show what you just created. To make sure it is mounted each time you boot, add this line to /etc/fstab: /mnt/swapfile swap swap defaults 0 0 and you're done! Whilst the ideal method might be to repartition and create a specific partition for swap, this could work well in some respects. Unsure if there is a performance hit for using a file instead of true swap space, but still a relatively good and easy method to do it quickly and simply without changing too much stuff. Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted May 25, 2006 Report Share Posted May 25, 2006 This is a great tip. I do have one question, though. Does anyone really need a whole gig of swap space? (I know yours was probably just an easy example.) Quote Link to comment Share on other sites More sharing options...
tyme Posted May 25, 2006 Report Share Posted May 25, 2006 swap space is supposed to be twice your available RAM. However, as I understand it, if you have over 1GB of RAM, swap space becomes somewhat unnecessary. Quote Link to comment Share on other sites More sharing options...
ianw1974 Posted May 25, 2006 Author Report Share Posted May 25, 2006 I thought I would list 1GB as an example, purely so you could then work out other sizes, such as 512MB or anything after that. Purely for ease, as you noticed :P Of course, once you've done the dd command, you can easily check to make sure you got your count value correct, as this is what sets the size of the file. A quick: ls -l /mnt would let you see if it makes 512MB or 1GB or whatever you happened to enter here. Red Hat always recommend double your ram, regardless, or at least in their exams as I've recently found when studying. However, of course, we all know that depending on your requirements/configuration, etc, you wouldn't necessarily need to follow this rule always. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.