Disks, Directories and File types - Linux 101

dos2unix

Well-Known Member
Joined
May 3, 2019
Messages
4,408
Reaction score
4,601
Credits
41,638

This was generated using Claude.Ai

Understanding Directories, Partitions, Filesystems & Mount Points

(Beginner level — no LVM, ZFS, RAID, clustering, etc.)

Linux storage concepts often get confusing because several different things sound similar. This guide breaks them down cleanly and visually.


1) Regular Directories

A regular directory is simply a folder in the existing filesystem.

Examples:

/etc
/home
/opt
/mydata

They require:

  • no disks
  • no partitions
  • no mounts
They’re created with:

Code:
mkdir /mydata


2) Partitions (Slices of a Disk)

A partition is a physical section of a disk.

Examples:

Code:
/dev/sda1/dev/sda2/dev/nvme0n1p3

A partition isn’t usable until it is:

  • Formatted with a filesystem
  • Mounted somewhere

3) Filesystems

A filesystem defines how data is stored (ext4, XFS, etc.).

Format a partition:

Code:
mkfs.ext4 /dev/sda2

Now it can hold files and directories.


4) Mount Points

A mount point is a directory where a filesystem becomes visible.

Example:

Code:
mkdir /mnt/datamount /dev/sda2 /mnt/data

After mounting:

  • /mnt/data shows the content of /dev/sda2
  • Anything previously inside /mnt/data is hidden until unmounted
Unmount:

Code:
umount /mnt/data


5) Directories With Their Own Partition

Some directories get their own partition:

  • /home
  • /var
  • /boot
  • /data
Reasons:

  • Prevent /var logs from filling up /
  • Reinstall OS without deleting /home
  • Improve isolation and stability
They appear in /etc/fstab:

Code:
UUID=123e4567-89ab-cdef-0000-111122223333  /home  ext4  defaults  0  2

This tells the system to mount that filesystem at boot.


6) ASCII Diagrams (Color Enhanced)



A) Single partition system​

Disk: /dev/sda
└── Partition: /dev/sda1
└── Filesystem: ext4
└── / (root filesystem)
├── /etc
├── /home
├── /opt
└── /mydata


B) Separate /home partition​

Disk: /dev/sda
├── /dev/sda1/
│ ├── /etc
│ ├── /opt
│ └── /var
└── /dev/sda2/home
├── user1/
└── user2/


C) What mounting does (before/after)​

Before:
/mnt/data (empty directory)

Mount:

Code:
mount /dev/sdb1 /mnt/data

After:
/mnt/data (shows filesystem on /dev/sdb1)


7) File Colors in ls Output

Terminal colors help identify file types quickly.

Directories​

blue — e.g., drwxr-xr-x

Executable files​

green — files with the executable bit (chmod +x)

Symbolic links​

cyan — e.g., lrwxrwxrwx
Broken links may appear as bright red.

Archives / compressed files​

red — .tar .gz .bz2 .xz .zip .rar .7z

Images & media​

magenta — .jpg .png .gif .svg .mp3 .mp4 .mkv

Device files​

yellow — block & char devices under /dev

Pipes (FIFOs)​

yellow — prw-r--r--

Sockets​

bright green — srwxrwxrwx

Setuid / Setgid executables​

Setuid → red background
Setgid → yellow background


File Color Quick Map (ASCII)

Blue → Directory
Green → Executable
Cyan → Symlink
Red → Archive / compressed
Magenta → Media
Yellow → Devices / FIFOs
Bright Green → Socket
Red BG → Setuid
Yellow BG → Setgid


8) Practice Exercise

Create, format, mount, and inspect:

Code:
mkdir /mnt/datamkfs.ext4 /dev/sdb1mount /dev/sdb1 /mnt/datals -l --color=auto / /mnt /mnt/data

Unmount when done:

Code:
umount /mnt/data
 
Last edited:


The term "filesystem" can be ambiguous for users new to linux terminology. In post #1 it's used in two ways with different meanings. Fortunately there are descriptions of these meanings in the linux manual pages so that those interested can become clearer on the matter.

The first use of the term "filesystem" in post #1 under the heading "1) Regular Directories", refers to the hierarchy of files in a linux directory tree. This filesystem hierarchy can be represented visually as a tree as in the image:


filesystem.png



A different tree representation of similar or the same information can be produced in the output of the tree command from a terminal such as the following. In this example the user is in the root directory and uses the command: tree -d -L2 which outputs the tree of directories (-d) which go to a depth of 2 levels (-L2). The output is severely snipped to show the essence of the filesystem structure:

Code:
.
├── bin -> usr/bin
├── boot
│   ├── efi
│   └── grub
├── dev
│   ├── block
│   ├── bsg
│   ├── bus
<snip>
├── etc
│   ├── alsa
│   ├── alternatives
│   ├── apache2
│   ├── apm
<snip>
├── home
│   └── ben
├── lib -> usr/lib
├── lib64 -> usr/lib64
├── lost+found  [error opening dir]
├── media
│   ├── ben
│   └── cdrom
├── mnt
├── opt
│   └── Min
├── proc
│   ├── 1
│   ├── 10
<snip>
├── run
│   ├── avahi-daemon
│   ├── connman
│   ├── console-setup
<snip>
── sbin -> usr/sbin
├── srv
├── sys
│   ├── block
│   ├── bus
<snip>

The details of this meaning of the term "filesystem" are explained in the manual page: hier, so one can run the following for the info:
Code:
 man hier

The second meaning of the term "filesystem" used in post #1 under the heading "3)Filesystems" refers to a different sort of structure altogether. This meaning of the term refers to the structure which organises how files are managed on the disk. That structure is invisible to the user and basically consists of metadata made up of inode numbers and other info that enable the user's commands to locate files on the disk. These filesystems have the names like ext4. Information on these filesystems are available in the manual pages with the command:
Code:
man 5 filesystems

Just to make the distinctions a little more fuzzy, in the manpage: man file-hierarchy, there are references to links on the linux file hierarchy system, but it refers to "file system", rather than "filesystem" as referred to in the man page man filesystems. The first two manpages mentioned however are clear.
 


Follow Linux.org

Members online

No members online now.

Top