Hands-On Lab Creating Filesystems On Partitioned Devices
Hands-On Lab Creating Filesystems On Partitioned Devices
Creating
Filesystems
on Partitioned
Devices
Contents Related Courses
Create Partitions 1
LPIC-1: System
Superblocks and Inodes 3 Admnistrator -
Exam 101
Filesystem Types 4
Linux Academy
Community
In this lab, you are provided with a CentOS 6 server and three 20GB disks to use for the creation of
filesystems. We also review various filesystem types and additional commands for making swap systems,
raid systems, and more.
Create Partitions
Log in to the server using the credentials provided on the Hands-on Lab page. Use sudo su - to switch
to the root user.
[root@linuxacademy] fdisk -l
Disk /dev/xvde: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7d833f39
We want to use /dev/xvdg as our partitioned device, adding three partitions of various sizes:
-1-
Creating Filesystems on Partitioned Devices Linux Academy
-2-
Creating Filesystems on Partitioned Devices Linux Academy
One statistic tracked in the superblock is inode statistics. Every file or directory has an associated inode, and
each inode is a unique number on the partitions. The inode itself contains information related to the file (or
directory) but does not contain the file name. Instead, it tracks the list of blocks that make up the data and
now to retrieve that data.
We can view the inodes related to a file using the -i flag with ls:
[root@linuxacademy] ls -i /var/log/messages
110 /var/log/messages
The number to the left is the inode number for that file.
-3-
Creating Filesystems on Partitioned Devices Linux Academy
This tells us not only the inode number, but information such as the block amounts, IO block information,
permissions, and more.
The _block IO_ amount, in particular, notes the size of each block; 4096 in this instance. This is the
minimum allocated block of data that a file can use. So even if we have a file only 3 bytes in size, it will still
take up about 4 bytes due to the 4096 block IO setting. For systems with a number of very small files, this
number can be adjusted at filesystem creation. This can also be set higher.
Additionally, we can see the amount of inodes set at filesystem creation, and how many have been used:
[root@linuxacademy] df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/xvde1 384272 43625 340647 12% /
tmpfs 76302 1 76301 1% /dev/shm
Since we have not created the /dev/xvdg filesystem yet, we instead can only see the information for /
dev/xvde and the tmpfs system. Your numbers may vary on your own server, but in this instance, we can
see we have 384272 inodes on the system, with 340647 free and 43625 used.
Filesystem Types
Linux Extended Filesystems (ext)
The ext filesystem type includes ext (no longer supported), ext2 (legacy), ext3, and ext4. ext3 includes
journaling, which allows for easier recovery from disk issues. ext4 also includes journaling, as well a
various performance enhancements, and is the most common to see on newer filesystems.
-4-
Creating Filesystems on Partitioned Devices Linux Academy
ReiserFS is one of the first filesystems to offer journaling, while btrfs builds on this to add extra administration
features and increased performance on larger files.
The ISO 9660 filesystem is common on CD-ROMs but not often used on Linux, while the UDF filesystem
is used for DVDs.
VFAT is an older DOS-based partition type occasionally used in USB keys because it can be read by both
Windows and Linux systems.
Create a Filesystem
mkfs
To create a filesystem of any type, we use the mkfs command. This can be done in two ways. First, by
appending a period and then the filesystem type to the command itself (mkfs.fstype). Alternatively,
mkfs can be used with the -t flag to define a filesystem type.
Depending on the size of the filesystem, this may take time to format. We can see from the output that this
-5-
Creating Filesystems on Partitioned Devices Linux Academy
defines our superblocks and automatically schedules filesystem checks. These are given the default values
for the filesystem but can be changed at filesystem creation via the command line using command line flags
such as -O and -b.
For example, we can create an ext4 system, define the block size (-b), set reserved disk space for the root
user (-m), define a label (-L), and use less superblocks than usually defined (-O):
mke2fs
For ext-based systems, we can also use the mke2fs command. This creates only filesystems in the ext2,
ext3, and ext4 format. This can work the same way as the mkfs command above but is also able to use a
configuration file to create the filesystem.
To view the configuration file, navigate to the /etc directory, and view the mke2fs.conf file in your
chosen editor:
[root@linuxacademy] cd /etc/
[root@linuxacademy] $EDITOR mk2efs.conf
-6-
Creating Filesystems on Partitioned Devices Linux Academy
[defaults]
base_features = sparse_super,filetype,resize_inode,dir_
index,ext_attr
enable_periodic_fsck = 1
blocksize = 4096
inode_size = 256
inode_ratio = 16384
[fs_types]
ext3 = {
features = has_journal
}
ext4 = {
features = has_journal,extent,huge_file,flex_bg,uninit_
bg,dir_nlink,extra_isize
inode_size = 256
}
ext4dev = {
features = has_journal,extent,huge_file,flex_bg,uninit_
bg,dir_nlink,extra_isize
inode_size = 256
options = test_fs=1
}
small = {
blocksize = 1024
inode_size = 128
inode_ratio = 4096
}
floppy = {
blocksize = 1024
inode_size = 128
inode_ratio = 8192
}
news = {
inode_ratio = 4096
}
largefile = {
inode_ratio = 1048576
blocksize = -1
}
largefile4 = {
inode_ratio = 4194304
blocksize = -1
}
hurd = {
blocksize = 4096
inode_size = 128
}
This file defines the defaults values used by the mke2fs command, such as the defined superblocks and
scheduled filesystem checked mentioned in the previous section. We can also set the inode size, blocksize,
inode ratio, and more. Close the file once reviewed.
Additional filesystem commands to be aware of (but are not fully tested on the LPIC exam) are the mkswap
command, which creates swap space on a partition, and the mkraid command that defines a raid array.
Additionally, there is the mknode command that allows for the creation of special files and devices in the
/dev directory, and mkisofs and mkudf, which creates filesystems for CD-ROMs and DVD-ROMs,
respectively.
Review
We have now learned how to create new filesystems, as well as change the various defaults during filesystem
creation. Take this time to use the remaining partition and additional available disks to further practice
filesystem creation.
-8-