When installing Ubuntu for the first time, I separated /
and home
into different partitions. Thinking back on it, how is this possible?
Isn't home
"in" /
.
A partition can contain a file system. Linux can mount a file system at a mountpoint (a directory). This mountpoint can be in another file system's directory tree, and the mountpoint /home
is in the root directory /
.
Mounting means that the content of the mounted directory is available via the mountpoint. This means that the home directory is in the root directory (directory tree), but it is still located in an own file system in an own partition.
You might want to read the manual page entry for the mount
command: https://www.man7.org/linux/man-pages/man8/mount.8.html
All files accessible in a Unix system are arranged in one big tree, the file hierarchy, rooted at
/
. These files can be spread out over several devices.
The file hierarchy is a way of logically organizing the files on your system but is not really representative of how the files are physically stored.
There is a a little confusion between the structure of the file system (as a hierarchical database) and the presentation of hierarchical directory tree in the running system.
Each hierarchy has some root. Therefore, each hierarchical filesystem has its own root.
But when they get mounted, their roots are mapped to some place in the in-memory hierarchy somewhere within VFS layer. So indeed, while the contents of your /home
is a root of that filesystem, when it is mounted as /home
, its content is being presented under that path. The confusion is rooted in the fact there is an important single file system, called "the root" which gets mounted to the root of the in-memory hierarchy and so its root becomes the root of the in-memory hierarchy.
In various situations, you may see those file systems mounted into alternate paths. The usual cases are:
/target
, Gentoo Handbook recommends to mount it at /mnt/gentoo
and so on). That is partially explained by the fact the installer itself is an application running on top of the OS, which already has its own root file system mounted and required to operate./newroot
), and then a switch is performed, so the kernel switches from one root to another at runtime. (The memory that was occupied by the initramfs
is then released and returned to general use.) If you see a debug initramfs shell in the boot menu, that is the way to stop the boot process right before the switch, so you can explore how the system looks at that stage.
/
which is root and in/etc/fstab
will point to some location. After that any folder under/
could be a mount: to another local disk partition or a different disk than what/
is or a network (NFS) mounted disk from another system. Simply know that any folder under/
can be a mount from a different location, that's simply how linux works or can work; linux (the computer) doesn't have feelings and doesn't care where it mounts from./
. That's just how the original designers thought about things. For example your hard disk is at/dev/sda
which you may notice is in/
. That/dev/sda
device may have several partitions like/dev/sda1
and/dev/sda2
etc one of which may be mounted as/home
. Yes, that's right, basically the API for the device driver of your disk also have a file location. My graphics card for example is at/dev/nvidia0
..