Bird
Raised Fist0
Linux CLIscripting~10 mins

mount and umount in Linux CLI - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - mount and umount
Start
↓
mount command
↓
Check device and mount point
↓
Mount device to mount point
↓
Device accessible at mount point
↓
umount command
↓
Unmount device
↓
Mount point freed
↓
End
The flow shows mounting a device to a folder to access it, then unmounting to free the folder.
Execution Sample
Linux CLI
sudo mount /dev/sdb1 /mnt/usb
ls /mnt/usb
sudo umount /mnt/usb
Mounts a USB device, lists its contents, then unmounts it.
Execution Table
StepCommandActionResultOutput
1sudo mount /dev/sdb1 /mnt/usbMount device /dev/sdb1 to /mnt/usbSuccess if device and folder exist
2ls /mnt/usbList files in mounted device folderShows files/folders on USBfile1.txt file2.jpg folderA
3sudo umount /mnt/usbUnmount device from /mnt/usbMount point freed, device no longer accessible
💡 Unmount frees the mount point, device no longer accessible there
Variable Tracker
VariableStartAfter mountAfter lsAfter umount
/mnt/usb (mount point)empty foldermounted device accessiblefiles listedempty folder
Key Moments - 3 Insights
Why do we need to use 'sudo' with mount and umount?
Mounting and unmounting devices require admin rights to access hardware and system folders, as shown in execution_table steps 1 and 3.
What happens if you try to list files before mounting?
The folder would be empty or show local files, not the device contents. Execution_table step 2 shows listing after mount to see device files.
Can you unmount using the device name instead of the mount point?
Yes, but it's safer to use the mount point path as in step 3 to avoid mistakes. Both ways work but mount point is clearer.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the output of 'ls /mnt/usb' after mounting?
ANo such file or directory
Bempty folder
Cfile1.txt file2.jpg folderA
DPermission denied
💡 Hint
Check the Output column in row 2 of the execution_table.
At which step does the mount point become accessible with device files?
AStep 3
BStep 1
CStep 2
DBefore Step 1
💡 Hint
Look at the Result column in step 1 of execution_table.
If you skip 'sudo' in the mount command, what likely happens?
APermission denied error
BMount succeeds anyway
CDevice unmounts automatically
DFiles list shows empty folder
💡 Hint
Refer to key_moments about needing admin rights for mount (step 1).
Concept Snapshot
mount device_path mount_point
- Attaches device to folder to access files
- Requires admin rights (sudo)
- umount mount_point
- Detaches device, frees folder
- Use ls on mount_point to see files
Full Transcript
This lesson shows how to use mount and umount commands in Linux. First, you use 'sudo mount /dev/sdb1 /mnt/usb' to attach the device to the folder /mnt/usb. Then, you can list files inside that folder with 'ls /mnt/usb'. Finally, you unmount the device with 'sudo umount /mnt/usb' to free the folder. Mounting needs admin rights, so sudo is required. After unmounting, the folder is empty again. This process lets you access external devices safely.

Practice

(1/5)
1. What does the mount command do in Linux?
easy
A. It formats a storage device for use.
B. It connects a device or filesystem to a directory so you can access its files.
C. It disconnects a device from the system safely.
D. It lists all files in a directory.

Solution

  1. Step 1: Understand the purpose of mount

    The mount command attaches a device or filesystem to a directory, making its files accessible.
  2. Step 2: Differentiate from umount and other commands

    Umount disconnects devices, formatting prepares devices, and listing files is done by ls, not mount.
  3. Final Answer:

    It connects a device or filesystem to a directory so you can access its files. -> Option B
  4. Quick Check:

    Mount = Connect device to directory [OK]
Hint: Mount = connect device to folder, umount = disconnect [OK]
Common Mistakes:
  • Confusing mount with umount
  • Thinking mount formats devices
  • Assuming mount lists files
2. Which of the following is the correct syntax to mount a device /dev/sdb1 to directory /mnt/usb?
easy
A. mount -u /dev/sdb1 /mnt/usb
B. mount /mnt/usb /dev/sdb1
C. umount /dev/sdb1 /mnt/usb
D. mount /dev/sdb1 /mnt/usb

Solution

  1. Step 1: Recall mount command syntax

    The correct syntax is mount [device] [mount_point], so device first, then directory.
  2. Step 2: Check options for correctness

    mount /dev/sdb1 /mnt/usb matches the syntax: mount /dev/sdb1 /mnt/usb. Others reverse order or use wrong command.
  3. Final Answer:

    mount /dev/sdb1 /mnt/usb -> Option D
  4. Quick Check:

    mount device directory = correct syntax [OK]
Hint: Device first, then directory in mount command [OK]
Common Mistakes:
  • Swapping device and directory order
  • Using umount instead of mount
  • Adding wrong options like -u
3. What will be the output of the command sequence below if /dev/sdb1 is already mounted on /mnt/usb?
mount /dev/sdb1 /mnt/usb
mount | grep /mnt/usb
medium
A. /dev/sdb1 on /mnt/usb type ext4 (rw,relatime)
B. mount: /mnt/usb is busy
C. mount: /dev/sdb1 is already mounted
D. No output

Solution

  1. Step 1: Understand mounting an already mounted device

    Running mount on an already mounted device usually remounts or shows no error, depending on system, but the second command lists mounts.
  2. Step 2: Analyze the grep output

    The command mount | grep /mnt/usb shows the current mount info for that directory, typically like /dev/sdb1 on /mnt/usb type ext4 (rw,relatime).
  3. Final Answer:

    /dev/sdb1 on /mnt/usb type ext4 (rw,relatime) -> Option A
  4. Quick Check:

    mount | grep shows mount info [OK]
Hint: mount | grep shows current mounts [OK]
Common Mistakes:
  • Expecting error when mounting already mounted device
  • Confusing mount error messages
  • Ignoring output of grep command
4. You try to unmount a device with umount /mnt/usb but get the error: umount: /mnt/usb: target is busy. What is the best way to fix this?
medium
A. Close any open files or terminals using /mnt/usb, then try umount again.
B. Force unmount with umount -f /mnt/usb immediately.
C. Reboot the system to clear the busy state.
D. Delete the /mnt/usb directory and try umount again.

Solution

  1. Step 1: Understand 'target is busy' error

    This error means some process is using files or directories inside /mnt/usb, blocking unmount.
  2. Step 2: Proper fix is to close those processes

    Close open files, terminals, or programs accessing /mnt/usb, then run umount again safely.
  3. Final Answer:

    Close any open files or terminals using /mnt/usb, then try umount again. -> Option A
  4. Quick Check:

    Busy means in-use; close files before umount [OK]
Hint: Close files using mount point before umount [OK]
Common Mistakes:
  • Forcing unmount without checking usage
  • Deleting mount directory instead of unmounting
  • Rebooting unnecessarily
5. You want to write a script that mounts a USB device /dev/sdb1 to /mnt/usb, copies a file data.txt to it, then safely unmounts it. Which sequence of commands is correct?
hard
A. umount /mnt/usb && mount /dev/sdb1 /mnt/usb && cp data.txt /mnt/usb/
B. cp data.txt /mnt/usb/ && mount /dev/sdb1 /mnt/usb && umount /mnt/usb
C. mount /dev/sdb1 /mnt/usb && cp data.txt /mnt/usb/ && umount /mnt/usb
D. mount /mnt/usb /dev/sdb1 && cp data.txt /mnt/usb/ && umount /mnt/usb

Solution

  1. Step 1: Mount device before copying files

    You must mount the device first to access its filesystem, so mount command comes first.
  2. Step 2: Copy file then unmount safely

    After copying, unmount to safely disconnect device. The sequence is mount, copy, then umount.
  3. Final Answer:

    mount /dev/sdb1 /mnt/usb && cp data.txt /mnt/usb/ && umount /mnt/usb -> Option C
  4. Quick Check:

    Mount -> copy -> umount sequence [OK]
Hint: Mount first, copy files, then unmount [OK]
Common Mistakes:
  • Copying files before mounting
  • Unmounting before copying
  • Swapping device and directory in mount
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard