Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
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
add comment

2 Answers

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
add comment

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
add comment

Your Answer

 
discard

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.