A hard drive can only have one single root directory, but Linux doesn’t treat this root directory the same exact way that Windows might have. New users who are coming over from other operating systems might be confused as a result. Think of the entire file structure as one large tree that got turned upside down.
The root of the entire tree, irrespective of any of the volumes, is all the way up at the top. You could have one single hard drive in a computer or hundreds of drives plugged into a slew of RAID sets. It doesn’t matter to Linux, because you will always have a single root that all the others grow from. You might end up noticing some real advantages to this methodology if you give it a try.
Hard Drives Only Have One Root Directory Anyway
The way that Linux, and functionally most Unix-based operating systems, organizes the file structure is by mounting material to this tree. Try typing ls -R / from a terminal and have a look at the incredible amount of information rolling up the screen.
In most cases, the / root area is the root area of a partition on your main hard disk. Now, your hard disk might be something other than a hard disk. Mobile phones running Android, which is based on Linux, often have a small eMMC microchip that the Linux kernel treats as a hard disk. It doesn’t matter what it is, but most of the / area is the same thing as the root directory on the hard disk.
Over time, other partitions and volumes get mounted elsewhere in directories. If you were to use the sudo command to stash some files in /mnt/ or /media/ and then later plugged in a microSDXC card reader that mounted something there, then you wouldn’t be able to see the things you had put in /media but they would still be there. Once you unmounted the device, they’d appear again. Fortunately, modern Linux distributions are designed to prevent this kind of thing from happening but you could still do it manually.
Keep in mind, though, that hard drives only have one root directory anyway. While in Linux the entire file structure itself has this root, that doesn’t change it. You might be used to the DOS and Windows paradigm inherited from the ancient CP/M OS where this root directory is mapped to a drive letter, but the on-disk data structures don’t change. You just don’t have to deal with C:\ vs D:\ and E:\ each time you want to think about a drive.
Windows Doesn’t Even Really Do This
While Microsoft Windows mapped drives genuinely to these letters in the 95 and 98 days, all versions of Windows NT actually internally use something similar to the Unix method and then create this user interface fiction to help those who have been using drive letters for a long time.
If you were to start examining Windows internals, then you’d find that the drive letters are actually represented as \??\c:\Program Files\ with the \??\c: area being a symlink to device and partition files just like Unix uses but represented different. Microsoft refers to this as the NT Object Manager. These mount points are still single root directories tied to actual volumes. In a way, Linux and other Unix-based operating systems do this without any further abstractions. This structure is used by the overwhelming majority of other Unix-like operating systems, including the antique Xenix distribution that Microsoft once published.
The benefit of not using drive letters is that you can mount more than 24 volumes or partitions, which helps to alleviate one of the biggest issues related to the classical CP/M way of doing things. CP/M didn’t have directories, so the letter assignments made sense at times.
One thing that’s the same in both methods of doing things relates to the . and .. special directories inside of each subdirectory. The . directory entry represents the working directory you’re already in while the .. entry represents the directory right above it. This allows you to reference objects relative to where you are.
Note that if you type cd / followed by cd .. into a terminal, nothing happens in most cases. You can try typing cd .. over and over again, but you won’t move up any further.
This is because while a hard drive and thus the Linux and Unix file structure can only have a single root directory, there’s no reason that a user should have to suffer from errors in a script or something by trying to move upwards. Interestingly, on some versions of DOS and Windows you won’t need a space between cd.. while you almost always will on Unix systems.
The post Fix: A hard drive can only have one single root directory appeared first on Appuals.com.