Dec 26

On File Systems and Linux Commands (Redhat/CentOs/Fedora)

On File Systems and Linux Commands (Redhat/CentOs/Fedora)

echo "Dec 26th, 2017, Sayed Ahmed, Justetc Technologies"

On file Systems - Target Audience: Technical People. Software Developers and System/Network Administrators or DevOps  (or wanna be)

/ and /boot are the default Linux file systems

you can also configure /home, /opt, /var, /tmp, /usr as separate file systems or can make these as part of the / file systems.

/ and /boot are mandatory

The advantages of having separate file systems (and/or partitions) for different purpose (/var, /usr) are: you can independently manage them, extend them or reduce them as required. Can implement restriction on users who can access which file system. do repair and maintenance activities separatel

Types of file systems: ext2, ext3, ext4, xfs (default for Redhat 7), btrfs, vfat, iso9660, BIOS Boot, EFI System Partitions, NFS, AutoFS, CIFS (Common Internet File Systems)

AutoFS: NFS based auto mount. You can use this for LDAP Client configuration. Check our LDAP Notes.

xfs_repair : repair xfs file system devices

813 File System Administration Commands
814 dumpe2fs
815 dumpe2fs /dev/sdb
816 lsblk
817 dumpe2fs /dev/sdb
818 dumpe2fs /dev/sdc1
819 dumpe2fs /dev/sda

820 e2fsck /dev/sdb
821 e2fsck /dev/sda

823 lsblk
824 mkfs.ext2 /dev/sdb
825 mkfs.ext2 /dev/sdc1

826 e2fsck /dev/sdc1
827 e2fsck is for ext2 file system. ext2 will be removed soon. ext2 is deprecated on RHEL 7.
828 fsck.ext2 /dev/sdc1
829 fsck.xfs /dev/sda


830 xfs_repair /dev/sda
831 dumpe2fs, e2fsck, e2label, mke2fs, resize2fs, tune2fs, mkfs.xfs, xfs_admin, xfs_growfs, xfs_info, xfs_repair, mkfs.vfat, blkid, df, du, findmnt, fuser, mount, umout - some file system related linux commands


835 man e2label
836 e2label - Change the label on an ext2/ext3/ext4 filesystem
838 e2label device [ new-label ]
840 e2label will display or change the filesystem label on the ext2, ext3, or ext4 filesystem located on device.

841 man mke2fs
mke2fs is used to create an ext2, ext3, or ext4 filesystem, usually in a disk partition. device is the special file corresponding to the device (e.g /dev/hdXX). blocks-count is the number of blocks on the device. If omitted, mke2fs automagically figures the file system size. If called as mkfs.ext3 a journal is created as if the -j option was specified.

man resize2fs
The resize2fs program will resize ext2, ext3, or ext4 file systems. It can be used to enlarge or shrink an unmounted file system located
on device. If the filesystem is mounted, it can be used to expand the size of the mounted filesystem, assuming the kernel supports on-line
resizing. (As of this writing, the Linux 2.6 kernel supports on-line resize for filesystems mounted using ext3 and ext4.).

849 man tune2fs
tune2fs allows the system administrator to adjust various tunable filesystem parameters on Linux ext2, ext3, or ext4 filesystems. The cur‐rent values of these options can be displayed by using the -l option to tune2fs(8) program, or by using the dumpe2fs(8) program.

852 man mkfs.xfs
mkfs.xfs constructs an XFS filesystem by writing on a special file using the values found in the arguments of the command line. It is invoked automatically by mkfs(8) when it is given the -t xfs option.

855 man xfs_admin
xfs_admin uses the xfs_db(8) command to modify various parameters of a filesystem.
Devices that are mounted cannot be modified. Administrators must unmount filesystems before xfs_admin or xfs_db(8) can convert parameters.
A number of parameters of a mounted filesystem can be examined and modified using the xfs_growfs(8) command.

859 man xfs_growfs
xfs_growfs expands an existing XFS filesystem (see xfs(5)). The mount-point argument is the pathname of the directory where the filesystem is mounted. The filesystem must be mounted to be grown (see mount(8)). The existing contents of the filesystem are undisturbed, and the added space becomes available for additional file storage.

863 man xfs_info
xfs_info is equivalent to invoking xfs_growfs with the -n option (see discussion below).

865 man xfs_repair
xfs_repair repairs corrupt or damaged XFS filesystems (see xfs(5)). The filesystem is specified using the device argument which should be the device name of the disk partition or volume containing the filesystem. If given the name of a block device, xfs_repair will attempt to find the raw device associated with the specified block device and will use the raw device instead. Regardless, the filesystem to be repaired must be unmounted, otherwise, the resulting filesystem may be inconsistent or corrupt.

870 man mkfs.vfat
mkfs.fat is used to create an MS-DOS filesystem under Linux on a device (usually a disk partition). device is the special file correspond‐ing to the device (e.g /dev/hdXX). block-count is the number of blocks on the device. If omitted, mkfs.fat automatically determines the filesystem size.

874 man blkid
The blkid program is the command-line interface to working with the libblkid(3) library. It can determine the type of content (e.g. filesystem or swap) that a block device holds, and also the attributes (tokens, NAME=value pairs) from the content metadata (e.g. LABEL or UUID fields).

878 man df
df displays the amount of disk space available on the file system containing each file
name argument. If no file name is given, the space available on all currently mounted file systems is shown. Disk space is shown in 1K blocks by default, unless the environment variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used.

882 df
883 du

884 man du
du - Summarize disk usage of each FILE, recursively for directories.

886 man findmnt
findmnt will list all mounted filesytems or search for a filesystem. The findmnt command is able to search in /etc/fstab, /etc/mtab or /proc/self/mountinfo. If device or mountpoint is not given, all filesystems are shown.

889 findmnt

890 man fuser
fuser displays the PIDs of processes using the specified files or file systems. In the default display mode, each file name is followed by a letter denoting the type of access:
c current directory.
e executable being run.
f open file. f is omitted in default display mode.
F open file for writing. F is omitted in default display mode.
r root directory.
m mmap'ed file or shared library.

899 man mount
mount command - All files accessible in a Unix system are arranged in one big tree, the file hierarchy, rooted at /. These files can be spread out over several devices. The mount command serves to attach the filesystem found on some device to the big file tree. Conversely, the umount(8) command will detach it again.


903 man umount
umount - The umount command detaches the file system(s) mentioned from the file hierarchy.
You can customize mount operation by giving some parameters and options such as async: allow async I/O operation, acl: to support ACL (facl: getfacl, setfacl), users: allow all users to mount exec:noexec: permit/deny execution of binary files, ro:read only suid/nosuid: allow/disallow setuid operation user/nouser: allow/disallow a normal user to mount the file system remount: remount an already existing filesystem,

_netdev: network connectivity is a must before mounting, owner: allow the file system owner to mount dev/nodev: allow/disallow device files on the file system, defaults: accept all defaults (async, auto, dev, exec, nouser, rw, suid), auto: support auto mounting when -a option is used for mount command

note: mount -a will mount all filesystems mentioned in /etc/fstab
umount -a : everything mentioned in fstab will be unmounted. provided auto was there for the mount operation. auto is default parameter for mount command


blkid : gives you UUID for partitions/file systems. you can use UUID in /etc/fstab - usually is a good practice. because if you use /dev/sda /dev/sdb in the /etc/fstab - that might not work always because that can change depending on what storage device to add or remove to the system.
909 blkid
910 xfs_admin -u
911 xfs_admin -u /dev/sda
912 xfs_admin -u /dev/sda1
913 xfs_admin -u /dev/sdc1
914 xfs_admin -u device/partition : will also give UUID for that partition


915 blkid /dev/sdb
916 blkid /dev/sdc1
917 blkid
918 you can also create a label for a partition/file-system and use that in the /etc/fstab file
919 xfs_admin -l /dev/sdc1
920 xfs_admin -l /dev/sda
921 lsblk

926 lsblk
927 df -h
to create a label: xfs_admin -L testpartition /dev/sdc1
929 xfs_admin -L testpartition /dev/sdc1
930 then you can use testpartition in the /etc/fstab file

xfs_admin : -l shows label, -L creates label

932 cat /etc/fstab
933 the default format in the /etc/fstab file
934 /dev/mapper/cl-root / xfs defaults 0 0

device   mount-point file-system defaults/options-you-want(auto, rw, defaults, async) dump-or-not-for-dump-command scan-sequence-for-fsck

UUID and Label cab be used for the device/first parameter on /etc/fstab file

941 vim /etc/fstab

/dev/mapper/cl-root / xfs defaults 0 0

UUID=45213437-3dcf-4ee7-b6b7-26c37e2a82d7 /boot xfs defaults 0 0

/dev/mapper/cl-swap swap swap defaults 0 0

/dev/sdb1 /mnt ext2 defaults 0 0

947 df -h: disk free : check usage
948 df -h

partiton exercise
950 parted /dev/sdb mklabel msdos
951 parted /dev/sdb mkpart 1 101MB
952 parted /dev/sdb mkpart primary 1 101MB
953 parted /dev/sdb print
954 parted /dev/sdb mkpart primary 101 201MB
955 parted /dev/sdb print

956 mke2fs -t ext3 /dev/sdb2
957 mkfs.xfs /dev/sdb1

958 blkid
959 xfs_admin -L testlabel /dev/sdb1

960 vim /etc/fstab
961 mkdir -p /disks/sdb1

962 mount -a
963 vim /etc/fstab
964 mount -a
965 blkid
966 vim /etc/fstab
967 mount -a
968 umount -a
969 mount -a
970 cat /etc/fstab

971 example of using label on /etc/fstab
972 LABEL="testlabel" /disks/sdb1 xfs defaults 0 1

973 xfs_repair /dev/sdb1

974 umount /dev/sdb1
975 xfs_repair /dev/sdb1
976 xfs_repair : requires the file system to be unmounted


you can use nfs-utils to mount/unmount remote file systems
978 yum -y install nfs-utils
979 mkdir /disks/nfs-pc2

the format in the /etc/fstab file can be
981 /disks/nfs-pc2 nfs _netdev 0 0

check that I used: nfs as the file system
For options: I used _netdev because this is network devie and network connectivity is a must for this mounting operation

to mount cd-drive on redhat/centos/fedora
985 mount /dev/sr0 /mnt
df -h can show you the cdrom device. for me it was: /dev/sr0

987 df -h
you could use -t with mount command to give file system. However, for CD the default works fine
for NFS to mount using commands

mount -t nfs /mount-point-on-our-system-like-/disks/nfs/pc2-share

you can also mount samba file system as well

Skip to toolbar