Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Let us assume that I have two hard drives (A,B) and have the following directories:

  • /var/www
  • /var/www/upload

Currently if I upload a file to /var/www OR /var/www/upload ; it will be saved in drive A.

How do I make the folder /var/www/upload point to the drive B. So if I upload a file to /var/www/upload it will be saved in drive B but when I upload a file to /var/www ,it will be saved in drive A.

share|improve this question

migrated from stackoverflow.com Sep 19 '09 at 22:10

This question came from our site for professional and enthusiast programmers.

add comment

3 Answers

Edit: I assumed that disk A is not mounted as the root (/) filesystem. If it is, just ignore lines with driveA.

Edit your /etc/fstab:

/dev/diskA    /var/www/          auto   defaults    1   2
/dev/diskB    /ver/www/upload    auto   defaults    1   2

You can replace "auto" by the filesystem you have on that partition, but the above should work anyway.

If disks A and B are mounted elsewhere you can try symlinking:

ln -s /path/to/driveA_mountpoint /var/www/
ln -s /path/to/driveB_mountpoint /var/www/upload

Note: /var/www and directory "upload" on driveA must not exist or this will fail.

Personally I prefer using the bind option of mount:

mount -o bind /var/www/ /path/to/driveA_mountpoint
mount -o bind /var/www/upload /path/to/driveB_mountpoint

Consider editing /etc/fstab though - it's probably the best way.

share|improve this answer
3  
This answer assumes that drive a is not the root drive. if A is the root drive then you only need to create an empty directory ( /var/www/upload ), then create an fstab entry for drive b in the example above. –  Roy Rico Sep 20 '09 at 1:02
1  
@minder - to put a bind mount in your /etc/fstab: /path/orig /new/path/mount bind defaults 0 0 –  warren Sep 23 '09 at 0:55
add comment

is Hard Drive B mounted? If it is,

ln -s /path/to/hard/drive/B/mount/point /var/www/upload

Otherwise

mount -t <fstype> -o defaults /dev/<hard driver B> /var/www/upload
share|improve this answer
    
this will work, but I think adding it to the fstab will be a better solution because it will remount when the machine boots whereas it wouldn't in your example. –  Roy Rico Sep 20 '09 at 1:04
add comment

cd /somewhere/within/drive/b

ln -s /var/www/upload directoryindriveb

share|improve this answer
    
The target (directory from HDD B) must be the first parameter of ln. –  Cristian Ciupitu Sep 20 '09 at 6:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.