Commands for Mounting Disks in Linux

fdisk -l                       # View available disks to mount, or use lsblk command

df -h                          # View already mounted disks

mkfs.ext4 /dev/sdb1            # Format the disk: format is ext4, note that this will `format the mountable disk`

mount /dev/sdb1 /data0         # Mount the disk to `/data0`, ensure `/data0` is empty

blkid                          # Get the disk's UUID and attributes, use UUID for boot-time mount

vim /etc/fstab                 # Boot-time mount, template: UUID=********** /data0  ext4  defaults  1 1

Backup

# Always back up before any operation
cp /etc/fstab /etc/fstab_backup

List Disks

fdisk

fdisk -l
Disk /dev/sda: 480.1 GB, 480103981056 bytes, 937703088 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x00057260

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    17803263     8388608   82  Linux swap / Solaris
/dev/sda3        17803264   937701375   459949056   83  Linux

Disk /dev/sdb: 600.1 GB, 600127266816 bytes, 1172123568 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xa6abba72

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048  1172119551   586058752    7  HPFS/NTFS/exFAT

Disk /dev/sdc: 300.0 GB, 300000000000 bytes, 585937500 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xb34e161e

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048   585934847   292966400    7  HPFS/NTFS/exFAT

lsblk

lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 447.1G  0 disk
├─sda1   8:1    0   500M  0 part /boot
├─sda2   8:2    0     8G  0 part [SWAP]
└─sda3   8:3    0 438.7G  0 part /
sdb      8:16   0 558.9G  0 disk
└─sdb1   8:17   0 558.9G  0 part
sdc      8:32   0 279.4G  0 disk
└─sdc1   8:33   0 279.4G  0 part

Disk Partitioning (New Disk)

# Follow the prompts
fdisk /dev/sdb

Mounted Disks

df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs         12G     0   12G   0% /dev
tmpfs            12G     0   12G   0% /dev/shm
tmpfs            12G  1.2G   11G  10% /run
tmpfs            12G     0   12G   0% /sys/fs/cgroup
/dev/sda3       439G  305G  134G  70% /
/dev/sda1       494M  166M  329M  34% /boot
tmpfs           2.4G     0  2.4G   0% /run/user/0

<span>/dev/sdb</span> is not mounted

Temporary Mount

mount /dev/sdb1 /data0

Find Disk UUID

# All disk UUIDs
blkid
/dev/sda1: UUID="d3ab3f39-3d7b-4242-b68e-b38fb4b29176" TYPE="xfs"
/dev/sda2: UUID="b072dffc-d2fd-4834-b0b7-d8b88b042f08" TYPE="swap"
/dev/sda3: UUID="64f9460d-b609-42a3-b5f1-8c3c4482500f" TYPE="xfs"
/dev/sdb1: LABEL="M-fM-^VM-0M-eM-^JM- M-eM-^MM-7" UUID="18DAF517DAF4F1BC" TYPE="ntfs"
/dev/sdc1: LABEL="M-fM-^VM-0M-eM-^JM- M-eM-^MM-7" UUID="CAACA88EACA8769B" TYPE="ntfs"
blkid | grep sdb1 | awk '{if(match($0, /UUID="([^"]+)"/, a)) {print a[0]} }'
UUID="18DAF517DAF4F1BC"
# Directly get UUID
blkid -s UUID -o value /dev/sda2

Boot-Time Mount

vim /etc/fstab

UUID=64f9460d-b609-42a3-b5f1-8c3c4482500f /                       xfs     defaults        0 0
UUID=d3ab3f39-3d7b-4242-b68e-b38fb4b29176 /boot                   xfs     defaults        0 0
UUID=b072dffc-d2fd-4834-b0b7-d8b88b042f08 swap                    swap    defaults        0 0
# New
UUID=18DAF517DAF4F1BC                     /data0                  ntfs    defaults        0 0

The meanings are as follows:

Field Meaning
Device File Generally the path + device name,<span>write the unique identifier (UUID, Universally Unique Identifier)</span>
Mount Directory Specify the directory to mount to, must be created before mounting
Format Type Specify the file system format, such as Ext3, Ext4, XFS, SWAP, iso9660 (for CD-ROM devices), etc.
Permission Options If set to defaults, the default permissions are: rw, suid, dev, exec, auto, nouser, async
Backup If 1, the disk will be backed up using dump after boot, if 0, no backup
Self-Check If 1, the disk will be automatically checked after boot, if 0, no self-check

Writing UUID is to prevent: issues with disk mounting misalignment after adding or removing disks.

Persistent Block Device Naming

Another way to mount

ls -l /dev/disk/by-id
lrwxrwxrwx 1 root root  9 May  7 18:33 ata-HGST_HUS728T8TALE6L4_VGKR5DJG -> ../../sdb
lrwxrwxrwx 1 root root  9 May 10 00:53 ata-HGST_HUS728T8TALE6L4_VGKR5GTG -> ../../sda
lrwxrwxrwx 1 root root 10 May 10 00:53 ata-HGST_HUS728T8TALE6L4_VGKR5GTG-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 May 10 00:53 ata-HGST_HUS728T8TALE6L4_VGKR5GTG-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 May 10 00:53 ata-HGST_HUS728T8TALE6L4_VGKR5GTG-part3 -> ../../sda3

MinIO

Deploy MinIO: Multi-Node Multi-Drive[1]

MinIO requires using expansion notation {x…y} to denote a sequential series of drives when creating the new deployment, where all nodes in the deployment have an identical set of mounted drives. MinIO also requires that <span>the ordering of physical drives remain constant across restarts</span>, such that a given mount point always points to the same formatted drive. MinIO therefore strongly recommends using /etc/fstab or a similar file-based mount configuration to ensure that <span>drive ordering cannot change after a reboot</span>. For example:

$ mkfs.xfs /dev/sdb -L DISK1
$ mkfs.xfs /dev/sdc -L DISK2
$ mkfs.xfs /dev/sdd -L DISK3
$ mkfs.xfs /dev/sde -L DISK4

$ nano /etc/fstab

  # <file system>  <mount point>  <type>  <options>         <dump>  <pass>
  LABEL=DISK1      /mnt/disk1     xfs     defaults,noatime  0       2
  LABEL=DISK2      /mnt/disk2     xfs     defaults,noatime  0       2
  LABEL=DISK3      /mnt/disk3     xfs     defaults,noatime  0       2
  LABEL=DISK4      /mnt/disk4     xfs     defaults,noatime  0       2

References

  • Chapter 6: Storage Structures and Disk Partitioning.[2]
Hardware Device File Name
IDE Device /dev/hd[a-d]
SCSI/SATA/USB Drive /dev/sd[a-z]
virtio Device /dev/vd[a-z]
Floppy Drive /dev/fd[0-1]
Printer /dev/lp[0-15]
CD-ROM Drive /dev/cdrom
Mouse /dev/mouse
Tape Drive /dev/st0 or /dev/ht0
  • archlinux Fstab[3]
  • archlinux Fdisk[4]
  • archlinux Persistent Block Device Naming[5]
  • archlinux Udev[6]
  • archlinux LVM[7]

References

[1]

Deploy MinIO: Multi-Node Multi-Drive: https://min.io/docs/minio/linux/operations/install-deploy-manage/deploy-minio-multi-node-multi-drive.html

[2]

Chapter 6: Storage Structures and Disk Partitioning: https://www.linuxprobe.com/chapter-06.html

[3]

archlinux Fstab: https://wiki.archlinux.org/title/Fstab

[4]

archlinux Fdisk: https://wiki.archlinux.org/title/Fdisk

[5]

archlinux Persistent Block Device Naming: https://wiki.archlinux.org/title/Persistent_block_device_naming

[6]

archlinux Udev: https://wiki.archlinux.org/title/Udev

[7]

archlinux LVM: https://wiki.archlinux.org/title/LVM

Leave a Comment