Linux HOWTO: Add Temporary File to Swap
Scenario: a Linux system with two drives. The system was built with resiliency as a priority, but availability is not critical. So, the filesystems were mounted atop md raid1 for resiliency, and the swap was striped across an md raid0 for performance.
One disk failed and was removed from the system. System returns to service on remaining drive until RMA is completed. Users are informed that the system is available but does not have swap space. Consensus is reached to add some temporary swap space via a swapfile.
Figure 2GB, space is available in /tmp. Check the man pages, and make notes. First, how much is 2GB?
> bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty’.
1024*1024*2
2097152
quit
Next, create a file of the appropriate size, mkswap, and swapon:
# dd if=/dev/zero of=/tmp/tmpswap bs=1024 count=2097152
2097152+0 records in
2097152+0 records out
2147483648 bytes (2.1 GB) copied, 21.552 seconds, 99.6 MB/s
# mkswap /tmp/tmpswap 2097152
Setting up swapspace version 1, size = 2147479 kB
# swapon /tmp/tmpswap
# swapon -s
Filename Type Size Used Priority
/tmp/tmpswap file 2097144 0 -1
Note: I like to think we don’t need to pass the size to mkswap, and it will just use the entire file. I figured I’d play it safe, like these notes.
RMA and subsequent maintenance involve a system reboot, so this swap space will go away. I figure that if we want to swapoff while the system is running, it is simply:
# swapoff /tmp/tmpswap
# rm /tmp/tmpswap
Response
Brian
Rather than striping swap space (which is generally overkill), a nice way to go about it is to create a swap partition on each disk and mount them all with pri=0 (man swapon, check out –p ). The kernel will round-robin the swap files, so you have some pseudo-striping going on, yet a drive failure won’t leave you without any swap.
Post a Public Comment
Danny Howard is 100% responsible for the content on this site, except some of it is stolen.
All rights are reserved, unless otherwise noted. Generally, I'm a BSD guy, so you can assume implicit permission to adapt, modify, and redistribute my intellectual property with appropriate attribution. Except some of this content is itself re-appropriated, so you'd best ask first, especially for commercial use. Thanks!
You can contact me via e-mail: dannyman@toldme.com
Most of http://dannyman.toldme.com/ is powered by WordPress.
If you're hip to RSS and whatnot, you can subscribe to this site.
These links are for dannyman: login AND backlinks