Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Recently I added a new 40GB hard drive as swap. I want the swap to be enabled when the computer logs me in. I followed the directions here to make the swap command run on start up.

I added swaps.desktop to /etc/xdg/autostart/ as well as to /usr/share/applications/. Inside swaps.desktop is this:

[Desktop Entry]
Name=Swap Drive Autostart
Exec=swapon -p 32767 /dev/sda5
Type=Application
Terminal=false

I am sure that the command shown (swapon -p 32767 /dev/sda5) works on its own, but when I restarted the computer, the swap was not enabled.

Then I made the file supposedly able to be run as myself (using this) because the file was not being run at start up:

sudo chown root:root /etc/xdg/autostart/
sudo chmod 700 /etc/xdg/autostart/

sudo chown root:root /usr/share/applications/
sudo chmod 700 /usr/share/applications/

I also did sudo visudo and added the lines:

administrator  ALL=(ALL) NOPASSWD: /etc/xdg/autostart/swaps.desktop
administrator  ALL=(ALL) NOPASSWD: /usr/share/applications/swaps.desktop

whoami says that I am administrator.

End result: When I try to run either swaps.desktop file on their own, I get Error: Permission denied. But when I run the file with "Open Current Folder as Root", it runs flawlessly and my swap space shows up in cat /proc/swaps.

What am I doing wrong, and how do I make this work correctly so that the swap is enabled whenever I log in?

share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

You need to add the fstab entry in /etc/fstab

It needs to be mentioned with your UUID

Here is my example of fstab entry

# swap was on /dev/sda5 during installation
UUID=c44126db-1f07-4dfa-a836-e478fecdd8d0 none            swap    sw              0       0

This is my swap entry which was Automatically created and u need to enter the value as show here

If you need to know the UUID of your drive, run the command

#blkid /dev/yourdrive

Then you will get the value like this:

/dev/sda5: UUID="c44126db-1f07-4dfa-a836-e478fecdd8d0" TYPE="swap"

See how i have run it in my PC :

root@system99:/home/sysadmin# blkid /dev/sda5 
/dev/sda5: UUID="c44126db-1f07-4dfa-a836-e478fecdd8d0" TYPE="swap"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.