Sobes.tech
Junior

How to properly mount a disk in an operating system?

sobes.tech AI

Answer from AI

  1. Identify the disk name and partition(s). Use the command lsblk or fdisk -l.

    lsblk
    # The output will show block devices and their structure
    
  2. Create a mount point (a directory where the disk will be mounted).

    sudo mkdir /mnt/mydisk  # Create directory /mnt/mydisk
    
  3. Format the disk/partition if it is not formatted or requires a different filesystem. For example, formatting to ext4:

    sudo mkfs.ext4 /dev/sdb1  # Format the first partition of disk /dev/sdb to ext4
    

    Important: Make sure to select the correct disk/partition before formatting, otherwise data loss may occur.

  4. Mount the disk/partition to the mount point.

    sudo mount /dev/sdb1 /mnt/mydisk  # Mount /dev/sdb1 to /mnt/mydisk
    
  5. Check if the disk is successfully mounted.

    df -h  # View information about mounted filesystems
    
  6. Configure automatic mounting at system startup by adding an entry to /etc/fstab. Obtain the UUID of the disk/partition for reliable mounting.

    sudo blkid /dev/sdb1  # Get UUID and TYPE of the filesystem
    # Example output: /dev/sdb1: UUID="your-uuid-here" TYPE="ext4" PARTUUID="..."
    

    Editing /etc/fstab:

    sudo nano /etc/fstab
    # Add a line in the format:
    # UUID="your-uuid-here" /mnt/mydisk ext4 defaults 0 2
    

    Fields in /etc/fstab:

    • UUID/Device: Disk/partition identifier or device path.
    • Mount point: Mount point.
    • File system type: Filesystem type (ext4, xfs, ntfs, etc.).
    • Options: Mount options (defaults, noauto, ro, rw, noexec, nosuid, etc.).
    • Dump: Dump utility flag (0 - do not archive).
    • Pass: Filesystem check order at boot (0 - do not check, 1 - root, 2 - others).
  7. Check the syntax of /etc/fstab and the ability to mount all entries.

    sudo mount -a  # Attempt to mount all from /etc/fstab
    

    If there are no errors, changes will apply at the next boot.