Search code examples
ubuntulinux-from-scratch

What is the purpose of mounting a partition and giving it a directory (i.e. mount point)?


From LFS instructions: http://www.linuxfromscratch.org/lfs/view/stable/chapter02/mounting.html

If using multiple partitions for LFS (e.g., one for / and another for /usr), mount them using:

mkdir -pv $LFS
mount -v -t ext4 /dev/<xxx> $LFS
mkdir -v $LFS/usr
mount -v -t ext4 /dev/<yyy> $LFS/usr
Replace <xxx> and <yyy> with the appropriate partition names.

I can't seem to understand the concept of mount point being a random directory. In this case LFS=/mnt/lfs


Solution

  • A filesystem is really just a big array of bytes stored (typically) in a partition. Mounting is how you get access to the files within it.

    Every filesystem has its own root directory. In Windows, you have drive letters (like C:) that refer to the root directories of different filesystems, but Unix and Linux use a different approach. There's a single "virtual" directory hierarchy, but any directory can be used as a mountpoint for the root of another filesystem.

    So when you mount your new filesystem on /mnt/lfs, it makes /mnt/lfs be an alias for that filesystem's root directory — think of it as a sort of fancy drive letter. As you follow the LFS instructions, you'll be creating subdirectories like bin and etc in there, and they're actually being placed under the root of the filesystem you created. Later, when you boot your finished LFS system, that same filesystem will be mounted as the root filesystem (/), so its contents will appear as /bin, /etc, and so on.

    There's nothing special about the path /mnt/lfs. You could've called it /mnt/foo or /foo/bar or whatever. All that really matters is that you have a path that refers to the root of your newly-created filesystem so that you can start copying things into it.