Devices and Mount
About the linux directory tree
- Linux has a single directory tree, starting with the root directory
- Othe oerating systems use different methods to refer to the same information.
Microsoft Windows for example, uses a single tree for each device. It uses letters to refer to thise devices.
eg: a:\mydir\myfile.txt
is a file called myfile.txt in a directory called mydir, inside a diskette inserted into drive a: - If you are a newcomer to UNIX systems (linux as an example), it can be a little confusing.
Linux Devices
- The Linux filesystem does not show only files
- cd into the /dev directiry and look at what you see there:
1cd /dev
2ls -l
- Here's an example from what I see in my Debian-11 Linux.
I just cut a few of the lines
1...
2brw-rw---- 1 root disk 8, 0 Sep 20 09:49 sda
3brw-rw---- 1 root disk 8, 1 Sep 20 09:49 sda1
4brw-rw---- 1 root disk 8, 2 Sep 20 09:49 sda2
5brw-rw---- 1 root disk 8, 3 Sep 20 09:49 sda3
6brw-rw---- 1 root disk 8, 4 Sep 20 09:49 sda4
7...
- These entries are not files, nor are they directories.
They are devices, in this case a hard disk drive (sda) and the partitions inside it (sda1, sda2, ...) - Note the letter b at the beginning of each line, specifying this as a
block device.
Disks, SSDs and the such are block devices. - Other files has a c, and that means that they are charcter devices
- We use the mount command to attach a device to specific location inside the directory tree.
Showing mounts
- Use the mount command to show mounts.
(there may be several of them) - Use this command to look for a mount for the root directory:
mount | grep " / " - You should be able to discover the device that is mounter there.
In my case this is /dev/sda1
Adding a mount
- Create a new directory under the current directory:
1cd
2mkdir myroot
- Mount your device there:
1sudo mount /dev/sda1 ./myroot/
- Go to this directory and look around:
1cd myroot
2ls
(use pwd to see that you are not dreaming):
1pwd
- Amazing.
now remove your new mount:
1cd ..
2sudo umount /dev/sda1 ./myroot