paint-brush
A Debian system uses a filesystemby@goerzenandothman

A Debian system uses a filesystem

by Goerzen & OthmanOctober 31st, 2023
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

10. Filesystems A Debian system uses a filesystem to store and manage your data. This chapter introduces you to the filesystem, describes how to add and remove filesystems, and shows you how to back up your system. 10.1 Concepts It’s probably a good idea to explain a little theory before discussing the mechanics of using disks. In particular, you must understand the concept of a filesystem. This can be a bit confusing because it has several meanings. The filesystem refers to the whole directory tree, starting with the root directory /, as described in earlier chapters. A filesystem in general means any organization of files and directories on a particular physical device. “Organization” means the hierarchical directory structure and any other information about files one might want to keep track of: their size, who has permission to change them, etc. So you might have one filesystem on your hard disk, and another one on each floppy disk. “Filesystem” is also used to mean a type of filesystem. For example, MS-DOS and Windows 3.1 organize files in a particular way, with particular rules: Filenames can have only eight characters, for example, and no permission information is stored. Linux calls this the msdos filesystem. Linux also has its own filesystem, called the ext2 filesystem (version two of the ext filesystem). You’ll use the ext2 filesystem most of the time unless you’re accessing files from another operating system or have other special needs. Any physical device you wish to use for storing files must have at least one filesystem on it. This means a filesystem in the second sense—a hierarchy of files and directories, along with information about them. Of course, any filesystem has a type, so the third sense will come into play as well. If you have more than one filesystem on a single device, each filesystem can have a different type—for example, you might have both a DOS partition and a Linux partition on your hard disk.
featured image - A Debian system uses a filesystem
Goerzen & Othman HackerNoon profile picture

Debian GNU/Linux: Guide to Installation and Usage by John Goerzen and Ossama Othman is part of the HackerNoon Books Series. You can jump to any chapter in this book here. Filesystems

10. Filesystems

A Debian system uses a filesystem to store and manage your data. This chapter introduces you to the filesystem, describes how to add and remove filesystems, and shows you how to back up your system.

10.1 Concepts

It’s probably a good idea to explain a little theory before discussing the mechanics of using disks. In particular, you must understand the concept of a filesystem. This can be a bit confusing because it has several meanings.


The filesystem refers to the whole directory tree, starting with the root directory /, as described in earlier chapters.


A filesystem in general means any organization of files and directories on a particular physical device. “Organization” means the hierarchical directory structure and any other information about files one might want to keep track of: their size, who has permission to change them, etc. So you might have one filesystem on your hard disk, and another one on each floppy disk.


“Filesystem” is also used to mean a type of filesystem. For example, MS-DOS and Windows 3.1 organize files in a particular way, with particular rules: Filenames can have only eight characters, for example, and no permission information is stored. Linux calls this the msdos filesystem. Linux also has its own filesystem, called the ext2 filesystem (version two of the ext filesystem). You’ll use the ext2 filesystem most of the time unless you’re accessing files from another operating system or have other special needs.


Any physical device you wish to use for storing files must have at least one filesystem on it. This means a filesystem in the second sense—a hierarchy of files and directories, along with information about them. Of course, any filesystem has a type, so the third sense will come into play as well. If you have more than one filesystem on a single device, each filesystem can have a different type—for example, you might have both a DOS partition and a Linux partition on your hard disk.

10.2 mount and /etc/fstab

This section describes how to mount a floppy or Zip disk, discusses the /dev directory, and addresses distributing the directory tree over multiple physical devices or partitions.

10.2.1 Mounting a Filesystem

On a GNU/Linux system there’s no necessary correspondence between directories and physical devices as there is in Windows, in which each drive has its own directory tree beginning with a letter (such as C:).


Instead, each physical device such as a hard disk or floppy disk has one or more filesystems on it. In order to make a filesystem accessible, it’s assigned to a particular directory in another filesystem. To avoid circularity, the root filesystem (which contains the root directory /) is not stored within any other filesystem. You have access to it automatically when you boot Debian.


A directory in one filesystem that contains another filesystem is known as a mount point. A mount point is a directory in a first filesystem on one device (such as your hard disk) that “contains” a second filesystem, perhaps on another device (such as a floppy disk). To access a filesystem, you must mount it at some mount point.


So, for example, you might mount a CD at the mount point /cdrom. This means that if you look in the directory /cdrom, you’ll see the contents of the CD. The /cdrom directory itself is actually on your hard disk. For all practical purposes, the contents of the CD become a part of the root filesystem, and when you type commands and use programs, it doesn’t make any difference what the actual physical location of the files is. You could have created a directory on your hard disk called /cdrom and put some files in it, and everything would behave in exactly the same way. Once you mount a filesystem, there’s no need to pay any attention to physical devices.


However, before you can mount a filesystem or actually create a filesystem on a disk that doesn’t have one yet, it’s necessary to refer to the devices themselves. All devices have names, which are located in the /dev directory. If you type ls /dev now, you’ll see a pretty lengthy list of every possible device you could have on your Debian system. For a summary of some devices, see Table 2.1 on page [*]. A more thorough list can be found on your system in the file /usr/src/linux/Documentation/devices.txt.


To mount a filesystem, we want to tell Linux to associate whatever filesystem it finds on a particular device with a particular mount point. In the process, we might have to tell Linux what kind of filesystem to look for.

10.2.2 Example: Mounting a CD-ROM

As a simple demonstration, we’ll go through mounting a CD-ROM, such as the one you may have used to install Debian. You’ll need to be root to do this, so be careful; whenever you’re root, you have the power to manipulate the whole system, not just your own files. Also, these commands assume there’s a CD in your drive; you should put one in the drive now. Then start with the following command:


su


If you haven’t already, you need to either log in as root or gain root privileges with the su (super user) command. If you use su, enter the root password when prompted.


ls /cdrom


Use this command to see what’s in the /cdrom directory before you start. If you don’t have a /cdrom directory, you may have to make one using mkdir /cdrom.


mount


Simply typing mount with no arguments lists the currently mounted filesystems.


mount -t iso9660 CD-device /cdrom


For this command, you should substitute the name of your CD-ROM device for CD-device in the above command line. If you aren’t sure, /dev/cdrom is a good guess because the install process should have created this symbolic link on the system. If that fails, try the different IDE devices: /dev/hdc, etc. You should see a message like this: mount: block device /dev/hdc is write-protected, mounting read-only.


The -t option specifies the type of the filesystem, in this case iso9660. Most CDs are iso9660. The next argument is the name of the device to mount, and the final argument is the mount point. There are many other arguments for mount; see the manual page for details.


Once a CD is mounted, you may find that your drive tray will not open. You must unmount the CD before removing it.


ls /cdrom


Confirms that /cdrom now contains whatever is on the CD in your drive.


mount


Displays the list of filesystems again; notice that your CD drive is now mounted.


umount /cdrom


This unmounts the CD. It’s now safe to remove the CD from the drive. Notice that the command is umount with no “n,” even though it’s used to unmount the filesystem.


exit


Don’t leave yourself logged on as root. Log out immediately, just to be safe.

10.2.3 /etc/fstab: Automating the Mount Process

The file /etc/fstab (it stands for “filesystem table”) contains descriptions of filesystems that you mount often. These filesystems can then be mounted with a shorter command, such as mount /cdrom. You can also configure filesystems to mount automatically when the system boots. You’ll probably want to mount all of your hard disk filesystems when you boot, so Debian automatically adds entries to fstab to do this for you.


Look at this file now by typing more /etc/fstab. It will have two or more entries that were configured automatically when you installed the system. It probably looks something like this:


/etc/fstab: static file system information.


<file system> <mount point> <type> <options> #<dump > <pass>


/dev/hda1 / ext2 defaults 0 1 /dev/hda3 none swap sw 0 0 proc /proc proc defaults 0 0 /dev/hda5 /tmp ext2 defaults 0 2 /dev/hda6 /home ext2 defaults 0 2 /dev/hda7 /usr ext2 defaults 0 2 /dev/hdc /cdrom iso9660 ro,noauto 0 0 /dev/fd0 /floppy auto noauto,sync 0 0

The first column lists the device the filesystem resides on. The second lists the mount point, the third indicates the filesystem type. The line beginning by proc is a special filesystem. Notice that the swap partition (/dev/hda3 in the example) has no mount point, so the mount point column contains none.


The last three columns may require some explanation.


The fifth column is used by the dump utility to decide when to back up the filesystem. In most cases, you can put 0 here.


The sixth column is used by fsck to decide in what order to check filesystems when you boot the system. The root filesystem should have a 1 in this field, filesystems that don’t need to be checked (such as the swap partition) should have a 0, and all other filesystems should have a 2. It’s worth noting that the swap partition isn’t exactly a filesystem in the sense that it does not contain files and directories but is just used by the Linux kernel as secondary memory. However, for historical reasons, the swap partitions are still listed in the same file as the filesystems.


Column four contains one or more options to use when mounting the filesystem. You can check the mount manpage for a summary; see section 5.1 on page [*].


10.2.4 Removable Disks (Floppies, Zip Disks, Etc.) Add the following lines to your /etc/fstab file:


/dev/sda1 /mnt/zip ext2 noauto,user 0 0 /dev/sda4 /mnt/dos msdos noauto,user 0 0


From now on, you’ll be able to mount the DOS-formatted Zip disks with the command mount /mnt/dos, and you be able to mount Linux-formatted Zip disks with the command mount /mnt/zip.


If you have SCSI hard disks in your system, you’ll have to change sda to sdb or sdc in the example above.

10.3 Backup Tools

Backups are important under any operating system. Debian GNU/Linux provides several different utilities that you might want to use. Additionally, while many of these utilities were aimed at tape backups originally, you’ll find that they are now being used for other things. For instance, tar is being used for distributing programs over the Internet. Some of the utilities that you’ll find include the following:


◼ Taper is a menu-driven, easy-to-learn backup program that can back up to a variety of media. Its limitation is that it doesn’t handle large (4GB or larger) backups.

◼ dump is designed specifically for tapes; its main strengths are its interface for file restores, low-level filesystem backups, and incremental backup scheduling. Its limitations include the inability to back up NFS or other non-ext2 filesystems and some rather arcane defaults.

◼ GNU tar (short for Tape ARchiver) is an implementation of what is probably the most widely used backup or archiving utility in Linux today. It makes a good general purpose tool and can deal with the widest variety of target media. Additionally, many different systems can read tar files, making them highly portable. tar’s weaknesses include a weaker incremental backup system than dump and no interactive restore selection screen.


10.3.1 tar

Because tar is used so much, and for quite a bit in addition to backups, it is being described here. For more details, see the tar manual page; instructions for viewing manual pages can be found in section 5.1 on page [*].


tar is an archiver. This means that tar can take many files and combine them all into one large file or write them out to a backup device such as a tape drive. Once you have this one large file, you will often want to compress it; the -z option is great for this. Hence, tar offers a great way to distribute programs and data on the Internet, and you’ll find that it is used extensively for this purpose.


Here’s a sample tar command line:


tar -zcvf myfiles.tar.gz /usr/local/bin


Let’s take a look at how this command can be broken down:


tar


Name of the command.—Tells tar that options will follow.


z


Tells tar to use gzip compression automatically; if you use this, it’s good to add a .gz extension as well.


c


Tells tar to create a new archive.


v


This says to be verbose; that is, it tells tar to let you know what it’s doing while it creates the archive.


f


This indicates that the next thing on the command line is the name of the file to be created or the device to be used. If I used /dev/st0 here, for instance, it would write the backup to the tape drive.


myfiles.tar.gz This is the name of the file to be created.


/usr/local/bi


This is the name of the file or directory to store in the archive. It’s also possible to specify several items here.


You may often find tar.gz files (or simply tgz files) on the Internet. You can unpack these with a command like:


tar -zxvf filename.tar.gz




About HackerNoon Book Series: We bring you the most important technical, scientific, and insightful public domain books.


This book is part of the public domain. John Goerzen and Ossama Othman (2004). Debian GNU/Linux : Guide to Installation and Usage. Urbana, Illinois: Project Gutenberg. Retrieved https://www.gutenberg.org/cache/epub/6527/pg6527-images.html


This eBook is for the use of anyone anywhere at no cost and with almost no restrictions whatsoever. You may copy it, give it away or re-use it under the terms of the Project Gutenberg License included with this eBook or online at www.gutenberg.org, located at https://www.gutenberg.org/policy/license.html.