In this lesson,
we're going to discuss how to manage file systems
including all the tools available
in the Linux environment to accomplish practical tasks.
Now to manage our file systems,
we're going to use lots of different files and configurations.
For example, we're going to start
by discussing the /etc/mtab file.
This file is very similar
to the /proc/mounts file
in the way it reports the status
of currently mounted file systems.
However, the /proc/mounts file is typically more accurate
and includes more up to date information
about the file systems than does the /etc/mtab file.
The /proc/partitions file is part of the virtual file system
that contains information about each and every partition
that is currently attached to the system.
The format of the /proc/partition file contains columns
including things like major, minor,
number of blocks and name.
The major column represents the class of device,
so that it can be mapped to an appropriate driver.
The minor column separates partitions into physical devices,
while the number of blocks column refers
to the number of physical blocks
that the partition takes up.
And the name column refers to the name of the partition.
Another command we can look at is the LS block column.
Now lsblk is the command that's going to be used
to display all the information about block storage devices
that are currently available on the given system.
The output is going to be displayed
in a tree-like format with each physical disk
at the top of the tree and each partition
or logical volume branching off from that device.
The information displayed here is going to include the names,
the major and minor numbers, the size, the device type,
and the mount point.
The proper way to use this command is to type lsblk,
the options, and then the device name.
There are lots of options in this command
that you can choose from depending on your needs.
For example, if you use the -a option,
it's going to list out empty devices,
as well as devices that have files on them.
If you use the -r option,
the device list is going to exclude devices
from the output that you provide
as a list of comma separated, major device numbers.
If you use the -f option,
it's going to display additional system information.
Whereas if you use the -l option,
it's going to display your results in a list format.
And finally, if you use the -m option,
it's going to display permission information
for all of your devices.
Another command we can look at is the block ID
or blkid command.
This offers similar functionality to lsblk,
but it simply prints out each block device
in a flat format and includes some additional information
like the device in partitioning UUID
and the file system type.
However, normally I like to use it as lsblk-f
if you want this type of information
instead of using blkid,
but if you want to use blkid, you can do that
by entering in blkid, the options, and the device name.
Now, when it comes to managing file systems and partitions,
some tools are designed to only work
with specific file system types like FAT
or EXT or NTFS or XFS or something like that.
Now, some of these can work with multiple types
or all types, but some specific tools work better
for specific file systems.
If you're going to work with the EXT file system,
which is the default on Linux,
there are several tools that you can use
on essentially any generation of the EXT file system type,
whether it's ext2, three, or four.
Some of the most common and useful tools
for managing EXT file systems include e2fsck,
resize2fs, tune2fs, and dumpe2fs.
At any times, a file system error can occur
due to a power failure, a hardware failure,
or an improper shutdown of your system.
If this happens, you're going to use the fsck command.
Now the fsck command is going to be used to check
for the correctness and validity of a file system.
Most systems automatically run the fsck command
at boot time, so that any errors
if they're found, can be detected and corrected
before the system is used.
A file system must be unmounted
before it can be scanned with fsck
to prevent damage to the file system.
To run fsck, you're going to type fsck, the options,
and the device or file system name.
Sometimes a repair is going to be required
in order to mount or modify a file system.
Even if a check does not report any damage
to the file system,
it might still consider it damaged internally
and require a repair.
You can always use fsck-r
and the device or file system name to repair a file system.
However, this option should not be used
when checking multiple file systems simultaneously.
If you're a system administrator
and you're working on a Linux system,
resizing or growing a file system
can be a challenging task for you.
You're going to need to resize an existing partition
when your partition gets full and you need more space.
In that case, you can use something like resize2fs.
This utility will allow you to increase
or decrease a file system size.
The resize2fs command allows you to resize ext2,
ext3, or ext4 file systems.
It can be used to enlarge
or shrink an unmounted file system locate on a device.
If the file system is mounted, it can be used
to expand the size of the mounted file system,
assuming the kernal supports online resizing.
The size parameter is going to specify the requested new size
of that file system.
If no units are specified, the units of the size perimeter
should be the file system block size
for the entire file system,
and it will use that by default.
The size of the file system may never be larger
than the size of the partition though.
If the size perimeter is not specified,
it's going to default to the size of the partition
and fill up all remaining space.
If you want to use this command,
simply type resize2fs, the options,
and the device or file system name
and the desired size to be able to run this command
and resize your partition.
The next one we're going to talk about is tune2fs.
This command is one of the advanced Linux commands
that allows you to adjust various tuneable parameters
to the ext2 and ext3 file systems.
Tuneable parameters enable you to remove reserve blocks,
alter reserve block counts,
specify the number of mounts between checks,
specify the time intervals between checks, and more.
Naturally, it also helps you confirm the existing parameters
configured for your file systems.
You can also use tune2fs to add a journal
to an existing ext2 or ext3 file system.
If the file system is already mounted,
the journal will be visible
in the root directory of that file system.
If the file system is not mounted,
the journal will be hidden.
To run the tune2fs command,
you need to enter tune2fs, the options,
and the device or file system name.
The tune2fs command has various different options
including -j, which is used as an ext3 journal
to an existing file system.
If you use -I, it's going to be used
to specify the maximum time interval
between file system checks,
and you can give it the parameter of days,
months or weeks using d, m, or w.
If you use -c and the maximum mounts count,
you can use this to specify the maximum number of mounts
between file system checks.
If you use the option -C and the mount count,
it's going to be used to specify the number of times
the file system can be mounted.
If you use the option -r, reserve block counts,
it's going to be used to specify the number
of reserved file system blocks.
If you use the option -e and the word continue,
remountro, or panic, you're going to be able to specify
the behavior of the kernel code,
whether the file system should continue
with normal execution,
whether it should remount the file system
in read-only mode,
or whether it should cause a kernel panic
whenever an error is detected.
If you use the option -l,
it's going to be used to list the contents
within the superblock of the file system.
And finally, if you use the option -u with the UUID,
you can specify the UUID for the file system
that you want set.
A file system superblock is something that contains metadata
about the file system including its size,
its type, and its status.
The superblock is critical
to the function of the file system.
If it becomes corrupted, you're going to be unable
to mount and work with that file system.
So, you need to use a tool like fsck
to repair the superblock if it becomes corrupted.
Another command that we need to talk about is dumpe2fs.
Now dumpe2fs is using a Linux system
that allows you to dump the ext2, ext3, or ext4 data.
It'll actually print the superblock
and the block group information for your selected device.
This can be useful when you're troubleshooting
a faulty file system.
To use it, just type dumpe2fs, the options,
and the device or file system name.
As you do this, the dumpe2fs command is going to have
a lot of different options.
For example, if you use -x,
it's going to print a detailed report
about block numbers in the file system.
If you use -b, it's going to print out the bad blocks
in that file system.
If you use -f, it's going to be used to force the utility
to display the file system status
regardless of whether the file system flags are set or not.
And if you use -i, it's going to be used
to display the file system data
from an image file created using the e2image command.
Now just like our EXT file system types,
there's also tools that allow you
to work with XFS file system types.
The XFS_info command is used to display details
about the XFS file system including its block information.
The XFS_admin command is used
to change the parameters of an XFS file system
including its label and its UUID.
If you use XFS_metadump,
it's going to be used to copy the superblock metadata
of the XFS file system and put that in a file.
If you use XFS_growfs, it's going to be used
to expand the XFS file system to fill the drive size.
If you use XFS_copy, it's going to be used to copy the contents
of the XFS file system to another location.
If you use XFS_repair it's going to be used to repair
and recover a corrupt XFS file system.
And finally, the XFS_db is going to be used
to debug an XFS file system.
Another you should be aware of is the lsscsi command,
also known as the LS SCSI command.
This command is used to list information
about SCSI devices that are connected to a Linux system.
The most common type of SCSI device used
in Linux systems these days is storage
and external hard disk drives,
which is why I'm bringing it up here.
If you simply enter lsscsi at the command line interface
and hit Enter, it's can respond with one line
for each SCSI device attached to your system.
For example, it can tell you
that there is a SCSI hard drive connected at 0080,
and it's mounted at /dev/SDA,
and that drive is manufactured by Fujitsu in this example.
If you want to display the size of the disk as well,
you can do that by using the -s option with lsscsi as well.
Most of us, though, aren't really going to be using
a lot of SCSI devices, because they're fairly old
and antiquated by now.
Instead, though, you may come across fiber channel
connected devices instead.
To interact with these devices and display their statistics,
you can use the fcstat command.
By entering fcstat at the command line interface,
you're going to be able to display general statistics
about fiber channel devices
that are connected to your system,
and this usually represents high speed
and large capacity external storage area network arrays.
If you want more detailed statistics,
you can also enter fcstat-e at your command line interface,
and this way you'll display all the statistics
including device specific statistics, link statistics,
and fiber channel for statistic types.
As I said before, you don't have to memorize
every single one of these commands,
but I just wanted to introduce you to them,
because you may come across them in the real world
in working on Linux systems.