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?

  • So you want a single nosuid etc. partition for /var, or a separate partition per subdirectory? – Useless Dec 7 '12 at 10:42
  • 1
    @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

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
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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