Live data from Hacker News

Ask HN: Recommended guides for learning filesystems?

news.ycombinator.com

11–20 of 33 posts

Re: Ask HN: Recommended guides for learning filesystems?

#11
I think you're asking two different questions here. What are some standard conventions for where system files are placed in Ubuntu & Linux? And how are filesystems implemented.

For file placement you might start here: https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard

Though I'd caution that it's not a strict standard, and you find that many linux distributions vary from it in particular ways.

For the implementation of file systems on Unix/Linux/Ubuntu, I'd say start at understanding inodes: (this link is just the first I found that seems like a reasonably short overview from my standpoint) https://www.cs.nmsu.edu/~pfeiffer/classes/474/notes/inodefs....

There are a world of different implementations when you get to the details, but the Linux kernel builds or reuses this core idea of inodes into many specific different filesystems. From there there is a lot of info, but the Linux VFS layer handles many common functions of of filesystems in Linux (even if you're system is using ext4 or btrfs, etc specifically). So the Linus Kernel vfs docs may be interesting if you're looking to go even deeper.

Re: Ask HN: Recommended guides for learning filesystems?

#13
post #4

I can't think of any guides. I picked up most of my know-how through using Linux (Ubuntu, specifically). A couple things for you which may be obvious, but a good place to start nonetheless: / - This is Root. Most of your system files are in this directory. /home/username/ - This is your home directory, a common abbreviation is "~/" (tilde). If you are a windows user, this is the equivalent of the file system you are…

Just to clarify: you typically don't have any files under `/`. It is literally the `root` of the directory structure. Nothing else. It could theoretically not be mounted at all, if all subdirectories are mounted individually (or it used to, I'm not convinced that's still the case).

In addition, you most typically wouldn't find the defaults in `/`, for the reason listed above. The default files copied over by the `useradd` (or `adduser`) command are usually sourced from `/etc/skel`.

To answer the OPs question, there are a number of differences in the way different distributions choose to implement their directory structure. That, and the default packages they ship with are the whole reason they exist. My best recommendation is to pick a distro, and learn the generalities you can from it.

Most configurations are found in `/etc/`. Most defaults can be found in `/etc/default`. `/opt` is usually after market software, or placed there to not conflict with the base system (for example, the Fedora/CentOS SCL installs newer toolsets, such as GCC/LD/Make into `/opt, though loads of proprietary software also installs there to not have to bother with proper packaging). `/usr` will be where all the system-provided tools and documentation will live. `/var` is used by programs and daemons to store their state.

Any directory can live on a different partition or disk. Use the `df -h` command to get an overview of your mount points. Also, unlike Windows, a disk or partition doesn't live next to all the others. They can all be interleaved into the root directory structure. Just because `/` is only 5GB doesn't mean you can't have a 2TB home directory or 30GB of programs and librairies installed.

Re: Ask HN: Recommended guides for learning filesystems?

#14

I think you're asking two different questions here. What are some standard conventions for where system files are placed in Ubuntu & Linux? And how are filesystems implemented. For file placement you might start here: https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard Though I'd caution that it's not a strict standard, and you find that many linux distributions vary from it in particular ways. For the implem…

> For file placement you might start here: https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard

And if you're at all interested in BSD file layout, there's hier(7): https://www.freebsd.org/cgi/man.cgi?hier(7) .

Re: Linux inodes (FreeBSD calls them "vnodes," short for virtual inodes, to distinguish the generic API from filesystem-specific per-file data, which it calls inodes), there's vnode(9) and VFS(9) to get started:

https://www.freebsd.org/cgi/man.cgi?vnode(9)

https://www.freebsd.org/cgi/man.cgi?VFS(9)

Re: Ask HN: Recommended guides for learning filesystems?

#15
Xv6 is usually a good source to learn about OS primitives: https://pdos.csail.mit.edu/6.828/2016/xv6.html

I have not looked at the filesystem implementation, but since it is designed as a teaching OS, my guess is that it should be a good entry point.

https://github.com/mit-pdos/xv6-public/blob/master/fs.c

Re: Ask HN: Recommended guides for learning filesystems?

#16
post #13
post #4

I can't think of any guides. I picked up most of my know-how through using Linux (Ubuntu, specifically). A couple things for you which may be obvious, but a good place to start nonetheless: / - This is Root. Most of your system files are in this directory. /home/username/ - This is your home directory, a common abbreviation is "~/" (tilde). If you are a windows user, this is the equivalent of the file system you are…

Just to clarify: you typically don't have any files under `/`. It is literally the `root` of the directory structure. Nothing else. It could theoretically not be mounted at all, if all subdirectories are mounted individually (or it used to, I'm not convinced that's still the case). In addition, you most typically wouldn't find the defaults in `/`, for the reason listed above. The default files copied over by the `use…

> It could theoretically not be mounted at all, if all subdirectories are mounted individually (or it used to, I'm not convinced that's still the case).

The submounts need something to mount on. Root could conceivably be an in-memory only filesystem with a few directories automatically populated for submounts to mount on, though.

Re: Ask HN: Recommended guides for learning filesystems?

#17
In university, one of my projects in Operating Systems was to build a file system.

I'd recommend anyone to do the same!

It does not have to be anything magical...just try to build a basic program that can emulate a file system (read files, write files, list files, have links, edit files, edit names, delete files, copy etc.)

The aim here is NOT to have a file system that you'll use daily, but to understand the concepts by programming them.

While this book goes into some details about it [0], I "understood" how it all worked together by building one.

FYI - I think the book focuses on C when giving examples, but if you know the concepts, it can be built in any language (Go, Java etc.)

[0] - https://www.amazon.com/Operating-System-Concepts-Abraham-Sil...

Re: Ask HN: Recommended guides for learning filesystems?

#18
post #16
post #13

Earlier quoted context omitted.

Just to clarify: you typically don't have any files under `/`. It is literally the `root` of the directory structure. Nothing else. It could theoretically not be mounted at all, if all subdirectories are mounted individually (or it used to, I'm not convinced that's still the case). In addition, you most typically wouldn't find the defaults in `/`, for the reason listed above. The default files copied over by the `use…

> It could theoretically not be mounted at all, if all subdirectories are mounted individually (or it used to, I'm not convinced that's still the case). The submounts need something to mount on. Root could conceivably be an in-memory only filesystem with a few directories automatically populated for submounts to mount on, though.

that's called initramfs.

Re: Ask HN: Recommended guides for learning filesystems?

#19

"The Design and Implementation of the FreeBSD Operating System" not only does a great job at covering how the UFS filesystem is implemented, but also does a great job at explaining how and Unix systems are implemented. I highly recommend this book to anyone with an interest in Unix internals. https://www.amazon.com/Design-Implementation-FreeBSD-Operati...

Came here to say this. Fantastic book for self-learners.

Re: Ask HN: Recommended guides for learning filesystems?

#20

A good book, but not widely known (maybe a little low level, but still...) Ah, it's also free ;) From the the haiku project website: https://www.haiku-os.org/legacy-docs/practical-file-system-d...

This also covers the design of the Be File System, for those who don't know.
Post reply on HN