Setup your swap partition a flash card in Debian linux

Jul 20th, 2012 | By | Category: Linux / Freebsd

*A WORD TO THE WISE – DO NOT ATTEMPT THIS*

Flash cards are not designed to handle heavy loads of tiny read/writes all the time and will fail sooner rather than later.. I just had my system go into the shitty with a syslog filled with 1000’s of messages like this:  [59443.104957] Write-error on swap-device (8:16:512616) because of having my flash on a flash card.  Obviously if you really want to try this then go ahead but you’ve been warned, it’s a bad idea

Sooo, I’ve heard some performance gains about this although overall I would say they are probably in all likelyhood negligible.  That and apparently after a year of heavy read/writting your flash card is going to be toast so keep that in mind before you run off to do this.  However if you are like me and you just have this god damn itch in you to be different in every way possible then you probably want to setup your flash card here as a swap drive.  I know I do!

When do you actually want to do this?

Well the main time you are going to see a performance boost from this is when your hard drive is just read/writing like a motherfucker.  This is probably only going to occur at a level where having a flash card swap drive would be a big bonus on production web servers  where we are seeing 10’s of thousands of hits per hour with everythign being logged, caches being served, etc etc.  For home use, probably not going to make a difference.  The other time would be if you have zero disk space left, although in all honesty I would keep the flash card as an ntfs for moving files around easily and do the swap on the hard drive but the more and more I talk about this the less and less I want to do it so here’s how you can go about doing it.

    Plug-in the flash drive.
ii>                 Linux shall automount the drive. Then you have to unmounts it
Sudo  unmounts /media/”usbdisk”
iii>                Now find the usb device in the terminal using the command
Sudo df –h    [it will be something like /ev/sda1 or /dev/sdb2 etc. I am considering /dev/sda1 here]
iv>               Sudo mkswap /dev/sda1 [creating the swap at the /dev/sda1 flash drive]
v>                 Sudo swapon –p 32767 /dev/sda1 [-p is to activate a partition and not a file. Anf the number 32767 is the priority number. Linux processes support a priority range of 0-32767. 0 being the min priority and 32767 being the highest]
Ok. The flash drive is now working as a swap partition.
It’s better to format the flash drive in exfat file system [specially ext4]  as the swap partition works best on that file system.  Or in linux you have the option to format it as a swap parition which is what I’ve done and it seems to be working out alright.
To verify the swap partition being operational type the following code on terminal
                Cat /proc/swaps
If the swap partition is active, then it will be shown on the output list along with the dedicated hard drive swap partition(s).
To it off type this code on terminal
                Sudo swapoff /dev/sda1 [/dev/sda1 here is the flashdrive as detected in step 3]
In case you are wondering this will be in effect after you reboot so there’s nothing further that needs to be done from what I can tell.  Enjoy your new partition!

[59443.104957] Write-error on swap-device (8:16:512616)

Tags: , , , , ,

Leave a Comment