大网数据广告活动
服务器运维问答

Bind multiple directories of one drive to multiple directories of another single mounted drive?

· 52CE 我爱测

I have SSD and HDD hard drives on server. SSD mounted to / HDD mounted to /mnt/ I have 20 (planning more) sites with 5-20 GB content each. I want to store /home/user/domain1.com/ to SSD /home/user/domain1.com/wp-content/uploads/ …

问题原文

原帖链接 · wtfowned · CC BY-SA 4.0

I have SSD and HDD hard drives on server.

SSD mounted to /

HDD mounted to /mnt/

I have 20 (planning more) sites with 5-20 GB content each.

I want to store

/home/user/domain1.com/ to SSD

/home/user/domain1.com/wp-content/uploads/ to HDD

And same for other domains

/home/user/domainN.com/ > SSD /home/user/domainN.com/wp-content/uploads/ > HDD

How to do it ?

I founded How do I mount sub-directory to a hard drive in Linux? , but its only for 1 drive/dir. Is there way to make some symlinks or something like this, which points to direct dir on other hard drive?

For example,

/home/user/domain1.com/wp-content/uploads/ points to /mnt/domain1.com/ /home/user/domain20.com/wp-content/uploads/ points to /mnt/domain20.com/

Thanks in advance!

已采纳解答

原帖链接 · silmaril · CC BY-SA 4.0

You doesn't need any "mounting" at all, you can simply symbolic-link the folder like that:

for domain in domain1.com domain20.com; do
  mkdir /mnt/$domain
  mv /home/user/$domain/wp-content/uploads/* /mnt/$domain
  rmdir /home/user/$domain/wp-content/uploads/ 
  ln -Ts /mnt/$domain /home/user/$domain/wp-content/uploads/ 
done

PS: it is possible to use bind mount also, but it's bit more cumbersome to setup automatically at boot, something like this should work:

for domain in domain1.com domain20.com; do
  mkdir /mnt/$domain
  mv /home/user/$domain/wp-content/uploads/* /mnt/$domain
  mount --bind /mnt/$domain /home/user/$domain/wp-content/uploads/
  echo "/mnt/$domain /home/user/$domain/wp-content/uploads/ none bind 0 0" >> /etc/fstab
done

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-08-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。