📂 Commands: mount and umount (Attaching & Detaching File Systems)
In Linux, storage devices (partitions, USB drives, or network shares) are not automatically accessible just by plugging them in. They must be "attached" to a specific directory in your existing file system tree. This process is called mounting.
1. The "Why"
For an Arch Linux user managing a dual-boot system with Windows and Linux, these commands are your primary tools for disk management:
- Accessing Data: Mount your Windows NTFS partition .
- System Repair: If your rEFInd bootloader breaks, you use a Live USB to
mountyour internal partitions and fix the configuration. - External Storage: Manually mount a USB drive to backup your files.
- Security:
umount(unmount) ensures all data is safely written to the disk before you physically pull out a USB drive, preventing data corruption.
2. The Mounting Process
To mount a device, you need two things:
- The Device Path: (e.g.,
/dev/sdb1), which you find usinglsblk. - The Mount Point: An empty directory where the files will appear (e.g.,
/mntor a folder you create).
3. Basic Syntax
A. Mounting a Partition
sudo mount /dev/sdb1 /mnt
Now, the contents of /dev/sdb1 are visible inside the /mnt directory.
B. Unmounting a Partition
sudo umount /mnt
Note: The command is umount (no "n" after the "u"). You can unmount using either the mount point or the device path.
4. Practical Examples for Your Workflow
A. Mounting your Windows Partition (Read-Only)
If you want to view files from Windows without accidentally deleting them:
sudo mount -t ntfs -o ro /dev/sda2 /mnt/windows
-t ntfs: Specifies the file system type.-o ro: Mounts as "Read-Only."
B. Troubleshooting the "Target is Busy" Error
If umount fails because a program is still using a file in that folder:
- Use
lsof /mntto find the process ID. - Close the program or kill the process.
- Try
umountagain.
C. Mounting the EFI Partition (Boot Repair)
If you need to fix your rEFInd or GRUB settings:
sudo mount /dev/nvme0n1p1 /boot/efi
5. mount -a and /etc/fstab
When you want a partition (like a secondary HDD for your Ahmed Codes projects) to mount automatically every time you boot:
- You add an entry to the
/etc/fstabfile. - To test if your
fstabentry is correct without rebooting, run:sudo mount -aThis tells the system to mount everything listed in the configuration file.
6. Pro-Tips
- The "Vanish" Trick: If you mount a device to a folder that already has files in it, those files will "disappear" until you unmount the device. They aren't gone; they are just covered by the new mount.
- Arch Linux Context: On Arch, many users prefer the
udisks2service (used by file managers like Thunar or Dolphin) to handle mounting automatically. However, knowing the manualmountcommand is vital for "TTY-only" situations or recovery mode. - Remounting: If you need to change a mount from Read-Only to Read-Write without unmounting:
sudo mount -o remount,rw /mnt
7. Summary Reference
| Goal | Command |
|---|---|
| Mount device | sudo mount [device] [dir] |
| Unmount device | sudo umount [dir] |
| See all mounted drives | `mount |
| List types/UUIDs | lsblk -f |