One tree, many filesystems
Linux doesn't give each disk its own drive letter. Instead every filesystem is attached onto a directory somewhere in the single tree that starts at /. That directory is the filesystem's mount point, and attaching it is mounting. By convention, temporary disks are mounted under /mnt.
Attach the disk, make an empty directory for it, and mount it there. Afterwards df -h and findmnt show it in place:
sudo losetup -fP --show disk.img
sudo mkdir -p /mnt/data
sudo mount /dev/loop0 /mnt/data
df -h /mnt/data
findmnt /mnt/dataIn the terminal
student@vulntech:~$ sudo losetup -fP --show disk.img [sudo] password for student: /dev/loop0 student@vulntech:~$ sudo mkdir -p /mnt/data student@vulntech:~$ sudo mount /dev/loop0 /mnt/data student@vulntech:~$ df -h /mnt/data Filesystem Size Used Avail Use% Mounted on /dev/loop0 55M 14K 51M 1% /mnt/data student@vulntech:~$ findmnt /mnt/data TARGET SOURCE FSTYPE OPTIONS /mnt/data /dev/loop0 ext4 rw,relatime
Use it like any other folder
Once mounted, the disk is just a directory. Files you create under the mount point are stored on the disk, not on the root filesystem:
echo "hello from my disk" | sudo tee /mnt/data/notes.txt
cat /mnt/data/notes.txt
ls -l /mnt/dataIn the terminal
student@vulntech:~$ echo "hello from my disk" | sudo tee /mnt/data/notes.txt [sudo] password for student: hello from my disk student@vulntech:~$ cat /mnt/data/notes.txt hello from my disk student@vulntech:~$ ls -l /mnt/data total 13 drwx------ 2 root root 12288 Oct 18 05:08 lost+found -rw-r--r-- 1 root root 19 Oct 18 05:09 notes.txt
Unmounting: umount
When you're finished, umount (note: no ‘n’) detaches the filesystem. Always unmount before unplugging a real disk, so everything still in memory is written out first:
sudo umount /mnt/data
findmnt /mnt/data
lsblk /dev/loop0In the terminal (after umount, /mnt/data is an empty directory again)
student@vulntech:~$ sudo umount /mnt/data [sudo] password for student: student@vulntech:~$ findmnt /mnt/data student@vulntech:~$ lsblk /dev/loop0 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS loop0 7:0 0 64M 0 loop
Common mistake:
umount: target is busymeans something is still using the disk — often your own shell sitting inside it.cdout of the mount point first, then unmount.sudo fuser -m /mnt/datashows what's holding it.
Tip:
mountwith no arguments, orfindmnt, lists everything currently mounted.mount -o loop FILE DIRis a shortcut that attaches a loop device and mounts it in one step.
Remember: A filesystem must be mounted onto a directory to be used:
sudo mount DEVICE DIR.df -handfindmntshow what's mounted;sudo umount DIRdetaches it safely.