8

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" /.

2
  • 3
    first, everything has to simply happen under / 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.
    – ron
    Commented Oct 26, 2022 at 20:46
  • That's not unusual. On Unix-like operating systems (including modern apple devices) everything is in /. 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..
    – slebetman
    Commented Oct 28, 2022 at 14:17

3 Answers 3

11

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.

10

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.

6

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:

  • Installation. During OS installation, the file system that is going to become a "root" of the new install, gets mounted somewhere else (Debian installer uses a mount point /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.
  • Recovery. This could be considered as a variation of the previous item; you run a recovery OS which has own root, but to access files on the to be recovered root system (or its other file system) you need to mount it somewhere else.
  • Boot. The OS startup process often needs to initialize storage before access to the main root file system is gained. For example, it may be placed in the encrypted volume, so there is a need to instantiate a transparent encryption path to access that file system, and you need to have some applications already being able to run that will perform this instantiation: ask for the password or key, check, and so on. Other cases may be the use of software RAID, volume management, loading drivers, configuring a network if the root file system is going to be a networked one (NFS or iSCSI) and so on. In all cases, a small temporary root file system is used which is called initramfs and it is stored in the boot volume alongside the kernel image, or transferred together with the kernel from the PXE boot facility, or even it could be built into the kernel image. That file system contains all configuration, programs, drivers and/or scripts needed to initialize the main root file system. When it is done, the main root is getting mounted into some path of the initramfs root (that is often /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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .