Swap & tmp, and /dev.

ArisVer

Golden Member
Mar 6, 2011
1,345
32
91
Why is not a swap area formed in the /tmp folder? The purpose of that folder seems to be ideal for the swap area to settle in.

Also, the /dev folder seems to be a partition on the hard disk, (based on the free space left).
 

Kirby

Lifer
Apr 10, 2006
12,028
2
0
Swap is virtual memory that's "swapped" (or called paging) back into main memory when it's needed. If you need something in memory and it's not there, you get a page fault and it loads it from swap. So if you need more memory, stuff that's not currently being used can be placed in swap.

tmp is just a temporary folder for normal files, like a .flv from your favorite adult streaming site. :p

No need to share it if they have two separate purposes.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
If you really want you could put a swap file in /tmp, but that's just now usually how it's done. In the past swap partitions were preferred because they were accessed directly by the kernel and thus bypassed the higher level filesystem I/O layers. But with current Linux distros swap files are just as efficient as partitions so the only real reason to use one over the other is personal preference.

Also, some distros use things like tmpreaper that clean out /tmp periodically or even mount it via tmpfs so it's not good to put things in there for extended periods of time.

And /dev is special, in the past it was just a directory full of device files for everything that might possibly be in your machine. Now it's a ram disk that's dynamically managed by udev with what's currently in your PC.
 

ArisVer

Golden Member
Mar 6, 2011
1,345
32
91
Having dedicated partitions to swap and the files /etc, /usr, /var (and others) is better according to security, but unless you know the disk space used it's difficult and disk consuming. (You may laugh, i made a 500MB partition for /boot).

/dev reports about 7KB, and also reports 170MB of free disk space. Big difference in numbers, it is strange. Does this mean i have 170MB of unused RAM dedicated to /dev?
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Having all of those filesystems has been a common unix security thing for a while, but you have to understand the reasons behind it. Most of them are very little things that are dubious unless it's a shared machine with people using shell accounts and even then are small hurdles for an attacker to overcome. Once they have root, and that can be done without having /usr writable, they can just run 'mount -o remount,rw /usr' to make it read-only or change any other mount flags like nosuid.

Separating user writable areas from things like /var are good to avoid the filesystem filling up causing things like MySQL to stop working but filling up a filesystem isn't as catastrophic as people seem to suggest. Fililng up the root won't cause the system to crash, just daemons that need to write to disk may stop/crash individually but you should still be able to get to a shell and fix it.

/dev should be mounted via tmpfs, which is swap backed ram disk. None of your memory is wasted for it and I'm sure it's not the only tmpfs mount on your system.