File Systems (mkfs, mount, fstab)
Remember, the exams are hands-on, so it doesn’t matter which method you use to achieve the result, so long as the end product is correct.
- Disk Partitioning (fdisk, parted)
- Logical Volume Management
- Unified Key Setup (LUKS) Encrypted File Systems
If you have used the “Disk Utility” to create your partitions, or they were created during the installation by “Disk Druid”, they will already be formatted with a file system, so this step will be unnecessary.
Once you have created a suitable partition, it is likely you will want to create a file system on it. This can be done using one of the variations of the
mkfs command. There are a wide variety of file system types available, but the Red Hat certification exams only consider ext2, ext3 and ext4. The ext4 file system is the default for RHEL6, so I will focus on that. The
mkfs command destroys any data on the partition, so be very careful when issuing the command. The following three commands all format and ext4 file system on the specified partition.
# mkfs.ext4 /dev/sdb3 # mkfs -t ext4 /dev/sdb3 # mke2fs -t ext4 /dev/sdb3
Not surprisingly, to create an ext2 or ext3 file system simply replace ext4 in the above commands.
Although not required for the certification exam, the xfs file system is quite important for single instance Oracle installations. If you are storing datafiles on a cooked file system, as opposed to ASM, you should probably consider using xfs, rather than any of the ext* file systems.
The RHEL6 Storage Administration Guide contains more information about file system options for the ext* and xfs file systems, but these are not part of the exam syllabus.
mount and umount
Once a file system has been created, it can be mounted using the
mount -t type device dir mount -t type -o options device dir
For example, the following output shows the creation of a new directory, which is used as a mount point for the “/dev/sdb3” ext4 volume.
# mkdir /u02 # mount -t ext4 -o rw /dev/sdb3 /u02 # df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_rhce1-lv_root 26G 3.0G 21G 13% / tmpfs 1002M 260K 1002M 1% /dev/shm /dev/sda1 485M 52M 409M 12% /boot /dev/sdb3 1.9G 35M 1.8G 2% /u02 #
The mount will only last until the next reboot, unless an entry is placed in the “/etc/fstab”.
umount command is used to unmount file systems.
# umount /u02 # df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_rhce1-lv_root 26G 3.0G 21G 13% / tmpfs 1002M 272K 1002M 1% /dev/shm /dev/sda1 485M 52M 409M 12% /boot #
Adding entries into the “/etc/fstab” allows you to make mounts persistent between reboots. If you have used the
mount command, much of the entries will look familiar. The basic format of an entry is shown below.
fs_spec fs_file fs_vfstype fs_mntops fs_freq fs_passno
These elements are explained below.
- fs_spec : The device name, UUID or the label of the volume to be mounted. Remote file systems are referenced in a slightly different manner.
- fs_file : The mount point.
- fs_vfstype : The type of file system (ext4, xfs, nfs, cifs etc.).
- fs_mntops : Any required mount options.
- fs_freq : When set to “1”, data is automatically dumped by the
dumpcommand on shutdown. When set to “0”, it is not.
- fs_passno : Used by fsck to determine the order of file system checks on reboot. Set the root file system to “1” and other local file systems to “2”. Remote or removable file systems should be set to “0”.
Before looking at some sample entries, it’s worth understanding how the UUID and volume labels can be identified. The
blkid command displays the UUID of the specified device, or all devices if no device is specified.
# blkid /dev/sdb3 /dev/sdb3: UUID="e98bc512-f45c-4a93-ac84-d96b7d9f7750" TYPE="ext4" #
If you have set a volume label, it will also be displayed.
# e2label /dev/sdb3 "Data_Volume" # blkid /dev/sdb3 /dev/sdb3: UUID="e98bc512-f45c-4a93-ac84-d96b7d9f7750" TYPE="ext4" LABEL="Data_Volume" #
The following output shows typical fstab entries for a variety of mounts.
# Mount using device name /dev/sdb3 /u02 ext4 defaults 1 2 # Mount using UUID UUID=e98bc512-f45c-4a93-ac84-d96b7d9f7750 /u02 ext4 defaults 1 2 # Mount using label LABEL=Data_Volume /u02 ext4 defaults 1 2 # Mount an NFS share. 184.108.40.206:/nfs_share /u02 nfs defaults 0 0 # Mount a samba (CIFS) share using in-line credentials or a credentials file. //220.127.116.11/share /u02 cifs rw,username=my_user,password=mypassword 0 0 //18.104.22.168/share /u02 cifs rw,credentials=/root/.smbcred 0 0 # Mount an ISO file. /u01/myfile.iso /u02 df,iso9660 loop,ro,auto 0 0 # Setting the ownership of the mount point //22.214.171.124/share /u02 cifs rw,credentials=/root/.smbcred,uid=500,guid=500 0 0
For more information about using a credentials file, look here.
The are a variety of mount options and the ones you choose will depend on what you are trying to achieve. Vendors like Oracle will often specify required options for specific file systems.
Swap partitions are managed a little differently than regular file systems. A swap partition is formatted using the
# mkswap /dev/sdb2 Setting up swapspace version 1, size = 1951892 KiB no label, UUID=83aa1e29-10c1-4821-9491-371df4edc5cb #
Including the “-L” option will allow you to label the swap partition at the same time.
# mkswap -L swap_vol /dev/sdb2 Setting up swapspace version 1, size = 1951892 KiB LABEL=swap_vol, UUID=eee7cd19-fe63-4bf9-a085-835112099c8f #
The swap partition is then enabled using the
swapon command. The “-v” flag is not necessary, but verbose mode is a little more reassuring as without it the command produces no output.
# swapon -v /dev/sdb2 swapon on /dev/sdb2 swapon: /dev/sdb2: found swap signature: version 1, page-size 4, same byte order swapon: /dev/sdb2: pagesize=4096, swapsize=1998741504, devsize=1998743040 #
We can see the current swap volumes using the “-s” flag.
# swapon -s Filename Type Size Used Priority /dev/dm-1 partition 4128760 0 -1 /dev/sdb2 partition 1951888 0 -2 #
swapoff command is used to disable a swap volume.
# swapoff /dev/sdb2 # swapon -s Filename Type Size Used Priority /dev/dm-1 partition 4128760 0 -1 #
Upgrading File Systems
The preferred option for any file system upgrade is to create a new file system and migrate the data to it, but this is not always possible. Before doing any file system upgrade, you should do the following things:
- Unmount the file system.
- Run the
fsckcommand to make sure the file system is OK.
- Perform a backup of the data on the file system.
To upgrade an existing ext2 file system to ext3, use the
tune2fs command with the “-j” flag to turn on journalling.
# tune2fs -j /dev/sdb4 Creating journal inode: done This filesystem will be automatically checked every 23 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. #
To convert an existing ext3 file system to ext4 issue the
tune2fs command with the following options.
# tune2fs -O extents,uninit_bg,dir_index /dev/sdb4 tune2fs -O extents,uninit_bg,dir_index /dev/sdb4 tune2fs 1.41.12 (17-May-2010) Please run e2fsck on the filesystem. #
In all attempted ext3 to ext4 conversions on OL6.2 I was prompted to check the file system, as seen above. The file system check repaired the issues in each case.
# e2fsck /dev/sdb4 e2fsck 1.41.12 (17-May-2010) One or more block group descriptor checksums are invalid. Fix<y>? yes Group descriptor 0 checksum is invalid. FIXED. Group descriptor 1 checksum is invalid. FIXED. Group descriptor 2 checksum is invalid. FIXED. Group descriptor 3 checksum is invalid. FIXED. Group descriptor 4 checksum is invalid. FIXED. Group descriptor 5 checksum is invalid. FIXED. Group descriptor 6 checksum is invalid. FIXED. Group descriptor 7 checksum is invalid. FIXED. Group descriptor 8 checksum is invalid. FIXED. Group descriptor 9 checksum is invalid. FIXED. Group descriptor 10 checksum is invalid. FIXED. Group descriptor 11 checksum is invalid. FIXED. Group descriptor 12 checksum is invalid. FIXED. Group descriptor 13 checksum is invalid. FIXED. Group descriptor 14 checksum is invalid. FIXED. old_data contains a file system with errors, check forced. Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information old_data: 11/122160 files (0.0% non-contiguous), 16598/487974 blocks #
After performing a file system upgrade, you should always do the following things.
- Perform a file system check (fsck or e2fsck).
- If the file system is present in the “/etc/fstab”, amend the fs_vfstype entry so it is mounted as the correct file system type.
Checking File Systems
e2fsck) command is used to check an unmounted file system. Simply pass the device as a parameter.
# fsck /dev/sdb4 e2fsck 1.41.12 (17-May-2010) old_vol: clean, 11/122160 files, 8397/487974 blocks # # e2fsck /dev/sdb4 fsck from util-linux-ng 2.17.2 e2fsck 1.41.12 (17-May-2010) old_vol: clean, 11/122160 files, 8397/487974 blocks #
Remember, if the file system is mounted, it should be unmounted first (or mounted as read only). In the following example, the file system is mounted to the “/u02” mount point.
# umount /u02 # e2fsck /dev/sdb4 e2fsck 1.41.12 (17-May-2010) old_vol: clean, 11/122160 files, 8397/487974 blocks # mount /u02
For more information see: