Wednesday, August 5, 2009

Adding a swap device

Lets assume you upgrade you RAM from 1 GB to 2 GB. Since, the swap device is usually statically created during install-time and you'll probably be stuck with less swap space than the recommended figure. Then, you have 3 options
1) Who needs extra swap?
2) Make a swap file (simpler, but slower)
3) Extend the swap device.

For Approach 2, you can use the "dd" command to created a file of required size and then use it as a loop device.

Lets see the Third approach in detail.

Run "$sudo parted --list" to get a list of block devices attached to the system.
Use "parted /dev/sda resize <partition-number> <start> <end>"

"/dev/sda" is the HDD on my machine. Replace appropriately from the "parted --list"'s output.
Take the "partition-number" from the "parted --list" command's output. Use the swap device's partition number. Adjust the start end as you wish (can be specified in MBs.. eg. parted /dev/sda resize 5 5000M 7000M"

You don't need to worry about keeping the space free or defragmenting the drives to avoid data loss. Parted (claims) to take care of it.

If you never had a swap space (and created a partition just now) or you are using a swap file,
Make a swapfs on the partition

"$mkswap <device>"
(eg. $mkswap /dev/sda5)

Then, tell the system to swap on that device
"$swapon <device>"
(eg. $swapon /dev/sda5)

Add an entry in /etc/fstab for persisting the settings
Sample entry:
"/dev/sda5     swap    swap    defaults    0 0"

Thats it!

Check whether everything went fine by,
"$cat /proc/swaps"

Recommended swap-space = twice of total physical memory.

Monday, August 3, 2009

enable "sudo" in Fedora..

One fine day I became tired of "su -" and entering the password every other minute. (Also, had to write a script which needed to sudo). So, I decided to enable sudo access. Its pretty simple.
There's a sudo'ers file : /etc/sudoers

Run "man sudoers" to find out exactly what format the file has to be in. It is a bit complex, but don't distress, you won't need its complexity unless you are a funky sysadmin. The sudoers file usually comes with the basic infrastructure and most-frequently-used categories defined. You can define your own categories too. (refer to "man sudoers")

One thing to remember is that the sudoers file should be modified *only* with the "visudo" command. visudo checks the syntax while exiting and optionally, replaces the old file if the syntax is found to be invalid.

Just append the following entry to your sudoers file
jitesh ALL=(ALL)    NOPASSWD: ALL

where, "jitesh" is the username on my machine.
"NOPASSWD: ALL" means that sudo won't ask for password. Use with care.