Sobes.tech
Junior

How to mount a disk in the operating system?

sobes.tech AI

Answer from AI

  1. Disk Identification: Use the lsblk or fdisk -l command to determine the device name (e.g., /dev/sdb1).

  2. Creating a Mount Point: Create a directory where the disk will be mounted:

    # mkdir /mnt/mydrive 
    // Create a directory named mydrive in the /mnt directory
    
  3. Mounting the Disk: Use the mount command:

    # mount /dev/sdb1 /mnt/mydrive 
    // Mount the /dev/sdb1 partition to the created mount point
    

    Optionally, specify the filesystem type with the -t option.

  4. Checking the Mount: Use the df -h command to verify if the disk has been successfully mounted.

  5. Automatic Mounting at Boot (Optional): Edit the /etc/fstab file, adding a line in the format:

    # <file>       <mount point>   <type>  <options>  <dump>  <pass>
    # /dev/sdb1    /mnt/mydrive    ext4   defaults 0       2
    
    • <file>: Device name or UUID. Use blkid for UUID.
    • <mount point>: Directory where the disk will be mounted.
    • <type>: Filesystem type (e.g., ext4, xfs).
    • <options>: Mount options (e.g., defaults, ro).
    • <dump>: Dump utility option (usually 0).
    • <pass>: Filesystem check order at boot (usually 0 or 2).
  6. Unmounting the Disk: Use the umount command:

    # umount /mnt/mydrive 
    // Unmount the disk from the specified mount point
    

    or

    # umount /dev/sdb1
    // Unmount the specified device
    

    If the disk is busy, the -l option for lazy unmount may be required.