Login
Password

Forgot your password?

Configuring Filesystems With Bash

By Edited Feb 26, 2014 0 0

Linux Terminal and Bash can be used to manage all of the filesystems that Linux supports. Hard drives with one of the many varieties of Linux installed typically use ext3 and ext2. XFS and ReiserFS are more high-powered systems, though less common. Bash can also work with the systems found on media devices such as flash drives.

MKFS

mkfs

The mkfs command is used to create filesystems on an already created partition. Make sure you back up any data you have on that partition because it can be wiped out while the partition is going through the formating process. There have been cases where system administrators have had to make use of their favorite recovery tool because they made a typo. If you need to create a partition, use sudo parted, type in your administrator password and then the mkpart command. Learn more about working with partitions here.

A typical mkfs usage might look like, mkfs -t ext3 /dev/sda1. The -text3 /dev/sda1 tells Bash to make an ext3 filesystem on the partition /dev/sda1. If you do not specify the exact type of system you want to use, Bash will automatically use ext2. Using - -verbose or -v will tell you exactly what is happening but, if you use it more than once, Bash will consider it a test run and not actually create the filesystem. Typing in mkfs - -version tells me that the mkfs command I am running on my Linux machine is part of util-linux 2.20.1, which has a fair chance of being outdated considering how swiftly the world of Linux moves. Of course, typing in man mkfs will tell you everything you want to know about this command.

MKE2FS

mke2fs

The mke2fs command is used to make ext2, ext3 and ext4 filesystems and is more often used by expert Linux users who want greater control over their work. This command might also be called as mkfs.ext2, mkfs.ext3 or mkfs.ext4 and will create a filesystem type to match. Useful options include -q for quiet operation if you are using it as part of a script, -t fs_type if you use it as mke2fs, -n for cases where you don't want to actually create the filesystem but want to see what it would do if you leave this option off, and -M last-mounted-directory for setting the last mounted directory for the filesystem. -c is useful for checking the partition for bad blocks before creating the filesystem; use it twice if time is not an issue and you want to do a read-write test. Man mke2fs is one of the longer “man” files and will create a list of many more options and what they do.

DF

df

The df command is used to inspect disk space usage and can be used to inspect the available disk space available on the file system using each file name. The usual syntax is df [OPTION]... [FILE]... If the user types in df without any arguments, the output will provide a chart like the one below, which shows stats for all mounted partitions, including attached media devices.

DF

Useful options include - -total, which provides a grand total of used and available space on all partitions, and -h, which prints out used and available space in units like megabytes or gigabytes. Use -l if inspecting local file systems is a priority.

DU

du

Typing in du without any arguments will give you many more details about the directories on your filesystem and where they are located on your hard drive. If you already know which directory or file you are looking for, the syntax should be du [OPTION] [FILE]. Useful options include -b for file size in bytes, -c for computing totals and -h to provide size in kilobytes, megabytes or gigabytes.

FSCK

fsck

The fsck command is useful when checking for and repairing errors in a Linux filesystem. The syntax is fsck [-lsAVRTMNP] [-C [fd]] [-t fstype] [filesys...] [--] [fs-specific-options], in which filesys can be a mount point, device name, ext2 label or UUID specifier. The fsck operation will return a code that is the sum of the conditions listed in the chart below:

fsck-chart

Anyway, man fsck will tell you everything you ever wanted to know about this command, and it's so long that I don't exactly expect you to memorize it on the first go. However, the option -N provides a good way to see what a particular option would do without actually making any changes to your filesystem.

Learn More About Linux

Going for your certification? It's a tough test, so make sure you have all the resources on your side that you can put together. This book is a good start.

Advertisement
Advertisement

Comments

Add a new comment - No HTML
You must be logged in and verified to post a comment. Please log in or sign up to comment.

Explore InfoBarrel

Auto Business & Money Entertainment Environment Health History Home & Garden InfoBarrel University Lifestyle Sports Technology Travel & Places
© Copyright 2008 - 2016 by Hinzie Media Inc. Terms of Service Privacy Policy XML Sitemap

Follow IB Technology