Advertisement
v1ral_ITS

how to mount iso on folder [ linux ]

Oct 5th, 2019
713
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.12 KB | None | 0 0
  1.  
  2. On Linux and UNIX operating systems, you can use the mount command to attach (mount) file systems and removable devices such as USB flash drives at a particular mount point in the directory tree.
  3.  
  4. The umount command detaches (unmounts) the mounted file system from the directory tree.
  5.  
  6. In this tutorial, we will go over the basics of attaching and detaching various file systems using the mount and umount commands.
  7. How to List Mounted File Systems
  8.  
  9. When used without any argument, the mount command will display all currently attached file systems:
  10.  
  11. mount
  12.  
  13. Copy
  14.  
  15. By default, the output will include all file systems including the virtual ones such as cgroup, sysfs, and others. Each line contains information about the device name, the directory to which the device is mounted to, the type of the filesystem and the mount options in the following form:
  16.  
  17. device_name on directory type filesystem_type (options)
  18.  
  19.  
  20. To display only certain file systems use the -t option.
  21.  
  22. For example, to print only the ext4 partitions you would use:
  23.  
  24. mount -t ext4
  25.  
  26. Mounting a File System
  27.  
  28. To mount a file system in a given location (mount point), use the mount command in the following form:
  29.  
  30. mount [OPTION...] DEVICE_NAME DIRECTORY
  31.  
  32.  
  33. Once the file system is attached, the mount point becomes the root directory of the mounted file system.
  34.  
  35. For example, to mount the /dev/sdb1 file system to the /mnt/media directory you would use:
  36.  
  37. sudo mount /dev/sdb1 /mnt/media
  38.  
  39.  
  40. Usually when mounting a device with a common file system such as ext4 or xfs the mount command will auto-detect the file system type. However, some file systems are not recognized and need to be explicitly specified.
  41.  
  42. Use the -t option to specify the file system type:
  43.  
  44. mount -t TYPE DEVICE_NAME DIRECTORY
  45.  
  46.  
  47. To specify additional mount options, use the -o option:
  48.  
  49. mount -o OPTIONS DEVICE_NAME DIRECTORY
  50.  
  51.  
  52. Multiple options can be provided as a comma-separated list (do not insert a space after a comma).
  53.  
  54. You can get a list of all mount options by typing man mount in your terminal.
  55. Mounting a File System using /etc/fstab
  56.  
  57. When providing just one parameter (either directory or device) to the mount command, it will read the content of the /etc/fstab configuration file to check whether the specified file system is listed or not.
  58.  
  59. If the /etc/fstab contains information about the given file system, the mount command uses the value for the other parameter and the mount options specified in the fstab file.
  60.  
  61. The /etc/fstab file contains a list of entries in the following form:
  62.  
  63. [File System] [Mount Point] [File System Type] [Options] [Dump] [Pass]
  64.  
  65.  
  66. Use the mount command in one of the following forms to attach a file system specified in the /etc/fstab file:
  67.  
  68. mount [OPTION...] DIRECTORY
  69. mount [OPTION...] DEVICE_NAME
  70.  
  71. Mounting USB Drive
  72.  
  73. On most modern Linux distribution like Ubuntu, USB drives will auto mount when you insert it, but sometimes you may need to manually mount the drive.
  74.  
  75. To manually mount a USB device, perform the following steps:
  76.  
  77.     Create the mount point:
  78.  
  79.     sudo mkdir -p /media/usb
  80.  
  81.  
  82.     Assuming that the USB drive uses the /dev/sdd1 device you can mount it to /media/usb directory by typing:
  83.  
  84.     sudo mount /dev/sdd1 /media/usb
  85.  
  86.     To find the device and filesystem type you can use any of the following commands:
  87.  
  88.     fdisk -lls -l /dev/disk/by-id/usb*dmesglsblk
  89.  
  90.  
  91. To mount exFAT formatted USB drives you’ll need to install the free FUSE exFAT module and tools.
  92. Mounting ISO Files
  93.  
  94. You can mount an ISO file using the loop device which is a special pseudo-device that makes a file accessible as a block device.
  95.  
  96.     Start by creating the mount point, it can be any location you want:
  97.  
  98.     sudo mkdir /media/iso
  99.  
  100.  
  101.     Mount the ISO file to the mount point by typing the following command:
  102.  
  103.     sudo mount /path/to/image.iso /media/iso -o loop
  104.  
  105.  
  106.     Don’t forget to replace /path/to/image.iso with the path to your ISO file.
  107.  
  108. Mounting NFS
  109.  
  110. To mount an NFS share you’ll need to have the NFS client package installed on your system.
  111.  
  112.     Install NFS client on Ubuntu and Debian:
  113.  
  114.     sudo apt install nfs-common
  115.  
  116.  
  117.     Install NFS client on CentOS and Fedora:
  118.  
  119.     sudo yum install nfs-utils
  120.  
  121.  
  122. Use the steps below to mount a remote NFS directory on your system:
  123.  
  124.     Create a directory to serve as the mount point for the remote filesystem:
  125.  
  126.     sudo mkdir /media/nfs
  127.  
  128.  
  129.     Generally, you will want to mount the remote NFS share automatically at boot. To do so open the /etc/fstab file with your text editor:
  130.  
  131.     sudo nano /etc/fstab
  132.  
  133.  
  134.     Add the following line to the file, replacing remote.server:/dir with the NFS server IP address or hostname and the exported directory:
  135.     /etc/fstab
  136.  
  137.     # <file system>    <dir>       <type>   <options>   <dump>  <pass>
  138.     remote.server:/dir /media/nfs  nfs      defaults    0       0
  139.  
  140.  
  141.     Mount the NFS share by running the following command:
  142.  
  143.     sudo mount /media/nfs
  144.  
  145.  
  146. Unmounting a File System
  147.  
  148. To detach a mounted file system, use the umount command followed by either the directory where it has been mounted (mount point) or the device name:
  149.  
  150. umount DIRECTORYumount DEVICE_NAME
  151.  
  152. If the file system is in use the umount command will fail to detach the file system. In those situations, you can use the fuser command to find out which processes are accessing the file system:
  153.  
  154. fuser -m DIRECTORY
  155.  
  156. Once you determine the processes you can stop them and unmount the file system.
  157. Lazy unmount
  158.  
  159. Use the -l (--lazy) option to unmount a busy file system as soon as it is not busy anymore.
  160.  
  161. umount -l DIRECTORY
  162.  
  163. Force unmount
  164.  
  165. Use the -f (--force) option to force an unmount. This option is usually used to unmount an unreachable NFS system.
  166.  
  167. umount -f DIRECTORY
  168.  
  169.  
  170. Generally not a good idea to force unmount as it may corrupt the data on the file system.
  171. Conclusion
  172.  
  173. By now you should have a good understanding of how to use the mount command to attach various file systems to your directory tree and detaching the mounts with the umount command.
  174.  
  175. To learn more about the mount and umount command options see their respective man pages.
  176. mount
  177. umount
  178. terminal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement