In this lecture I’ll show you how to mount and unmount file systems in Linux. As you already know, on Linux, t 1
the structure of the file system is hierarchical, much like an upside down tree. 2
The root directory, which is forward slash, lies at the base of the file system and all other directories 3
are spreading from there. 4
This is the root directory. 5
If you want to access a file system that's on another partition or disk, you need to mount it or logically 6
attach it to an existing directory of the unique file system. That directorate is called Mount Point. 7
To mount or to attach a file system in the directory tree, use the mount command. 8
If you run it without any argument, it will display all currently attached file systems. 9
The output is really large because it includes virtual file systems such as sysfs, tmpf, proc 10
so on. 11
We are not interested in the virtual filesystems for the moment. This is for example the partition 12
that is mounted on the root directory. To display only certain filesystem types use -t option. 13
For example, I want to see only ext4 files systems. 14
This is the default filesystem type for most modern Linux distributions, so mount -l -t 15
ext4 16
l comes from list t from type; and it has displayed only partitions of type ext4 17
Or only fat32 partitions called vfat on Linux 18
Let's mount a new filesystem in a given location, or a mount point. I'm going to insert a USB stick! 19
Note that in order to access USB disks in virtual box, you have to install virtual box extension pack. 20
I've already shown you how to do that in the installation section at the beginning of the course. 21
I'm inserting the disk. 22
It was inserted and Windows has mounted automatically. 23
To access it in Ubuntu, which runs in virtual box, in the running VM, go to devices 24
and select the USB stick. 25
This is the disk. 26
OK, if you run Linux as the main operating system, you don't have to do that. 27
By the way, on Ubuntu, when you insert a stick, it will be automatically mounted in /media, the 28
user name of the user who's logged in, and another directory with the name of the USB stick. 29
I'm running mount again. 30
This is the USB stick mounted on media. 31
Media, the username, the name of the stick, and this is its contents. 32
Sometimes it's not mounted automatically, like in the case of a disk partition, or you want to mount 33
it in another place or with other options. In Linux, a storage device is logically represented as a 34
special char device file in /dev. 35
In this example, it's sdb. 36
This is the name of the file. 37
This is a char device file that represents the USB stick. To find the name of the device file you run 38
as root fdisk -l 39
This is the file. 40
You can also run the dmesg command to find the name of the device file: look, it's sdb and lsblk is 41
another alternative that will list all block devices. 42
Having the name of the device file we can mount it in any directory that already exists. 43
I'm creating a new director on the desktop mkdir /home/student /Desktop and USB. 44
It was created on the desktop. 45
This is the directory and I'm running the mount command. 46
Note that only root can mount partitions using the mount command so sudo mount the name of the device 47
file/dev /sdb 48
and the mount point, the directory where it will attached; so home/ student /Desktop /USB. 49
And it was mounted! We can access its contents in that directory. 50
This is its contents. 51
Note that you can mount the same physical device in different places; in this example, the USB stick 52
is mounted on both /media and on the desktop. 53
It's mounted on two different directories. 54
The mount command will auto-detect the filesystem type. However, some filesystems are not automatically 55
recognized and the need to be explicitly specified. Use the -t option to specify the filesystem 56
type, like this. 57
-t and its type vfat, this is fat32. 58
Of course, it says that's already mounted. 59
When you want to unmount a disc or a partition, run the umount command and the mount point. 60
umount 61
and the mount point. Don't forget the run it as root. 62
Note that the command is umount and the not unmount and you only give the mount point directory 63
as argument; and you are allowed to unmount partitions only if they are not used; so close any open files 64
or directories on that partition. 65
Alternatively, you could try a lazy unmount using the -l or --- lazy option. 66
It will unmount a busy file system as soon as it's not busy anymore. 67
-l 68
It's not mounted. 69
I've already unmounted. If you want to specify other additional options, use the -o option. Let's 70
mounted read-only so sudo mount -o ro 71
/dev/sdb and the mount point. 72
I cannot mount it read-only on the desktop because it's already mounted read write is /media. 73
So first I'll unmount the partition from /media. 74
And now I'll mounted read-only. 75
Great! It worked. mount-l-t vfat 76
Ro means that it was mounted read-only; you can only read the partition, you cannot modify it. If you 77
realized that by mistake you have mounted it read only you can remount it with other options like this. 78
-o rw it means rad write ,remount 79
It was remounted rad write 80
Let's see how to punt an iso file. 81
Many downloadable operating systems, including Windows and various Linux distributions, are 82
distributed as ISO images. To mount such an image start by creating the mount point at any location you 83
want; for example mkdir ~/iso Then mount the image using the mount command and 84
the - o loop option, like this. 85
sudo mount path_to_iso_file 86
the mount point and -o loop. This is how you mount an ISO file. 87
At the end, I want to give you some tips about disk partitioning. You can always use the disk command, 88
which is the standard utility used to manage disks and partitions. 89
However, at least for beginners, this is not the easiest task. You can get in lots of troubles and the 90
risk of losing data is huge. 91
My advice is to make a backup of the most important files before working with disks and partitions. 92
And if you run a graphical interface, use a program called gparted instead. Gparted is a free partition 93
editor graphically managing your disk partitions. First install gparted using sudo apt 94
install gparted 95
Once it was installed, simply started as root. 96
sudo gparted 97
This is the application. 98
This is the graphical interface of gparted, and after selecting the disk, you can perform many actions 99
with partitions such as create or delete, resize or move partitions.