In the Linux ecosystem, mounting and unmounting disks are crucial operations that allow users to access and manage storage devices efficiently. This guide aims to provide a practical approach to understanding and executing these operations, enabling even beginners to handle their storage needs confidently.

Advertisement

Introduction

Mounting is the process of making a storage device accessible to the system by assigning it a specific directory (known as a mount point) in the directory tree. Unmounting, conversely, is the process of detaching the storage device, making it inaccessible to the system.

These operations are fundamental for managing external hard drives, USB drives, and even network storage within Linux, ensuring data integrity and efficient storage access.

How to Mount a Disk in Linux

Mounting can be achieved through the command line, which offers flexibility and power not found in graphical interfaces. Here’s a step-by-step guide:

  1. Identify the Disk: First, you need to identify the disk you want to mount. Use the lsblk command to list all block devices, including disks and partitions:
    lsblk
    
  2. Create a Mount Point: A mount point is simply a directory where the disk’s contents will be accessible. Create a new directory for your mount point if it doesn’t already exist:
    sudo mkdir /mnt/mydisk
    
  3. Mount the Disk: Now, use the mount command to mount the disk to the mount point you’ve created. Replace /dev/sdx1 with your disk’s identifier and /mnt/mydisk with your mount point:
    sudo mount /dev/sdx1 /mnt/mydisk
    

How to Unmount a Disk in Linux

Unmounting is simpler but equally important. Use the umount command followed by either the mount point or the device name:

sudo umount /mnt/mydisk

Or:

sudo umount /dev/sdx1

Ensuring Safe Unmounting

Sometimes, you might encounter an error stating the device is busy. This usually means a process is still using the mounted device. You can find out which process is causing the issue with the lsof or fuser command:

sudo lsof /mnt/mydisk

Terminate the process or ensure it’s not using the disk before attempting to unmount again.

Advanced Mounting Options

Linux’s mount utility comes with a plethora of options for advanced users. For instance, specifying the filesystem type with the -t option can be necessary for certain disks:

sudo mount -t ntfs /dev/sdx1 /mnt/mydisk

Additionally, options like ro for read-only access or rw for read-write access can be specified with the -o option:

sudo mount -o ro /dev/sdx1 /mnt/mydisk

Automating Mounts with /etc/fstab

For disks that need to be mounted at boot time, Linux provides the /etc/fstab file. Adding an entry here can automate the mounting process, ensuring your disks are always ready when the system starts.

Conclusion

Mounting and unmounting disks in Linux might seem daunting at first, but it’s a straightforward process once you understand the basics. By following this guide, you’re now equipped to manage your disks effectively, whether you’re running a home server, managing an enterprise network, or simply exploring Linux’s capabilities. Remember, with great power comes great responsibility—always ensure you’re mounting and unmounting safely to protect your data.

Share.

4 Comments

  1. I have a dedicated server provided to me by 1and1. I started migrating websites to the server only to realise that I am running out of disk space. I had to clear my backups in order to continue migrating my sites. I thought this to be weird as the server comes with 4T of disk space.

    On accessing the system via ssh. I see the following setup by 1and1:

    #vgdisplay

    — Volume group —
    VG Name vg00
    System ID
    Format lvm2
    Metadata Areas 1
    Metadata Sequence No 8
    VG Access read/write
    VG Status resizable
    MAX LV 0
    Cur LV 3
    Open LV 3
    Max PV 0
    Cur PV 1
    Act PV 1
    VG Size <54.00 GiB
    PE Size 4.00 MiB
    Total PE 13823
    Alloc PE / Size 11520 / 45.00 GiB
    Free PE / Size 2303 / <9.00 GiB
    VG UUID CmLv2a-xKAn-cFQQ-K4TU-f5y2-UK8K-Uv1PO9

    — Volume group —
    VG Name hdd
    System ID
    Format lvm2
    Metadata Areas 1
    Metadata Sequence No 2
    VG Access read/write
    VG Status resizable
    MAX LV 0
    Cur LV 1
    Open LV 1
    Max PV 0
    Cur PV 1
    Act PV 1
    VG Size <3.58 TiB
    PE Size 4.00 MiB
    Total PE 938308
    Alloc PE / Size 1024 / 4.00 GiB
    Free PE / Size 937284 / <3.58 TiB
    VG UUID Pv2xfH-zkE1-hgH0-dOzZ-FgKp-IobS-5C2zea

    Also #pvscan reveals this:
    PV /dev/sda3 VG vg00 lvm2 [<54.00 GiB / <9.00 GiB free]
    PV /dev/sdb1 VG hdd lvm2 [<3.58 TiB / <3.58 TiB free]

    Can someone please let me know the best process for getting this unused free space in to the root volume group? I have searched and seen so many different answers. As I have already started migrating a number of websites. I cannot afford to break the server, otherwise I would have a fiddle, break, and learn as I usually do.

    Just a thought failed to mention this is Hardware Raid 5

    Update to question below:

    #pvdisplay
    — Physical volume —
    PV Name /dev/sda3
    VG Name vg00
    PV Size <54.00 GiB / not usable 2.81 MiB
    Allocatable yes
    PE Size 4.00 MiB
    Total PE 13823
    Free PE 767
    Allocated PE 13056
    PV UUID 6J06IE-52et-s8aV-bXk0-alud-0N1v-NEwHHr

    — Physical volume —
    PV Name /dev/sdb1
    VG Name hdd
    PV Size <3.58 TiB / not usable <3.78 MiB
    Allocatable yes
    PE Size 4.00 MiB
    Total PE 938308
    Free PE 937284
    Allocated PE 1024
    PV UUID bGlBQQ-gnmF-gOav-VTfj-np5R-sAKs-YNxemq

    I would like to reduce the physical volume in /dev/sdb1 by 2 or 3TB and increase /dev/sda3 by the same amount. Can this be done? If so what process would I need to follow?

    If not I noticed mentioned in the replies "Migrating the websites to hdd" What process would I have to follow and what are the implications of doing this?

    Logical Volumes:

    — Logical volume —
    LV Path /dev/vg00/usr
    LV Name usr
    VG Name vg00
    LV UUID sRvgQ3-W80K-AJQD-lZid-fqF3-1KTY-JH2Ul0
    LV Write Access read/write
    LV Creation host, time ,
    LV Status available
    # open 1
    LV Size 15.00 GiB
    Current LE 3840
    Segments 2
    Allocation inherit
    Read ahead sectors auto
    – currently set to 8192
    Block device 253:0

    — Logical volume —
    LV Path /dev/vg00/var
    LV Name var
    VG Name vg00
    LV UUID xWSCRG-vBPH-JLha-yJ8X-3zMP-WgRG-AOoJqO
    LV Write Access read/write
    LV Creation host, time ,
    LV Status available
    # open 1
    LV Size 31.00 GiB
    Current LE 7936
    Segments 3
    Allocation inherit
    Read ahead sectors auto
    – currently set to 8192
    Block device 253:1

    — Logical volume —
    LV Path /dev/vg00/home
    LV Name home
    VG Name vg00
    LV UUID 2foQrE-Wy3C-Ig1Z-zIDy-tTFQ-YyO5-ayHBZl
    LV Write Access read/write
    LV Creation host, time ,
    LV Status available
    # open 1
    LV Size 5.00 GiB
    Current LE 1280
    Segments 1
    Allocation inherit
    Read ahead sectors auto
    – currently set to 8192
    Block device 253:2

    — Logical volume —
    LV Path /dev/hdd/data
    LV Name data
    VG Name hdd
    LV UUID GwJgTL-LC8r-jn0a-yQ5H-mTX3-dARL-Xz0eOU
    LV Write Access read/write
    LV Creation host, time ,
    LV Status available
    # open 1
    LV Size 4.00 GiB
    Current LE 1024
    Segments 1
    Allocation inherit
    Read ahead sectors auto
    – currently set to 8192
    Block device 253:3

    I increased the LV on /dev/vg00/var by 100% (This is where the websites are stored). but this will quickly be used up once I continue to migrate more sites over!

    This may also help. This is from running the mount command I have removed additional lines:

    /dev/sda1 on / type ext3 (rw,noatime,data=ordered)
    /dev/mapper/vg00-usr on /usr type ext4 (rw,noatime,data=ordered)
    /dev/mapper/hdd-data on /data type ext4 (rw,noatime,quota,usrquota,data=ordered)
    /dev/mapper/vg00-home on /home type ext4 (rw,noatime,quota,usrquota,data=ordered)
    /dev/mapper/vg00-var on /var type ext4 (rw,noatime,quota,usrquota,data=ordered)

    Thank you for your responses much appreciated!

    • which one of the following system that you cannot mount with the mount command ???
      a) iso9660 b)swap c)FAT d)root e)VFAT

Leave A Reply


Exit mobile version