The Terminal: A Grand Tour

Hi all, and welcome back. Today, lets take a look at the behind-the-scenes action of your Linux distribution. There won’t be any terminal code in today’s post, but I advise you follow along and take a real look with your own eyes. Where else to start besides the / directory? It’s literally the directory of directories. Don’t confuse the / directory with the /root directory. They’re very different.

Next, we’ll head over the /boot directory. In here is where all of your start-up scripts, and kernel images are kept. Also found in this directory are all the files and scripts for your boot loader, in our case, GRUB. GRUB is Grand Unified Boot Loader, and it’s fairly standard on most any recent Linux distro. One notable file you’ll be working with GRUB trouble shooting is your /boot/grub/menu.lst file. It’s the main configuration file for GRUB. I hope you’re writing this down. 🙂

Not far away is the /bin and /sbin directories. They’re chocked full of all the executable files for only the essential programs used by the system and root user, respectively. The /bin directory can seem weird at first. The reason is because there are actually 4 of them. While /bin and /sbin are for essential apps, /usr/bin and /usr/sbin are the rest of the applications in the system, typically those installed by your distro or you, rather than needed by the kernel. /usr/bin is for the everyday user apps, while /usr/sbin is basically filled with non-essential apps for the root user.

The /dev directory is one area that is exclusive to Linux/UNIX OSs. Remember many moons ago when I said that everything in Linux/UNIX is represented as a file? The /dev directory is a shining example of this. It’s comprised entirely of text files for your hardware. The most notable ones are the ones for your harddrives. On older kernel versions, IDE harddrives were known as hda, hdb, hdc, with different partitions as numbers. So, Debian is probably installed to hda1. Perhaps you have Linux dual-booting on a single drive. It’s likely on hda2. Or maybe you’re a 2-harddrive kinda guy (or gal). Linux is on hdb1 perhaps. I’m sure you see the point.

Probably the second largest directory in any Linux distribution would have to be /etc. It’s entire purpose is for configuration files. If you want something changed or tweaked, /etc is where you want to be. It’s not just system config files either. It’s also full of config files for various network services. Want to change you password? /etc/passwd. Want to see what partitions are currently mounted? /etc/fstab. Want to know hostnames and IP addresses? /etc/hosts. How ’bout network services? /etc/init.d. (For quite some time, Gnome’s Network Manager was completely worthless, so in my years with Debian, I’ve gotten to know /etc/network/interfaces pretty well. If you want to toggle between DHCP and static IPs and designate your IP address, Netmask, and Network address, this is the file if Network Manager isn’t cutting the mustard).

The /home directory is the directory for all of the /home directories for each user on your system. Without root privileges, your /home/username directory is the only place where you have the power to create/destroy files and wreak your own havoc. It’s pretty much the same as the C:\Documents and Settings folder in a standard-fare Windows installation.

Speaking of Windows, I’m sure you know that Windows programs need DLL files, right? DLL stands for Dynamic Link Library. Linux/UNIX apps don’t exactly need DLLs but their programs do need library files, or .lib files. This is where the /lib directory comes into play. It’s nothing but .lib files for various system and user apps.

If you’ve been reading lately, you might have seen an article by OStatic’s Kristin Shoemaker, citing that Linux support more devices than any other OS. Amazing what Open-Source software is capable of, isn’t it? back on topic here, this means that the Linux kernel supports millions upon millions of various devices. Can you imagine how slow and bloated our Linux kernel would be if it contained every driver for every supported device, just in case you needed it? Well this is where the /initrd directory comes in. You’re likely to not be in this neck of the Linux filesystem woods very often, but it’s still worth going over. Initrd is short of Initial Ram Drive image, also called Ram Disk. See, instead of Linux having every possible driver compiled into it’s kernel, it sets up device drivers as kernel modules, for use when it needs them. During the boot process, the modules and the kernel are both loaded into memory, aka, the ram disk. The modules are copied into the kernel as they become available in the ram disk, and the ram disk is released when the kernel has all the modules it needs for the available hardware. Boiled down, what initrd does is creates a block device backed by memory, loads it with data from a file, then mounts the device to create a filesystem image. In contrast initramfs, or INITial RAM File System, creates a file system image from a file, without mounting any block-device, like a harddrive. initramfs uses filesystems like tmpfs and ramfs, which weren’t around when initrd became popular. With initrd, the file contains a filesystem in on-disk format. With initramfs, the file contains a compressed CPIO archive. It’s just more convenient for a system builder to create and modify the contents of the filesystem with initramfs. If I’m not too late, to try and make a long explanation shorter, the /initrd directory is the home of initrd and initramfs.

The /opt and /usr directory are all for your everyday user software. executables, documentation, some library files…. it’s all there. Technically, the installed software is in the /usr/local/ or /usr/local/bin directories, but we’re not splitting hairs here. Some examples; /usr/share/X11 has support files for the X-windows System, /usr/share/dict contains dictionaries for the spell checker, /usr/share/doc features various documentation files, usr/share/man is comprised of all the man files, /usr/src contains all of your source code files of your installed applications, and the Linux kernel. The /usr directory is probably the largest single directory in the whole Linux filesystem. The /opt directory is used in the same way, but is used for system-wide 3rd party sofwares like Adobe Flashplayer or Sun Microsystem’s Java Runtime Environment.

The /var directory is permanent storage for files created by programs for system/network services, like log files. In fact, /var/log is where all your log files are kept, and /var/spool are used to que files requested by a program. If you’re running local mail services on your network, your mail will likely be in /var/spool/mail by default.

One of the most interesting directories in my opinion would be the /proc directory. The /proc directory is actually a link to the /proc virtual filesystem. It’s used for keeping tabs on system resources and kernel variables. Have a look for fun. Edit files at your own risk!!! (in other words, I’m strongly advising you don’t touch anything!!!).

There are also a few directories that don’t need lengthy explanations. /net, /mnt, /misc, /lost+found, /root, /tmp, and /media to be exact.The /lost+found directory’s sole purpose in life is to be the orphanage for the rogue files found by running fsck (File System ChecK). The /net directory is used mainly for mounting network shares, while the /mnt directory is used by HAL for auto-mounting directories listed in your /etc/fstab, and to mount local partitions. The /misc directory is usually empty, but can be put to many uses like more space for mounting local partitions, or unpacking archive files. The /root directory. is the home directory for the root user account, while the /tmp directory is used by running applications to store temporary data.

Pretty interesting, eh? I hope you enjoyed the tour, and I hope that wasn’t all too much information to digest. It’s not imperative hat you have an incredibly detailed knowledge of Linux kernel programming or Linux/UNIX software engineering. As a Network Administrator, it’s hardly your job to be a kernel engineer. However, a basic understanding of what’s there and why is manditory for any Linux professional. If there’s anything you’re still not clear on, or you find something that you’re interested in knowing more about, a quick Google search on “Linux Filesystem Tour” will prove I’m not the only one to write such a piece. I had fun and I hope you did too. Keep checking back soon as I’ve got a few more irons in the fire and I’ll have my next post up soon. Keep reading, keep experimenting and don’t be afraid to ask questions.


aka That Linux Guy


2 Responses to The Terminal: A Grand Tour

  1. chandramde says:

    I like this post. I think it would be nicer if you can spend a little extra time to make it much more readable. For example: /proc is better than just /proc.

    Keep writing, Andrew!

    Chandra MDE

  2. […] The Terminal: A Grand Tour […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: