104.1 Create Partitions and Filesystems
Candidates should be able to configure disk partitions and then create filesystems on media such as hard disks. This includes the handling of swap partitions.
Key Knowledge Areas
- Use various mkfs commands to set up partitions and create various filesystems such as: ext2, ext3, ext4, xfs, reiserfs v3 and vfat.
Linux File Systems
In order to persist data on a disk you need to create a file system on it first. At installation time you will be asked which type of file system should be used to format your configured block device before installation can occur.
Linux supports many filesystems the most popular being the extended (ext2,ext3,ext4) file system family. The ext3 filesystem has been the default Linux filesystem over the last several years but has recently begun to be replaced by ext4, the latest iteration of the extended filesystem.
Ext4 is backwardly compatible with ext3 and ext3 and ext4 are both backwardly compatible with ext2. Ext4 is considered an interim solution while a more modern filesystem, called Btrfs, is developed. The features required from a modern filesystem include, pooling, snapshots, checksums and integral multi-device spanning, all of which btrfs will deliver in due course.
Ext2 File System
The Second Extended File System (ext2fs or ext2), sometimes referred to as the Linux native filesystem, was developed in 1993 and became the dominant filesystem used on Linux. Due to its widespread use over several years, ext2 is regarded as a well tested and reliable filesystem. It is also consequently the best supported filesystem on Linux with a range of management tools and utilities. The utilities are part of the e2fsprogs package available on your Linux distribution and are often installed by default. The utilities and tools included in the e2fsprogs package include:
- e2fscka fsck program that checks for and corrects inconsistencies
- mke2fsused for creating ext2 file systems
- tune2fsused to modify file system parameters
- dumpe2fswhich prints superblock and block group information.
- debugfsused to manually view or modify internal structures of the file system
Ext3 File System
The ext3 filesystem is an ext2 filesystem with journaling capabilities. Journaling improves reliability and eliminates the need to check the file system after an unclean shutdown, which results in faster start ups. One of the advantages of having ext3 being backwardly compatible with ext2 is that it allow well-tested and mature file system maintenance utilities, such as fsck and tune2fs for monitoring, checking and repairing ext2 file systems to also be used with ext3 without major changes.
Ext4 File System The ext4 filesystem is an extension to ext3, meant to extend storage limits and add other performance improvements. Features include large volume and file size support, backward compatibility with ext3 and ext2 which allows use of maintenance utilities available, use of checksums in the journal to improve reliability, faster file system checking and snapshot support.
XFS File System
XFS is a high-performance journaling file system created by Silicon Graphics, originally for their IRIX operating system. The code was donated by Silicon Graphics and ported to the Linux kernel. XFS has a good reputation for speed and robustness and is particularly good at handling large files. XFS is much less popular than ext and consequently there are fewer tools and utilities to monitor and maintain XFS filesystems. The XFS tools are found as part of the xfsprogs package on most Linux distributions and include:
- xfs_fsr - Used to defragment mounted XFS file systems. When invoked with no arguments, xfs_fsr defragments all regular files in all mounted XFS file systems. This utility also allows users to suspend a defragmentation at a specified time and resume from where it left off later.
- xfs_bmap - Prints the map of disk blocks used by files in an XFS filesystem. This map list each extent used by a specified file, as well as regions in the file with no corresponding blocks (i.e. holes).
- xfs_info - Prints XFS file system information.
- xfs_admin - Changes the parameters of an XFS file system. The xfs_admin utility can only modify parameters of unmounted devices/file systems.
- xfs_copy Copies the contents of an entire XFS file system to one or more targets in parallel.
- xfs_metadump - Copies XFS file system metadata to a file. The xfs_metadump utility should only be used to copy unmounted, read-only, or frozen/suspended file systems; otherwise, generated dumps could be corrupted or inconsistent.
Reiserfs File System
ReiserFS is another general-purpose, journalled file system designed by Hans Reiser. It is particularly efficient at handling a large number of small files. It was one of the first journalling file systems for Linux and is often used in situations where the drive will store a large number of small files. Other filesystems that are not as efficient at handling small files, end up wasting a lot of space as their minimum block allocation often exceeds the size of the file. Reiserfs, like the XFS system, also has a fewer number of tools and utilities than the extended file system. Utilities for reiserfs are found in the reiserfsprogs package and include reiserfsck.
File System Formatting
In order to create a filesystem you need to format the partition. To create a file systems while running a Linux system you need to install the associated formatting tools which should be available as a package. The formatting tools follow the naming convention of the filesystem type preceded with the mkfs, for make filesystem.
The formatting tool for ext2 for example is mke2fs. Similarly the formatting tool for the xfs file system is mkfs.xfs while for reiserfs it is mkfs.reiserfs The mkfs command is a wrapper around each filesystem specific tool and acts as a front for all the different file system types. The syntax for using the mkfs command is:
mkfs –t <fstype> <DEVICE>
The ext3 filesystem is created by specifying an ext2 file system and passing in the -j parameter to enable journaling support.
Example 1: Making a xfs filesystem
# mkfs –t xfs /dev/hda12
Example 2: Making a ext2 filesystem
# mke2fs /dev/hda11 [or mkfs –t ext2 /dev/hda11]
Example 3: Making a ext3 filesystem
# mke2fs -j /dev/hda11 [or mkfs –t ext2 -j /dev/hda11]
Example 4: Making a ext4 filesystem
# mkfs.ext4 /dev/hda1 [or mkfs –t ext4 /dev/hda11]
Formatting Swap Space
Swap space is made with the mkswap command. Swap space does not have a real filesystem as the kernel does raw read and writes to swap space to enhance the speed with which it can access cached memory pages. To create swap space you would run
# mkswap /dev/sda2
To activate the swap space you would run the command swapon; for example:
# swapon /dev/sda2
Used files, terms and utilities:
- fdisk (covered in section 102.1)