📜  ubuntu --bind vs mount - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:20:43.892000             🧑  作者: Mango

Ubuntu --bind vs mount - Shell/Bash

When it comes to mounting file systems in Ubuntu, there are two ways to do it - using the --bind option or the mount command.

1. --bind option

The --bind option is a simple way to mount a directory or file system to another location. It creates a hard link between the two locations, so changes made in one location are reflected in the other.

Example:

$ sudo mount --bind /home/user1 /mnt/user1

This command mounts the /home/user1 directory to /mnt/user1. Any changes made to files or directories within /home/user1 will also be reflected in /mnt/user1.

2. mount command

The mount command is a more flexible way to mount file systems. It allows you to specify various options when mounting a file system, such as read-only, no-exec, etc. With the mount command, you can also mount file systems from remote servers.

Example:

$ sudo mount -t nfs -o soft,timeo=900,retrans=3,proto=tcp server:/home/user1 /mnt/user1

This command mounts the /home/user1 directory from the remote server to /mnt/user1 using the NFS protocol. The soft option specifies that the mount should fail gracefully if the remote server is unavailable. The timeo and retrans options specify the timeout and number of retransmissions to use when communicating with the remote server. The proto option specifies the protocol to use - in this case, TCP.

Conclusion

Both the --bind option and the mount command are useful for mounting file systems in Ubuntu. The --bind option is simpler and easier to use, but the mount command offers more flexibility and options. Which one you should use depends on your specific needs and use case.