Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to create a new partition and move the contents of the /var directory to it for the security reason of having /var/www and other subdirectories "mounted" with nosuid, noexec, and nodev permissions. How do I do it for /var or any other root directory?

share|improve this question
So you want a single nosuid etc. partition for /var, or a separate partition per subdirectory? – Useless Dec 7 '12 at 10:42
@Useless Just one partition and just for /var alone. – Desmond Hume Dec 7 '12 at 10:43
/ itselv is more difficult. But you did not ask about that... – Nils Dec 8 '12 at 21:03
up vote 6 down vote accepted

Actually, a slight modification to warl0ck's plan (because I'm paranoid)

  1. create the new partition
  2. boot to single-user mode
  3. mount the new partition as /new_var or something, and rsync as described
    • you might as well run aptitude autoclean before running rsync, to reduce the amount getting copied over (or even ... clean if you don't mind re-downloading your apt cache)
  4. move /var to /old_var so you don't lose it right away, and then mount the new partition as /var

    • there may be live logs or pid files in old_var - if you don't mind losing whatever changed since re-starting, you can ignore those
  5. edit fstab so the new partition will mount as /var on future boots, and reboot to normal multi-user mode

  6. if all that went well, you can sudo rm -fr /old_var when you're sure it's working. If anything breaks, you still have old_var around
share|improve this answer
The copy/rsync/whatever should be done in single-user mode too. – Carlos Campderrós Dec 7 '12 at 14:00
Good point, I've edited that in. – Useless Dec 7 '12 at 14:28

A simple way is mount the new partition on some temporarily location, then do a rsync to synchronize /var/ and the new location,

Afterwards, boot to root maintain mode, erase /var, and change fstab that mount the new partition onto /var

share|improve this answer

Your Answer


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.