Search the Community
Showing results for tags 'mount'.
-
Mounting is a process of accessing files or folders through the local file system and making modifications. Windows Share is a Windows built-in feature to share files or directories with others over a local area network (LAN). In this tutorial, I will be exploring Windows Share and how to mount it on a Linux file system using the mount.cifs utility. What is CIFS CIFS also known as Common Internet File System is a dialect of SMB protocol that is developed by Microsoft to access files or folders from users over the same network connection. However, the latest SMB protocols have replaced this widely used network file-sharing protocol for mounting Windows Share on Linux. There is a specific utility called mount.cifs which is used to mount Windows Share on Linux. In the next section, I will discuss the process of installing it on Linux. How to Install CIFS-Utils on Linux To mount Windows Share on Linux mount.cifs utility is needed which is a part of the CIFS-Utils package. To install cifs-utils on Ubuntu, Debian, and distributions based on them, use the default package manager. sudo apt install cifs-utils Use the dnf package manager to install cifs-utils on CentOS and Fedora distributions, sudo dnf install cifs-utils For Red Hat (RHEL) and Red Hat-based distributions use the yum package manager. sudo yum install cifs-utils Note: For the instructions implemented in this guide, I am using Ubuntu 22.04. The process is similar and can be performed without any issue on any Linux distribution. How to Mount Windows Share on Linux We need a mount point, a directory created anywhere on the Linux system, to mount the Windows share. I am creating a /media/WinShare directory on root using mkdir command with sudo privileges. sudo mkdir /media/WinShare We will follow the below-given syntax of the mount command to mount the Windows Share on Linux. sudo mount -t cifs //[IP-ADDRESS]/[SHARE-NAME] /[MOUNT] -o username=[USERNAME] In the above syntax: [IP-ADDRESS]: It is the IP address of the remote machine, which is Windows in this case; to access the IP address, open the command prompt and run the ipconfig command. Note the IPV 4 address. [SHARE-NAME]: It is the Windows Share name or the folder name that is shared for the network. [MOUNT]: It is the mount point directory set up on the client’s machine, which is Linux. -o: This is a flag used to define cifs-utils options, to read more about the cifs utils options run man mount.cifs command. The table below lists some options that users often use. username To provide the username of the remote machine password To provide password explicitly [Not recommended] credentials To set the file containing credentials [Recommended] vers To set the protocol version explicitly 1.0, 2.0, or 3.0 Now, I have created a Windows Share with the name MyFolder, to mount it on Linux using /media/WinShare as a mount point I will use the following command. sudo mount -t cifs //192.168.18.14/MyFolder /media/WinShare -o username=shahr After executing the command you will be asked to enter the password of the remote machine. On successfully mounting the Windows Share, you will not get any alert. To verify the successful mount use the df -h command; which is essentially used to get disk space of the file system. df -h In many instances, it may be necessary to state the user domain. Find the system domain of the Windows system using the wmic (Windows Management Instrumentation Command Line) command in the command prompt. wmic computersystem get domain After knowing the domain which is WORKGROUP in my case, simply insert it in the above command using the domain option. sudo mount -t cifs //192.168.18.14/MyFolder /media/WinShare/ -o username=shahr,domain=WORKGROUP However, this is not a secure way to mount the shared folder. To make it more secure, the mount.cifs utility has an option called credentials. The credentials option allows you to set a path of a plain text file containing the credentials of the remote machine instead of explicitly mentioning the username or password. Let’s create a text file that contains the credentials of the machine to be accessed; in this case, it is the Windows machine. sudo nano ~/.credentials-cifs Type the following information in the file. username=[USERNAME] password=[PASSWORD] domain=[DOMAIN] After adding this information to the file, save the file by pressing ctrl+x and then y. To mount the Windows Share with credentials option use the following command. sudo mount -t cifs //192.168.18.14/MyFolder /media/WinShare/ -o credentials=~/.credentials-cifs Note: I will advise giving the absolute path to the credentials file instead of using ~/. How to Make the Windows Share Mount Permanent Before attempting the following section, note key important points. If the permanent mount is not properly set up, then Linux will not boot. Ensure everything is correct before reboot. I will suggest using the mount -a command to check for errors. The IP of the remote machine must be static, otherwise, the mounting will fail, and eventually the system boot. To make the Windows Share mount permanent, we need to modify the fstab (File System Table) file. The fstab file manages the file system and also allows you to mount the external file system manually. Let’s open the fstab file located in the /etc directory using the nano editor. sudo nano /etc/fstab To make Windows Share permanent on Linux, follow the syntax given below. //[IP-ADDRESS]/[SHARE-NAME] /[MOUNT] cifs credentials=[CREDENTIALS-FILE-PATH] [DUMP] [PASS] Note: Use tab instead of space to separate the fields in the fstab file. Let’s replace the [IP-ADDRESS], [SHARE-NAME], [MOUNT], and [CREDENTIALS-FILE-PATH] with actual information. The [DUMP] and the [PASS] options are used to enable backup of the mounted file system and fsck check on boot, respectively. Set 0 and 0 for both options to keep them disabled. //192.168.18.14/MyFolder /media/WinShare cifs credentials=/home/user/.credentials-cifs 0 0 Note: Provide the absolute path of the credentials file. After modifying the fstab file, save and exit the editor using ctrl+x and then y. The subsequent step involves mounting the Windows Share by means of the mount command. sudo mount /media/WinShare If there are no errors, then the mount is successful and will remain permanent even on boot. How to Unmount the Windows Share To unmount the Windows Share, use the umount command with the mount point. sudo umount /[MOUNT] In our example, the [MOUNT] is /media/WinShare directory. sudo umount /media/WinShare If the above command fails to unmount the Windows Share, then try force unmounting using the -f flag. sudo umount -f /media/WinShare Or use the -l flag, which detaches the file system if the above command also fails. sudo umount -l /media/WinShare To read more about these options, run the man mount command. How to Create Windows Share Windows Share is a directory that is set to share on a local area network. Before accessing Windows Share on Linux, it has to be set up on Windows. First, ensure that Windows is enabled for CIFS communication. For that, open the Turn Windows feature on and off on Windows. Find SMB 1.0/CIFS File Sharing Support in the list and check it. After a few moments, you will be asked to restart the system. To enable network discovery on Windows, navigate to the Advanced sharing settings; once there, you should find the option for Network discovery and ensure that this option is enabled by selecting the Turn on network discovery option. Next, we need to create a Windows Share folder that will be mounted on Linux using mount.cifs utility. Create a folder anywhere on Windows and right-click on it, and then from the context menu click on Properties. Navigate to the Sharing tab on the opened window and click on the Share button to proceed with the folder-sharing settings. Now, click on the drop-down icon, select Everyone from the list, and then click on the Add button. Select the Permission Level, set it to Read/Write to this folder, and then click on Share. Now, the Windows Share is ready to share. Conclusion If you have recently moved to Linux, then you will definitely need to access data on your Windows system. Any sort of data can be shared on Linux from Windows using the Windows Share option. To access Windows Share on Linux, the IP address and password of the Windows machine are required. Mounting the Windows Share on Linux using mount.cifs utility requires two steps. First, set the mount point on Linux and then use the mount command with the -t cifs option to mount the Windows Share on Linux. View the full article
-
In Linux, the file systems set the files in the form of a tree. This file system initiates from the root directory and all the child branches come out of this root directory. When we want to add a new child (file system) to this tree, the Linux mount command comes into practice. It allows us to attach a file to a specified mount point in the current file system. The command tells the kernel about the directory and the type of file system to mount and also the device name where the file system is present. This article demonstrates the use of the Linux mount command using several examples. Syntax: The syntax for using the mount command is as follows: mount -t [type] [dev] [directory] Here, mount is the keyword for the mount command. The “-t[type]” refers to the type of file system; it is an optional parameter. We need to provide the “dev” device on which the provided file system is mounted. Lastly, the destination directory name has to be mentioned at which the file system is mounted. Mount Options Different options can be indicated to mount a file system. Here is a list of some of these possibilities: -a It is employed to attach all of the file systems that are listed in etc/fstab. -l It is utilized to list all the file systems that are mounted and adds the labels. -h All the options for commands could be generated from it. -V It displays the version information. -t It tells the type of the file system. -T It is used to describe the substitutes etc/fstab file. -r It enables the read-only mounting of the file system. Utilizing the Linux Mount Command to Mount All the Files We can display the list of all the file systems that are currently mounted by simply writing the mount command on the terminal. Launch the terminal first. Additionally, type the subsequent command: omar@omar-VirtualBox:~$ mount Hit “enter” and you get the currently mounted file systems list: sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) udev on /dev type devtmpfs (rw,nosuid,relatime,size=1946576k,nr_inodes=486644,mode=755,inode64) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000) tmpfs on /run type tmpfs (rw,nosuid,nodev,noexec,relatime,size=401848k,mode=755,inode64) /dev/sda3 on / type ext4 (rw,relatime,errors=remount-ro) securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,inode64) tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k,inode64) cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot) pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime) bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700) systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=29,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=18327) tracefs on /sys/kernel/tracing type tracefs (rw,nosuid,nodev,noexec,relatime) debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime) hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M) mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime) configfs on /sys/kernel/config type configfs (rw,nosuid,nodev,noexec,relatime) fusectl on /sys/fs/fuse/connections type fusectl (rw,nosuid,nodev,noexec,relatime) none on /run/credentials/systemd-sysusers.service type ramfs (ro,nosuid,nodev,noexec,relatime,mode=700) /dev/sda2 on /boot/efi type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro) tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=401844k,nr_inodes=100461,mode=700,uid=1000,gid=1000,inode64) gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000) Also, using the “-l” mount option, you can obtain the list of the mounted file. omar@omar-VirtualBox:~$ sudo mount -l After entering the sudo password, it displays the file systems here: sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) udev on /dev type devtmpfs (rw,nosuid,relatime,size=1946576k,nr_inodes=486644,mode=755,inode64) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000) tmpfs on /run type tmpfs (rw,nosuid,nodev,noexec,relatime,size=401848k,mode=755,inode64) /dev/sda3 on / type ext4 (rw,relatime,errors=remount-ro) securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,inode64) tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k,inode64) cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot) pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime) bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700) systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=29,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=18327) tracefs on /sys/kernel/tracing type tracefs (rw,nosuid,nodev,noexec,relatime) debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime) hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M) mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime) configfs on /sys/kernel/config type configfs (rw,nosuid,nodev,noexec,relatime) fusectl on /sys/fs/fuse/connections type fusectl (rw,nosuid,nodev,noexec,relatime) none on /run/credentials/systemd-sysusers.service type ramfs (ro,nosuid,nodev,noexec,relatime,mode=700) /dev/sda2 on /boot/efi type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro) tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=401844k,nr_inodes=100461,mode=700,uid=1000,gid=1000,inode64) gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000) Checking the Mount Version The version of the mount can be obtained using the following command: omar@omar-VirtualBox:~$ sudo mount –V This shows us the version information of the mount. mount from util-linux 2.37.2 (libmount 2.37.2: selinux, smack, btrfs, verity, namespaces, assert, debug) Listing the Particular File System with the Mount Command Using the mount command, we can find out the mounts that are used by a particular file system. For instance, if we want to find the mounts that the “ext4” file system is using, we need to write the command in the proceeding syntax: omar@omar-VirtualBox:~$ -t <filesystem-type> To get the list of all the ext4 file systems, run this command: omar@omar-VirtualBox:~$ sudo mount -t ext4 /dev/sda3 on / type ext4 (rw,relatime,errors=remount-ro) Utilizing the /Etc/Fstab The /etc/fstab is used to find the mount location of the devices and has all the information about the system devices. It also tells us about the mount options that these system devices employ. To check if a particular file system is present in the /etc/fstab configuration file after reading its content, you need to provide one of the two parameters which are [device] or [directory] with the mount command. To find the structure of /etc/fstab, run this command: omar@omar-VirtualBox:~$ cat /etc/fstab Here, you will see the structure that it follows: # /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # <file system> <mount point> <type> <options> <dump> <pass> # / was on /dev/sda3 during installation UUID=3333d4f7-af61-4a62-9b78-46de26682e91 / ext4 errors=remount-ro 0 1 # /boot/efi was on /dev/sda2 during installation UUID=6DAB-1E13 /boot/efi vfat umask=0077 0 1 /swapfile none swap sw 0 0 From this, we understand that the file system that is currently mounted is —————-. The mounting point for it is the root “/”. Next, the type of the file system is mentioned as “ext4”. The mount option that is used here is “defaults,noatime”. Lastly, the value for “dump” is “0” and the value for “pass” is mentioned as “1”. If we want to mount a file system that is present in the /etc/fstab configuration file, you can either use the “mount [option] [directory]” command which tells you about the mounting point or “mount [option] [device]” which provides the mounting device. Mounting a USB We can mount a USB drive manually if the automated mounting fails to mount. To manually mount a USB, we first create a directory. Write the following mkdir command and make sure to write it with sudo privileges as we create a new directory which requires the admin rights. omar@omar-VirtualBox:~$ sudo mkdir /media/usb-drive [sudo] password for omar: Now, the mounting point for the USB drive is created. To locate the USB drive and the file system, we have to write the command on the terminal: omar@omar-VirtualBox:~$ sudo fdisk –l Here, we get the list of all the USB drives and files: Disk /dev/sda: 17.95 GiB, 19273465856 bytes, 37643488 sectors Disk model: VBOX HARDDISK Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: B1802B5F-BC14-4293-888D-BACCD438E53C Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 1054719 1050624 513M EFI System /dev/sda3 1054720 37642239 36587520 17.4G Linux filesystem Mount any specific USB drive through the device identifier from the output of the fdisk output. From the previous output, we have three drives. We choose the /dev/sda3. We write the command as follows: omar@omar-VirtualBox:~$ sudo mount /dev/sda /media/usb-drive If the drive is not already mounted, it will be mounted. mount: /media/usb-drive: /dev/sda already mounted or mount point busy. As shown in our output, it says that the USB drive is already mounted. Mounting the ISO Files and CD-ROM with the Mount Command The ISO (identical storage image of optical media) files as well as the CD-ROMs can also be mounted using the mount command in Linux. As for the CD-ROMs, they are removable devices. So, Linux attaches them automatically when removed after insertion. But if it does not mount the CD-ROMs, you can mount it yourself. First, we run a command to attach a CD-ROM. Then, we go for ISO files. To manually mount the CD-ROM, carry out the following command: omar@omar-VirtualBox:~$ sudo mount -t iso9660 -o ro /dev/cdrom /mnt Here, the iso9660 is the standardized file system for CD-ROMs. Whereas to mount an ISO file, the –o loop mount option is used because an ISO file must have its data mapped to a loop device before it can be mounted. Detaching a Mounted File System Using the umount command, we can unmount an attached file system. Detachment can be done by either providing the device identifier or the point of mount for that specific file system. For instance, to unmount a USB drive, the command is as follows: omar@omar-VirtualBox:~$ sudo umount /media/usb-drive Conclusion The Linux mount command is explained in detail in this guide. We demonstrated the syntax and the mount options for this command in the initial section of this article. With the utilization of these options, you can obtain the required output. Either all of the file systems that are currently mounted or a single specified system can be found with the mount command options. The use of the mount command with different examples to mount a file system, USB drive, or ISO file is explained with practical implementation in Linux Mint 21. View the full article
-
Forum Statistics
63.6k
Total Topics61.7k
Total Posts