0% found this document useful (0 votes)
31 views

Hands-On Lab Creating Filesystems On Partitioned Devices

The document discusses creating filesystems on partitioned devices in Linux. It covers creating partitions, filesystem types, superblocks and inodes, and using commands like fdisk, mkfs, and mke2fs to build filesystems.

Uploaded by

Iyyappan Mani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Hands-On Lab Creating Filesystems On Partitioned Devices

The document discusses creating filesystems on partitioned devices in Linux. It covers creating partitions, filesystem types, superblocks and inodes, and using commands like fdisk, mkfs, and mke2fs to build filesystems.

Uploaded by

Iyyappan Mani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Hands-on Lab

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 Extended Filesystems (ext) 4


Related Videos
Extent Filesystem (xfs) 4

ReiserFS, Btrfs, ISO 9660, UDF, and VFAT 5


Create Partitions
Create a Filesystem 5 and Filesystems
(Filesystem Types
mkfs 5 and Creation)
mke2fs 6

Additional Filesystem Commands 7


Need Help?
Review 8

Linux Academy
Community

... and you can


always send in a
support ticket on
our website to talk
to an instructor!

Lab Connection Information


• Labs may take up to five minutes to build
• The IP address of your server is located on the
Hands-on Lab page
• Username: linuxacademy
• Password: 123456
• Root Password: 123456
Creating Filesystems on Partitioned Devices Linux Academy

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.

First, we want to run fdisk -l to view the available disks:

[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

Device Boot Start End Blocks Id System


/dev/xvde1 1 766 6144000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/xvde2 766 784 146432 82 Linux swap /
Solaris
Partition 2 does not end on cylinder boundary.

Disk /dev/xvdg: 21.5 GB, 21474836480 bytes


255 heads, 63 sectors/track, 2610 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: 0x00000000

Disk /dev/xvdf: 21.5 GB, 21474836480 bytes


255 heads, 63 sectors/track, 2610 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: 0x00000000

Disk /dev/xvdj: 21.5 GB, 21474836480 bytes


255 heads, 63 sectors/track, 2610 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: 0x00000000

We want to use /dev/xvdg as our partitioned device, adding three partitions of various sizes:

[root@linuxacademy] fdisk /dev/xvdg

-1-
Creating Filesystems on Partitioned Devices Linux Academy

Command (m for help): n


Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +4G
Command (m for help): p

Disk /dev/xvdg: 21.5 GB, 21474836480 bytes


255 heads, 63 sectors/track, 2610 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: 0x8e0d99a2

Device Boot Start End Blocks Id System


/dev/xvdg1 1 523 4200966 83 Linux

Command (m for help): n


Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (524-2610, default 524):
Using default value 524
Last cylinder, +cylinders or +size{K,M,G} (524-2610, default 2610): +2G
Command (m for help): p

Disk /dev/xvdg: 21.5 GB, 21474836480 bytes


255 heads, 63 sectors/track, 2610 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: 0x8e0d99a2

Device Boot Start End Blocks Id System


/dev/xvdg1 1 523 4200966 83 Linux
/dev/xvdg2 524 785 2104515 83 Linux

Command (m for help): n


Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (786-2610, default 786):
Using default value 786
Last cylinder, +cylinders or +size{K,M,G} (786-2610, default 2610): +5G
Command (m for help): p

Disk /dev/xvdg: 21.5 GB, 21474836480 bytes


255 heads, 63 sectors/track, 2610 cylinders

-2-
Creating Filesystems on Partitioned Devices Linux Academy

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: 0x8e0d99a2

Device Boot Start End Blocks Id System


/dev/xvdg1 1 523 4200966 83 Linux
/dev/xvdg2 524 785 2104515 83 Linux
/dev/xvdg3 786 1439 5253255 83 Linux

Command (m for help): w


The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

Confirm the changes:

[root@linuxacademy] fdisk -l /dev/xvdg


Disk /dev/xvdg: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x8e0d99a2

Device Boot Start End Blocks Id System


/dev/xvdg1 1 523 4200966 83 Linux
/dev/xvdg2 524 785 2104515 83 Linux
/dev/xvdg3 786 1439 5253255 83 Linux

Superblocks and Inodes


A superblock on a disk is the portion of the disk that contains a record of information related to the filesystem.
This includes the filesystem size, inode statistics, and the last time the filesytem has been checked. Normally
located in the first sector of a disk, the superblock is also replicated multiple times throughout the disk to
facilitate recovery. For example, the first backup block on an ext4 system is on block 8193.

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

We can also retrieve more information using the stat command:

[root@linuxacademy] stat /var/log/messages


File: `/var/log/messages’
Size: 20078 Blocks: 40 IO Block: 4096 regular file
Device: ca41h/51777d Inode: 110 Links: 1
Access: (0600/-rw-------) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2017-05-31 11:09:29.390694716 -0400
Modify: 2017-05-31 11:09:28.390215840 -0400
Change: 2017-05-31 11:09:28.390215840 -0400

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.

Extent Filesystem (xfs)


The xfs filesystem is also common among current Linux filesystems. Like ext4, it has enhanced performance;
it also works well with filesystems with a large number of small files, due to a default block size of 2048
(versus the 4096 we saw above).

-4-
Creating Filesystems on Partitioned Devices Linux Academy

ReiserFS, Btrfs, ISO 9660, UDF, and VFAT


These filesystems are less common and will not be tested extensively on the LPIC, past knowing their
names.

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.

Let’s create an ext3 filesystem on /dev/xvdg1:

[root@linuxacademy] mkfs -t ext3 /dev/xvdg1


mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
262944 inodes, 1050241 blocks
52512 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1077936128
33 block groups
32768 blocks per group, 32768 fragments per group
7968 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

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):

[root@linuxacademy] mkfs -t ext4 -b 8192 -m 10 -L LargeData -O sparse_


super /dev/xvdg2
Warning: blocksize 8192 not usable on most systems.
mke2fs 1.41.12 (17-May-2010)
mkfs.ext4: 8192-byte blocks too big for system (max 4096)
Proceed anyway? (y,n) y
Warning: 8192-byte blocks too big for system (max 4096), forced to
continue
Filesystem label=LargeData
OS type: Linux
Block size=8192 (log=3)
Fragment size=8192 (log=3)
Stride=0 blocks, Stripe width=0 blocks
131680 inodes, 263064 blocks
26306 blocks (10.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=285177856
5 block groups
65528 blocks per group, 65528 fragments per group
26336 inodes per group
Superblock backups stored on blocks:
65528, 196584
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

When prompted, input y to proceed past the warning.

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


-7-
Creating Filesystems on Partitioned Devices Linux Academy

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.

This lab is now complete!

-8-

You might also like