2

While reading on mount point, I think of file management in Linux as followed :

  • / is the main body of a tree
  • /a is a branch from the main body, /a/b is a branch from /a branch
  • To mount a partition c onto the mount point /a/b means "hanging" /c onto the /a/b branch, resulting in /a/b/c

I have some questions:

  1. Can we only mount a whole partition, or can we do with a part of that partition ? Please elaborate.

  2. Do we mount a partition onto another already-mounted partition ? For example some d mounted on /mnt, now can I mount another /e onto d, creating /mnt/d/e ? Or we can/should only mount to "fixed branch" such as /, /mnt ? If it is possible, what will happen if we unmount /d, will /e be automatically unmounted as well ?

  3. Can we mount onto something with a different filesystem ? For example, /a having filesystem F1, can I mount /b having filesystem F2 onto a and create /a/b ?

  4. Let's say a device sda having 2 partitions sda1, sda2. In common practice, would people mount at any mount point they want such as /sda1 to /a/sda1 , sda2 to /b/c/sda2 , or do they mount to the same directory ?

  5. In linux such as Fedora 22, how can I create some virtual or temporary partition/filesystem for testing and learning mounting and mountpoint ?

4

First: you don't mount partition. The thing that is mounted is filesystem. Filesystem may live on a partition but that's not necessarily so; filesystems commonly live:

  • inside file (e.g. ISO images),

  • entirely in RAM (e.g. /tmp is sometimes created this way),

  • inside kernel (/sys and /proc work this way),

  • or as a network service (NFS and Samba work this way).

To mount a partition c onto the mount point /a/b means "hanging" /c onto the /a/b branch, resulting in /a/b/c

This is incorrect.

First, there are many ways to refer to the filesystem (for example, most common -- and safest in most cases -- way is using UUID, try running lsblk -o +UUID,LABEL as normal user to see IDs your kernel knows about) but none of them have implications on the actual resulting path.

So when mounting, you provide a path (that path is called mountpoint and must already exist). After the filesystem is mounted, its root becomes accessible at that very path you provided --- not a subdirectory of it.

  1. Can we only mount a whole partition, or can we do with a part of that partition ? Please elaborate.

In theory, you could have multiple filesystems on a single partition but then you'd need specific software to be able to find it there (truecrypt used to do this, IIRC).

If you want to mount only part of a filesystem, then again, in theory it could be possible but kernel does not do it like this. In theory you could devise a filesystem that allows to be mounted only partially and then write a driver for it but I guess it would be between hard and impossible. AFAIK, none of commonly used filesystems support this.

  1. Do we mount a partition onto another already-mounted partition?

Yes, you can do it. You can mount any number of filesystem over the same path and unmount them in any order. Only the last mounted filesystem will be accessible, though.

Actually it's done commonly by some programs e.g. for security reasons: mount a filesystem, open a file on it, then mount something else over the same path. Now no other process can access the first file.

For example some d mounted on /mnt, now can I mount another /e onto d, creating /mnt/d/e ? Or we can/should only mount to "fixed branch" such as /, /mnt ? If it is possible, what will happen if we unmount /d, will /e be automatically unmounted as well ?

If you mount a filesystem on /mnt, and that filesystem happens to contain eg. directory 'foo', then you can use this directory to mount another filesystem. But kernel won't let you unmount a filesystem that is being used. Opening a file, having a process chdir to a directory and using a directory as a mount point all count as "being used".

mount to "fixed branch" such as /,

Oh, and by the way, never ever do this. Don't mount anything directly to /; this would most likely immediately break your system.

  1. Can we mount onto something with a different filesystem

Yep. In fact, with any common distribution, by the time you get to the login screen, you have about 5 different filesystems (heh, it's 16 on my Fedora box right now) mounted somewhere under /.

Run mount to see what filesystems are currently mounted.

  1. Let's say a device sda having 2 partitions sda1, sda2. In common practice, would people mount at any mount point they want such as /sda1 to /a/sda1 , sda2 to /b/c/sda2 , or do they mount to the same directory ?

As far as I can remember, only requirement is that the mount point (i.e. the directory) must already exist. Other than that, you can come up with any scheme that fits your needs. The fact that the filesystems are lay on same disk does not pose any limit.

After all, you could even move the filesystem later to a different medium and re-mount it. You would do it e.g. if the disk is failing or you want more space.

Regarding naming, it's rather question of why you need the filesystem in the first place. It's common to have a separate (large) filesystem just for user home directories. Natural place for home directories is /home so the trick is to mount that filesystem to this path. For servers it's often advantageous to separate /var this way. But if you just want a separate storage, you can always mount it to any unused path (eg. /finance), as long as the path is unique and meaningful for your users (I guess /sda1 would not be but YMMV ;)).

  1. [...] how can I create some virtual or temporary partition/filesystem for testing and learning mounting and mountpoint ?

See Archemar's answer. (By the way it should work on any common GNU/Linux distribution, not just Fedora 22.)

4

This is very broad

  1. local partition are mounted as a whole. You cannont mount it partially.
  2. you can (and usually do a lot) mount partition over other partition. exisiting data is "hidden" (e.g. file foo.txt in /mnt/a/b/foo.txt is hidden when you mount "b" on /mnt/a/b )
  3. yes you can, it it advised to mount local over local, distant on distant or local, but you can mount local ext3 over an nfs over an ext3 over ...
  4. it depends on your need.
  5. mount point dissapear at boot unless writen in /etc/fstab.

You can create temporary device and mount point using

  • dd if=/dev/zero count=100 bs=1K of=foo ,
  • then mkfs -t ext3 foo,
  • then, as root, mount foo /mnt

    unmount /mnt and delete foo when done.

as per request.

you have /dev/sda1 /dev/sda2

ls /mnt
#empty
mount /dev/sda1 /mnt/a
error mount point doesn't exist (1)
mkdir /mnt/a 
mount /dev/sda1 /mnt/a
ls /mnt
a
ls /mnt/a
# empty
mkdir /mnt/a/b
date > /mnt/a/b/foo.txt
mount /dev/sda2 /mnt/a/b
ls /mnt/a/b
# empty
umount /mnt/a
device busy (2) 
date > /mnt/a/b/bar.txt
ls /mnt/a/b
bar.txt
umount /mnt/a/b
ls /mnt/a/b
foo.txt
  • (1) you must mount on existing dir.
  • (2) /mnt/a can't be unmounted, because there is a mount point using it (/mnt/a/b )
  • Very resourceful answer ! On 2. can you elaborate the hidden part "when you mount "b" on /mnt/a/b " ? Do you mean mounting another /b on /a, or /a/b/b ? Besides, will /b (another partition) get unmount if I unmount its parent /a ? On 4 so it is possible ? – Kenny Dec 17 '15 at 15:40

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.