nixCraft Poll

Topics

The importance of Linux partitions

Posted by Vivek Gite [Last updated: December 5, 2007]

In general, many new Linux sys admin create only two partitions / (root) and swap for entire hard drive. This is really a bad idea. You always need to consider following points:

(1) Performance
(2) Security
(3) Stability
(4) Backup

Let us assume you have 120 GB SCSI hard disk with / and swap partitions only. One of user (may be internal or external or cracker user) runs something which eats up all hard disk (DoS attack). For example, consider following tiny script that user can run in /tmp directory:

#!/bin/sh
man bash > $(mktemp)
$0

Anyone can run above script via cron (if allowed), or even with nohup command:
$ nohup bad-script &

Result is disaster as my entire file system comes under Denial of Service attack. It will even bypass the disk quota restriction. One of our Jr. Linux sys admin created only two partition. Later poorly written application eats up all space in /var/log/. End result was memo for him (as he did not followed internal docs that has guidelines for partition setup for clients server). Bottom line create partition as follows:

/ - Root partition
/home - Users home directory
/usr - Linux/BSD binary programs are installed here
/tmp - Temporary files partition
/var - Stores files which keep changing size, e.g. log, or squid caching files

If you don't have partitions like this then following attack can take place:
1) Denial of Service attack against disk space (see above example script)
2) Users can download or compile SUID programs in /tmp or even in /home
3) Performance tunning is not possible
4) Mounting /usr as read only not possible to improve security
5) All of this attack can be stopped by adding following option to /etc/fstab file:
nosuid - Do not set SUID/SGID access on this partition
nodev - Do not character or special devices on this partition
noexec - Do not set execution of any binaries on this partition
ro - Mount file system as readonly
quota - Enable disk quota

Please note that above options can be set only if you have separate partitions. Make sure you create partition as above with special option set on each partition
/home - Set option nosuid, and nodev with diskquota option
/usr - Set option nodev
/tmp - Set option nodev, nosuid, noexec option must be enabled

For example entry in /etc/fstabe for /home should read as follows:

/dev/sda1  /home          ext3    defaults,nosuid,nodev 1 2

Here is mount command output from one of my OpenBSD production server:

/dev/wd0a on / type ffs (local)
/dev/wd1a on /home type ffs (local, nodev, nosuid, with quotas)
/dev/wd0d on /root type ffs (local)
/dev/wd0e on /usr type ffs (local, nodev)
/dev/wd0f on /tmp type ffs (local, nodev)
/dev/wd0h on /var type ffs (local, nodev, nosuid)
/dev/wd0g on /var/log type ffs (local, nodev)

For more info please read man pages of fstab, mount, fdisk.

Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

You may also be interested in other helpful articles:

Discussion on This Article:

  1. polarizer Says:

    You did mention nodev, nosuid, noexec for /tmp (for /var/ and /var/log it’s a good idea too) but the output from your production server does not show some these settings. So why?

    polarizers 2cent

  2. cyberciti Says:

    Yup we do have nodev, nosuid, with quotas enabled on /home and /var partitions.
    /dev/wd1a on /home type ffs (local, nodev, nosuid, with quotas)
    /dev/wd0h on /var type ffs (local, nodev, nosuid)

    However on /tmp it is only nodev enabled and not nosuid. This is OpenBSD box. And rest of the services are chrooted i.e. www and ftp and /tmp is very small system around

  3. Tudor Vaida Says:

    (1) Performance
    (4) Backup
    Nothing in your article about them.

  4. nixcraft Says:

    Tudor,

    (4) Backup
    You can easily dump and restore /home partition without touching rest of file system.

    (1) Performance
    You can easily disable or enable few properties for performance such as disable file creation update time on /var partition or database partition to save disk I/O.

    Above are two prime examples.

    Appreciate your post.

  5. S. Beatty Consulting » Blog Archive » An Ubuntu Server 7.04 Installation in VMware Says:

    [...] The importance of Linux partitions [...]

  6. Nabin Limbu Says:

    If noexec is enabled in /var, then it can create problem to cgi-bin scripts which are normally stored in /var/www/cgi-bin

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , ,

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.