cheat-sheets

Mount

In Linux, mount attaches a filesystem on a device to a directory. Before a user can access a file on a Unix-like machine, the filesystem on the device which contains the file needs to be mounted. It is used for disks, SD cards, USB storage, ISO images and network shares (NFS).


List mount-points #

findmnt (optional)<device/directory>

Unmount #

umount <device/directory>

Find Devices #

COMMANDDESCRIPTION
lsblk -fDevices, filesystems, UUIDs and mount points
sudo blkidUUID and type of each device
df -hTMounted filesystems with usage
findmnt --realReal (non-virtual) mounts as a tree

Mount #

COMMANDDESCRIPTION
sudo mount /dev/sdb1 /mnt/dataMount a partition
sudo mount -o ro /dev/sdb1 /mnt/dataMount read-only
sudo mount -o remount,rw /mnt/dataChange options of a live mount
sudo mount -o loop image.iso /mnt/isoMount an ISO image
sudo mount --bind /src /dstBind-mount a directory elsewhere
sudo mount -t nfs <SERVER>:/export /mnt/nfsNFS share
sudo mount -t cifs //<SERVER>/share /mnt/smb -o username=<USER>,uid=1000SMB/CIFS share
sudo umount -l /mnt/dataLazy unmount a busy mount
sudo umount -f /mnt/nfsForce unmount an unreachable NFS share
lsof +f -- /mnt/data / fuser -vm /mnt/dataWhat is keeping a mount busy

Make It Permanent (/etc/fstab) #

Use UUIDs, not /dev/sdX names, which can change.

UUID=1234-ABCD  /mnt/data  ext4  defaults,nofail  0  2
<SERVER>:/export  /mnt/nfs  nfs  defaults,_netdev,nofail  0  0
//<SERVER>/share  /mnt/smb  cifs  credentials=/root/.smbcreds,uid=1000,_netdev,nofail  0  0
FIELDMEANING
1Device, UUID=, or remote path
2Mount point
3Filesystem type
4Options (nofail avoids a boot hang if absent, _netdev waits for the network)
5dump flag (0)
6fsck order (1 for root, 2 for others, 0 to skip)

Test before rebooting: sudo mount -a and findmnt --verify. After editing, sudo systemctl daemon-reload.

Format a New Disk #

bash
sudo parted /dev/sdb --script mklabel gpt mkpart primary ext4 0% 100%
sudo mkfs.ext4 /dev/sdb1
Search all sheets

Tip: / or Ctrl/Cmd+K to open, Esc to close.