Sobes.tech
Junior

How to mount a disk in an operating system?

sobes.tech AI

Answer from AI

Disks in operating systems are mounted by linking the storage device to a specific point in the file system hierarchy.

On Linux/Unix-like systems, this is done using the mount command.

Steps:

  1. Identify the disk:

    # View all block devices
    lsblk
    
    # Or use dmesg for recent connection messages
    dmesg | grep 'sd[a-z]'
    
  2. Create a mount point:

    # Create a directory where the disk will be mounted
    sudo mkdir /mnt/mydisk
    
  3. Mount the disk:

    # Mount the partition (/dev/sdb1) to the created mount point (/mnt/mydisk)
    sudo mount /dev/sdb1 /mnt/mydisk
    
    # If the filesystem is specified explicitly (e.g., ext4)
    sudo mount -t ext4 /dev/sdb1 /mnt/mydisk
    
  4. Check:

    # Check mounted filesystems
    df -h
    
    # Or
    mount | grep /mnt/mydisk
    
  5. Automatic mounting at boot: Edit the /etc/fstab file:

    # Device  Mount point  Filesystem type  Options      Dump  Pass
    /dev/sdb1     /mnt/mydisk         ext4    defaults   0     0
    

    It is better to use the device's UUID for reliability:

    # Get the device's UUID
    blkid /dev/sdb1
    
    # Example fstab entry using UUID
    UUID=<your_disk_uuid> /mnt/mydisk ext4 defaults 0 0
    

    After editing /etc/fstab, you can check the syntax and try to remount everything:

    sudo mount -a
    

On Windows, mounting occurs automatically when a new disk is connected and assigned a drive letter. Disk management is done through "Disk Management".

  1. Open "Disk Management": Press Win+R, type diskmgmt.msc, and press Enter.
  2. Identify the disk: Find the disk in the list. An unallocated disk will be marked as "Unallocated".
  3. Initialize (if necessary): Right-click the disk -> "Initialize Disk". Choose partition style (MBR or GPT).
  4. Create a partition and format: Right-click on the "Unallocated" space -> "New Simple Volume". Follow the wizard: specify volume size, assign a drive letter or mount in an empty folder (similar to Linux), choose filesystem (NTFS, FAT32).
  5. Check: The disk will appear in "File Explorer" under the assigned letter or in the mounted folder.

Mounting in a folder on Windows:

  1. Create an empty folder (e.g., C:\MountPoint).
  2. In "Disk Management", when assigning a drive letter or later (right-click the created volume -> "Change Drive Letter and Paths..."), select "Add" -> "Mount in the empty NTFS folder:". Specify the path to the created folder.

The method choice (drive letter or folder) depends on the usage scenario. Mounting in a folder is convenient for structuring large data volumes or if drive letters are insufficient.