Author Topic: (Solved) How to use tmpfs for /tmp?  (Read 806 times)

Offline zhangyou

  • Full Member
  • ***
  • Posts: 50
(Solved) How to use tmpfs for /tmp?
« on: March 20, 2011, 06:34:19 AM »
I notice that there is a tmp folder in my home folder, which is ~/tmp. Apparently it is functioned as the /tmp in other distros. Now I want to move it to RAM so that I can get more use of my 4GB RAM and clean the content in there every reboot.

I already added a line of tmpfs /dev/shm tmpfs defaults 0 0 in /etc/fstab according to my previous Bodacious Bacon setting but it doesn't help.

I tried to create a link of ~/tmp to /tmp, but there is already a folder named tmp in home folder so never succeeded.

What should I do?
« Last Edit: March 21, 2011, 11:27:20 AM by zhangyou »

Offline Bald Brick

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 6395
  • I'm going South
Re: How to use tmpfs for /tmp?
« Reply #1 on: March 20, 2011, 06:50:46 AM »
I notice that there is a tmp folder in my home folder, which is ~/tmp. Apparently it is functioned as the /tmp in other distros. Now I want to move it to RAM so that I can get more use of my 4GB RAM and clean the content in there every reboot.

I already added a line of tmpfs /dev/shm tmpfs defaults 0 0 in /etc/fstab according to my previous Bald Bricks Bodacious Bacon setting but it doesn't help.

I tried to create a link of ~/tmp to /tmp, but there is already a folder named tmp in home folder so never succeeded.

What should I do?

Many of us have /tmp in RAM. So if ~/tmp is a link to /tmp, both /tmp and ~/tmp will be in RAM.

To get /tmp into ram you need the line
Code: [Select]
none /tmp tmpfs defaults 0 0in /etc/fstab. Its created automatically if you check "Clean /tmp at each boot" in PCC.

If you add it manually, remember to empty /tmp before you reboot (or everything in /tmp will remain on your hard drive but hidden under the tmp in RAM).

If you wish to make ~/tmp a symbolic link to /tmp, first check that it isn't a link already; if it isn't, remove your existing ~/tmp and, as your normal user, create the link with the command
Code: [Select]
ln -s /tmp ~/tmpor by drag and drop in Konqueror or Dolphin.
« Last Edit: March 20, 2011, 09:09:15 AM by Bald Brick »
Feed the trolls!
They need it!

AMD Athlon 7450 Dual-Core Processor, 7.80 GiB RAM, Nvidia GeForce GT 120/PCIe/SSE2, OpenGL/ES-version: 3.3 0 NVIDIA 295.40, SBx00 Azalia (Intel HDA) soundcard, ‎Logitech B500 webcam, SAA7146 DVB card, HDDs: Seagate 250824AS, Western Digital WD10EAVS-00D

Offline zhangyou

  • Full Member
  • ***
  • Posts: 50
Re: How to use tmpfs for /tmp?
« Reply #2 on: March 20, 2011, 06:57:54 AM »
Thanks Bald Brick
the ~/tmp is a folder not a link. so every time i delete it, it is automatically created again in no time. therefore it is impossible to create a link named tmp in home folder.

Offline Bald Brick

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 6395
  • I'm going South
Re: How to use tmpfs for /tmp?
« Reply #3 on: March 20, 2011, 07:48:53 AM »
Thanks Bald Brick
the ~/tmp is a folder not a link. so every time i delete it, it is automatically created again in no time. therefore it is impossible to create a link named tmp in home folder.

You could try doing it from outside KDE, e.g. from a tty. Hold down Ctrl and Alt and hit F1; then log in as your normal user and enter
Code: [Select]
rm -rf ~/tmp && ln -s /tmp ~/tmp
(But remember that rm with the options -r and -f is dangerous.)

Edit:

Ctrl+Alt+F8 should give you your desktop back. If ~/tmp is still recreated too fast, log out of KDE and start a terminal session as your normal user.

Edit 2:

I was just able to create ~/tmp as a link to /tmp by running
Code: [Select]
rm -rf ~/tmp && ln -s /tmp ~/tmpin Konsole, i.e. from within KDE. Even if ~/tmp is recreated fast and automatically these days, it wasn't fast enough....
« Last Edit: March 20, 2011, 09:26:51 AM by Bald Brick »
Feed the trolls!
They need it!

AMD Athlon 7450 Dual-Core Processor, 7.80 GiB RAM, Nvidia GeForce GT 120/PCIe/SSE2, OpenGL/ES-version: 3.3 0 NVIDIA 295.40, SBx00 Azalia (Intel HDA) soundcard, ‎Logitech B500 webcam, SAA7146 DVB card, HDDs: Seagate 250824AS, Western Digital WD10EAVS-00D

Offline zhangyou

  • Full Member
  • ***
  • Posts: 50
Re: How to use tmpfs for /tmp?
« Reply #4 on: March 21, 2011, 11:26:49 AM »
Quote
Edit 2:

I was just able to create ~/tmp as a link to /tmp by running
Code:
rm -rf ~/tmp && ln -s /tmp ~/tmp
in Konsole, i.e. from within KDE. Even if ~/tmp is recreated fast and automatically these days, it wasn't fast enough....

The command of
Code: [Select]
rm -rf ~/tmp && ln -s /tmp ~/tmp however didn't work. But I managed to make it work by using:
Code: [Select]
rm -rf tmp && ln -s /tmp tmp when opening a konsole in home folder.

Thanks very very much!!!

Offline Bald Brick

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 6395
  • I'm going South
Re: How to use tmpfs for /tmp?
« Reply #5 on: March 21, 2011, 12:51:30 PM »
Quote
Edit 2:

I was just able to create ~/tmp as a link to /tmp by running
Code:
rm -rf ~/tmp && ln -s /tmp ~/tmp
in Konsole, i.e. from within KDE. Even if ~/tmp is recreated fast and automatically these days, it wasn't fast enough....

The command of
Code: [Select]
rm -rf ~/tmp && ln -s /tmp ~/tmp however didn't work.

I wonder why not. Bash does normally understand "~" to mean the user's home directory. (That's why I told you to run the command as your normal user. If you did, "~" should have been interpreted as "/home/<user>". If you run the command as root, "~" just means "/root".)

Quote
But I managed to make it work by using:
Code: [Select]
rm -rf tmp && ln -s /tmp tmp when opening a konsole in home folder.

That's the main thing. (But then you must have run the command from within /home/<user>, or it wouldn't have worked....)

Quote
Thanks very very much!!!

You are very welcome.
« Last Edit: March 21, 2011, 12:57:09 PM by Bald Brick »
Feed the trolls!
They need it!

AMD Athlon 7450 Dual-Core Processor, 7.80 GiB RAM, Nvidia GeForce GT 120/PCIe/SSE2, OpenGL/ES-version: 3.3 0 NVIDIA 295.40, SBx00 Azalia (Intel HDA) soundcard, ‎Logitech B500 webcam, SAA7146 DVB card, HDDs: Seagate 250824AS, Western Digital WD10EAVS-00D