I've been setting up a spare computer so that I can cross-compile system images for various platforms I have. The spare computer really isn't all that powerful, but I have zero issue with just leaving it to churn away until it's done (maybe I should have a beowulf cluster made from my old scrap), so I'll be compiling OpenWRT, Android (hahaha ... aaah.. oh dear) and U-Boot images.
I also used it as an opportunity to learn more about Debian, so after installing Jessie I pushed it further and installed Unstable which means we have access to more packages, such as being able to install packages from multiple architectures (such as armhf) using packages maintained for Debian (hopefully).
So I encountered a problem where by my swap partition is too small, it's set to 4gByte and my system RAM is also 4gByte - enter a problem when compiling Android which requires 16gByte to compile. Bum.
I learned of a solution which is to create a swap file, as this was temporary and I did not want to re-size the swap partition in Linux. Swapping, if you don't know, is when you don't have enough RAM in your computer, so it copies the contents to your hard drive instead (RAM being significantly faster than your hard drive) which means that it'll still operate properly but it'll slow down, a lot. This is actually one of the more frequent complaints about Microsoft Windows with computers supplied by your company's IT Support or purchased from the store - the fact that you often have significantly less RAM than you require so it hammers the swap/pagefile.
With creating a swapfile I had to do the following:
- Create the file
- Make it recognised as swap
- Mount the file
To create the file, a lot of people and tutorials may recommend that you use 'dd', but this can be slow (like really stupidly slow) so instead I used 'fallocate' which instead of filling the amount of space required with data, or zeroes, preallocates the blocks and marks them as uninitialised.
sudo fallocate -l 20G /extraswap
We specify the length with "- l" and in this case I set it to twenty gigabytes and I put the swapfile in root, because I couldn't think of somewhere better and I'm lazy. I discovered later through trial and error that we want this to now be seen as a swap file (by that I mean it needs a header) and to do that we mkswap!
sudo mkswap /extraswap
Still not done, we have a choice, before it can be activated the permissions should be changed because otherwise it will complain at us:
sudo chmod 0600 /extraswap
Now I had a choice. Either I activate the swap temporarily and only use it when I need it, or I have it activated from system boot.
At the very least I tested to see if it was ok:
sudo swapon /extraswap
Since I'm using Debian Unstable/Sid the system has switched from SystemV to Systemd - "What's the difference?" is a big contentious topic right now, let's just say it's moving away from Keeping it Simple, Stupid and moving towards abstraction. For now, we can still edit fstab!
sudo vi /etc/fstab
And in fstab, we add the following line ("but how do I use vi?"):
/extraswap none swap sw 0 0
And 'Ding!' the swap file should be mounted the next time the system boots, automagically.
Top Comments