Linux Administration Bootcamp
Installing and Connecting to a Linux System
Intermediate Linux Skills
Linux Boot Process and System Logging
Disk Management in Linux
LVM - The Logical Volume Manager
User Management in Linux
Networking With Linux
Shell Scripting with Linux
Command Line Kung Fu
In this course, you will learn how to install a Linux system and connect to it, whether that be on Mac or Windows.
In this lesson, you will learn how to create a file system as well as how to mount and unmount that file system. You'll also learn how to prepare swap space for use by your Linux system. Next you'll learn about the File System Table and how it controls where devices are mounted on a Linux system. Finally, you'll learn about disk UUIDs and Labels, and how you can use them in conjunction with the File System Table.
Before a partition can be used by a Linux system, it will need a file system. The extended file system or ext for short, was created specifically for Linux. It was soon replaced by ext the second extended file system. Since then ext3 and ext4 have been released. These series of file systems are the most commonly used file systems on Linux systems and are often found as the default file systems on Linux distributions. If you have special needs, you should research some of the other popular file systems available on Linux. These include ReiserFS, JFS, XFS, ZFS and Btrfs.
To create a file system, use the mkfs command. The format is mkfs -t TYPE DEVICE. The type will be a file system type such as ext3 or XFS. The device is the path to the partition on which you want the file system to reside. Here is how you would create an ext3 file system on the second partition of the sdb disk. You would run mkfs -t ext3 /dev/sdb2. To create an ext4 file system, just run mkfs -t ext4 /dev/sdb3. The mkfs utility is actually a front end for the various file system builders. Running mkfs -t ext4 dev sdb3 is actually the same as running mkfs.ext4/dev/sdb3.
If you want to see the options available for a specific file system consult the man page for the given command. For example, you can run man mkfs.xfs to find more information about creating XFS file systems. To mount a partition, use the mount command followed by the path to the device and then the directory where you want to mount that device. For example, to mount dev sdb3 on opt run mount /dev/sdb3 /opt. You can use the mount command without any arguments to see what is currently mounted but be aware that mount will not only show physical file systems but also virtual file systems. These virtual file systems are often RAM-based file systems that provide ways to interact with other parts of the system.
If you want a shorter list of mount points that contain storage devices use the df command. You can think of the df command as the disk free command, as it reports file system usage. Be aware that manually mounting a file system from the command line will not cause it to persist between reboots. In order to make the mount permanent, you will need to add an entry in the etc/fstab file. To unmount a partition use the umount command followed by either the device path or the mount point. To unmount opt you could run umount /opt or umount /dev/sdb3. Instead of creating a file system and mounting it with swamp you create a swap area and enable it.
To prepare the swap area for use, use the mkswap command followed by the path of the partition. To enable the swap partition use the swapon command followed by the path to the device. To see the swap devices in use run swapon -s. The /etc/fstab file controls where devices are mounted on a Linux system and what options to use when mounting those devices. Each entry consists of one line with six columns. If a line starts with a pound sign it's a comment and it's ignored. The six columns are the device, the mount point, the file system type, options, dump and file system check order. Each of these columns is separated by a space or a tab.
Here's an example fstab file. The device column contains a path to a device, a label for a device or a UUID also known as a universally unique identifier of a device. The mount point column determines where the device will be mounted. The third column contains the file system type. Use the same type here as you did when you created the file system with the mkfs command. The mount option column is used to specify which options to mount the file system with. The keyword defaults represents the default mount options for the file system type. Consult the man page for fstab, the mount command and the file system type you are using for a full list of options.
To specify multiple options, separate them with a comma. It's important to not use spaces before or after the commas. The dump column is used by the dump utility. If it contains a zero, dump will ignore this file system. If it contains a one, dump we'll back up this file system. You can safely ignore this column, if you do not use the dump utility to perform backups. Today dump is rarely used for backups. The final column is the fsck column. It is by the fsck program at boot time to determine if a file system is to be checked, and if so, in what order to check them.
Valid values are zero, one and two. If this column contains a zero, fsck we'll skip checking this file system. File systems with a value of one will be checked first and then file systems with a value of two will be checked next. For file systems that you want to have checked it's a best practice to set the slash file system to one with a remaining file system set to two.
Let's look at this example, fstab file. The first entry ensures that dev sda2 will get mounted on slash. Its false system type is XFS and it uses the default options. Since the dump column contains a zero, the dump utility will not back up this file system. The value in the fsck column is one, so this file system will get checked first during the boot up process. The second entry ensures that dev sda1 will be used as a swap device.
For swap devices, use the swap keyword as the mount point and the file system type. The dump and fsck columns are set to zero as swap space does not need to be backed up or checked. This fstab uses UUIDs and Labels in the device column. The device with the UUID that starts with dbae4 will be mounted on slash. The device with the label opt will be mounted on /opt and the dev sda1 device will be used as swap space.
To view labels in UUIDs, you can use the lsblk-f command. If you're only interested in the UUIDs, you can use the blkid command Each system type will have a utility that you can use to create or modify the label for the file system. For ext file systems you can use the e2 label command. Simply pass the path to the device as the first argument and the label as the second argument. Here's how to add the label opt to the dev sdb3 device. Run e2label /dev/sdb3 opt.
In this lesson, you learned how to create file systems with the mkfs command. You learned how to mount those file systems with a mount command. Once those file systems were mounted, you learned how to view the disc usage with the df command. Next you learn that you can use the umount command to unmount a file system. You learned how to prepare swap space using the mkswap command and how to enable it with swapon. You also learned about the fstab file and how you can mount a device by using its path. It's UUID or its Label. Finally, you learned how to display and create labels for devices.
QA: A world-leading tech and digital skills organisation
We help many of the world’s leading companies to build their tech and digital capabilities via our range of world class training courses, reskilling bootcamps, work-based learning programmes and Apprenticeships. We also create bespoke solutions, blending elements to meet specific client needs.