Skip to content
abdallahmekky

CHEAT SHEET

Storage cheat sheet

Partitions, LVM, file systems, fstab, swap and NFS. The commands behind most RHCSA storage tasks.

All cheat sheets

Inspect

lsblk                        # tree of disks and partitionslsblk -f                     # with file systems and UUIDsblkid                        # UUIDs and typesdf -hT                       # mounted file systems and free spacedu -sh /var/*                # size of each itemfindmnt                      # mount treefdisk -l                     # partition tables

Partitions

fdisk /dev/vdb               # interactive: n new, p print, t type, w write, q quitparted /dev/vdb print        # show the partition tablepartprobe /dev/vdb           # tell the kernel about the changes

LVM: create

pvcreate /dev/vdb1                    # physical volumevgcreate vg0 /dev/vdb1                # volume grouplvcreate -n data -L 2G vg0            # logical volume of 2 GiBlvcreate -n logs -l 100%FREE vg0      # use all the free spacepvs  vgs  lvs                         # short statuspvdisplay  vgdisplay  lvdisplay       # detailed status

LVM: grow and remove

vgextend vg0 /dev/vdc1                    # add a disk to the grouplvextend -r -L +1G /dev/vg0/data          # grow by 1 GiB and the file system (-r)lvextend -r -l +100%FREE /dev/vg0/data    # use all the free spacexfs_growfs /data                          # grow XFS by handresize2fs /dev/vg0/data                   # grow ext4 by handumount /data                              # to remove: unmount firstlvremove /dev/vg0/data                    # then the volume,vgremove vg0                              # the group,pvremove /dev/vdb1                        # and the physical volume

XFS can grow but never shrink. ext4 can shrink, offline only.

File systems and mounting

mkfs.xfs /dev/vg0/data                # XFS, the RHEL defaultmkfs.ext4 /dev/vg0/data               # ext4mkdir -p /data                        # a mount pointmount /dev/vg0/data /data             # mount itumount /data                          # unmount it

/etc/fstab

# device       mount point  type  options   dump  fsckUUID=1234-abcd  /data        xfs   defaults  0     0
mount -a                      # test fstab now, not at bootsystemctl daemon-reload       # after editing fstab on a systemd system

Swap

mkswap /dev/vdb2              # prepare a partition as swapswapon /dev/vdb2              # enable itswapon --show                 # list active swapswapoff /dev/vdb2             # disable itdd if=/dev/zero of=/swapfile bs=1M count=1024    # or use a file: create it,chmod 600 /swapfile                              # lock it down,mkswap /swapfile                                 # prepare it,swapon /swapfile                                 # enable it
UUID=aaaa-bbbb  none  swap  defaults  0 0

NFS and autofs

showmount -e server                      # exports offered by a servermount -t nfs server:/share /mnt          # mount an NFS share
server:/share  /mnt  nfs  defaults  0 0
# /etc/auto.master.d/shares.autofs/shares  /etc/auto.shares# /etc/auto.sharesdata  -rw,sync  server:/share
dnf install -y autofssystemctl enable --now autofs

More cheat sheets

Questions

How do I extend an LVM volume and its file system?

Use lvextend -r -L +1G /dev/vg0/data. The -r flag also grows the file system, XFS or ext4, in one step.

Can XFS be shrunk?

No. XFS can only grow. To make it smaller you must back up, recreate a smaller file system and restore.

How do I test /etc/fstab without rebooting?

Run mount -a. Errors appear immediately instead of at boot. Run systemctl daemon-reload after editing the file.

How do I find the UUID of a device for fstab?

Run blkid /dev/vg0/data or lsblk -f. Use UUID=... in the first fstab column.