Related Series Links:
1.Partition Party
2.Filesystem & mounting (this article)
3.LVM Land
This is a continuation of my Partition Party post. You may want to start there if you'd like to follow along.
A few more steps are necessary before the disk is fully operational. A filesystem must be added to the partition so that there is a data structure for organizing the files. Then it must be mounted to a directory within the file system hierarchy.
For brevity, I will mount just one of the partitions from the sdc drive. Let's review what we're working with.
[sorad@dev9 ~]$ lsblk /dev/sdc
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sdc 8:32 0 10G 0 disk
├─sdc1 8:33 0 2G 0 part
├─sdc2 8:34 0 2G 0 part
├─sdc3 8:35 0 2G 0 part
├─sdc4 8:36 0 1K 0 part
├─sdc5 8:37 0 2G 0 part
└─sdc6 8:38 0 2G 0 part
To create the filesystem you use the mkfs command to specify the type of filesystem followed by the path to the partition. In this example it will be XFS. Information regarding the new file structure is printed after creation.
[sorad@dev9 ~]$ sudo mkfs.xfs /dev/sdc1
[sudo] password for sorad:
meta-data=/dev/sdc1 isize=512 agcount=4, agsize=131072 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=1 inobtcount=1 nrext64=0
data = bsize=4096 blocks=524288, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=16384, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
To see our new creation we can use blkid or lsblk -f. I prefer the latter as it also gives additional info and is more readable. Let's use both actually. I'll also specify the sdc1 partition so we don't get the full list of all drives on the system.
[sorad@dev9 ~]$ sudo blkid /dev/sdc1
/dev/sdc1: UUID="81bff549-814e-407f-ab1f-396cb95a7f09" TYPE="xfs" PARTUUID="5ace204b-01"
[sorad@dev9 ~]$ lsblk -f /dev/sdc1
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
sdc1 xfs 81bff549-814e-407f-ab1f-396cb95a7f09
On to the mount step. First, create the directory that will be the mount point for the drive. Then mount the drive using the (you guessed it) mount command.
[sorad@dev9 ~]$ sudo mkdir /mountsdc
[sorad@dev9 ~]$ sudo mount /dev/sdc1 /mountsdc
To check the partition has been mounted we can use the df command. lsblk -f could be used also, as it includes the same info. The -hT options specify to print sizes in human readable format and to show the Type of filesystem.
[sorad@dev9 ~]$ df -hT /dev/sdc1
Filesystem Type Size Used Avail Use% Mounted on
/dev/sdc1 xfs 2.0G 47M 1.9G 3% /mountsdc
To test if sdc1 is now fully operational, I will use fallocate. This command is handy for whipping up a "fake" file, particularly of a large size. I will not go into further detail in this article, but you will see in the command that the file is 500MB in size. Running df again will show the available storage has dropped from 1.9G to 1.5G. Finally, I'll show the fake file in the mount point directory.
[sorad@dev9 ~]$ sudo fallocate -l 500M /mountsdc/large_test_file
[sorad@dev9 ~]$ df -hT /dev/sdc1
Filesystem Type Size Used Avail Use% Mounted on
/dev/sdc1 xfs 2.0G 547M 1.5G 28% /mountsdc
[sorad@dev9 ~]$ ll /mountsdc
total 512000
-rw-r--r--. 1 root root 524288000 May 14 13:26 large_test_file
I bet you thought we were finished. Not quite. The /etc/fstab file must be edited if the drive needs to be mounted automatically when the system starts. The following info needs to be provided in order:
- path to the partition
- mount point
- type of file system
- defaults 0 0 (Just add this for now - this will most often be used)
Time to open everyone's favorite editor, vi! I've left out most of the file contents except for the newly added drive. The numbering above the data does NOT go in the file. It is only there to correlate to the checklist above.
[sorad@dev9 ~]$ sudo vi /etc/fstab
[sudo] password for sorad:
# /etc/fstab
# Created by anaconda on Tue Jan 14 19:45:24 2025
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
1. 2. 3. 4.
/dev/sdc1 /mountsdc xfs defaults 0 0
The /etc/fstab file is quite particular as far as syntax goes. Additional characters, such as the numbering I included, can 'break' the file and cause your system to not boot properly. We can error check this file by running mount -a which forces the system to remount all filesystems in fstab. If you can run this command without any errors, you should be good to go.
A final note. You can unmount a drive using umount. Notice it is not unmount. Easy to mix up!
I welcome any questions, comments, or concerns. Thank you for reading.