- [Ubuntu] How to mount the external hard drive permanently
- Mount a File System on Linux
- Before You Begin
- File Systems Available for Linux
- How to List Currently Mounted File Systems on Linux
- How to Mount File Systems on Linux
- Mount a Windows Floppy Disk
- Mount a CD-ROM
- Mount a Disk Drive Permanently
- Mount a USB Drive
- Mount an ISO File
- Mount a Remote File System
- Unmounting File Systems
- Conclusion
- More Information
[Ubuntu] How to mount the external hard drive permanently
I will introduce this topic with a real example. The scenario is that I have two external NTFS hard drives. I want them to behave like the partition on Windows, like D drive, E drive something. However, every time when the Ubuntu is rebooted, those two hard drives are mounted to the path /media// and they are read-only.
I wrote a temporary solution for the above issue, but it stil requires to execute the command every time when PC boots. This post will give a one-go solution.
Before trying the solution, make sure that the hard drives are unmounted. The solution is
sudo mkdir /media/windows1 sudo mkdir /media/windows2 sudo vi /etc/fstab # Configure the mount record, see below sudo mount -a
There is a file /etc/fstab which is responsible for maintaining the mounting partition on Ubuntu. It looks like below.
# /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). # # # / was on /dev/nvme0n1p2 during installation UUID=34987fb7-46e7-4a74-a63e-ee73fb7e033d / ext4 errors=remount-ro 0 1 # /boot/efi was on /dev/nvme0n1p1 during installation UUID=2142-6826 /boot/efi vfat umask=0077 0 1 /swapfile none swap sw 0 0
For solving this issue at once, we need to add the records of two hard drives including UUID, mount point and other information.
Take the NTFS hard drive as an example, we can simply add the below line at the end of the file for each hard drive:
/dev/hda2 /media/windows ntfs-3g defaults,locale=en_US.utf8 0 0
The first parameter /dev/hda2 is the /dev location, but it also can be UUID, or LABEL. You can simply find the UUID and LABEL of the hard drive with sudo blkid . And it will show the output like below:
/dev/hda1: LABEL="InternalStorage" UUID="F9F4FD4FD4FE101C" TYPE="ntfs" PARTUUID="c53b3b2a-01"
So, the record can be like
UUID=F9F4FD4FD4FE101C /media/windows ntfs-3g defaults,locale=en_US.utf8 0 0 # or LABEL=InternalStorage /media/windows ntfs-3g defaults,locale=en_US.utf8 0 0
The second parameter /media/windows is the mount point. In my case, I have to create two directories under /media . Let’s say
mkdir /media/windows1 mkdir /media/windows2
For the other parameters, we can leave it as it is. It is totally fine. Or you can dive /etc/fstab configuration deeper into Ubuntu Fstab explanation
At the end, my fstab configuration might look like
/dev/hda1 /media/windows1 ntfs-3g defaults,locale=en_US.utf8 0 0 /dev/hdb2 /media/windows2 ntfs-3g defaults,locale=en_US.utf8 0 0
To make the changes effect immediately, we can run sudo mount -a
Mount a File System on Linux
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
Mounting or unmounting a file system on Linux is usually straightforward, except when it isn’t. This article teaches you how to mount and unmount file systems, as well as list available and currently mounted file systems. It also explains how to handle the case where file systems won’t unmount because they are in use.
Before You Begin
- If you have not already done so, create a Linode account and Compute Instance. See our Getting Started with Linode and Creating a Compute Instance guides.
- Follow our Setting Up and Securing a Compute Instance guide to update your system. You may also wish to set the timezone, configure your hostname, create a limited user account, and harden SSH access.
The steps in this guide require root privileges. Be sure to run the steps below as root or with the sudo prefix. For more information on privileges, see our Users and Groups guide.
File Systems Available for Linux
- On a Linux system, you can list the currently available file system types from the command line with:
nodev sysfs nodev tmpfs nodev bdev nodev proc nodev cgroup nodev cgroup2 nodev cpuset nodev devtmpfs nodev configfs nodev debugfs nodev tracefs nodev securityfs nodev sockfs nodev bpf nodev pipefs nodev ramfs nodev hugetlbfs nodev devpts ext3 ext2 ext4 squashfs vfat nodev ecryptfs fuseblk nodev fuse nodev fusectl nodev mqueue nodev pstore nambtrfs nodev autofs
FILESYSTEMS(5) Linux Programmer's Manual FILESYSTEMS(5) NAME filesystems - Linux filesystem types: ext, ext2, ext3, ext4, hpfs, iso9660, JFS, minix, msdos, ncpfs nfs, ntfs, proc, Reiserfs, smb, sysv, umsdos, vfat, XFS, xiafs DESCRIPTION When, as is customary, the proc filesystem is mounted on /proc, you can find in the file /proc/filesystems which filesystems…
How to List Currently Mounted File Systems on Linux
- You can list the currently mounted file systems from a Linux command line with a simple mount command:
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=441300k,nr_inodes=110325,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=99448k,mode=755,inode64) /dev/sda 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=18031) hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M) mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime) debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime) tracefs on /sys/kernel/tracing type tracefs (rw,nosuid,nodev,noexec,relatime) fusectl on /sys/fs/fuse/connections type fusectl (rw,nosuid,nodev,noexec,relatime) configfs on /sys/kernel/config type configfs (rw,nosuid,nodev,noexec,relatime) none on /run/credentials/systemd-sysusers.service type ramfs (ro,nosuid,nodev,noexec,relatime,mode=700) tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=99444k,nr_inodes=24861,mode=700,inode64)
# /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). # # /dev/sda / ext4 errors=remount-ro 0 1 /dev/sdb none swap sw 0 0
TARGET SOURCE FSTYPE OPTIONS / /dev/sda ext4 rw,relatime,errors=remount-ro ├─/sys sysfs sysfs rw,nosuid,nodev,noexec,relatime │ ├─/sys/kernel/security securityfs securityfs rw,nosuid,nodev,noexec,relatime │ ├─/sys/fs/cgroup cgroup2 cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot │ ├─/sys/fs/pstore pstore pstore rw,nosuid,nodev,noexec,relatime │ ├─/sys/fs/bpf bpf bpf rw,nosuid,nodev,noexec,relatime,mode=700 │ ├─/sys/kernel/debug debugfs debugfs rw,nosuid,nodev,noexec,relatime │ ├─/sys/kernel/tracing tracefs tracefs rw,nosuid,nodev,noexec,relatime │ ├─/sys/fs/fuse/connections fusectl fusectl rw,nosuid,nodev,noexec,relatime │ └─/sys/kernel/config configfs configfs rw,nosuid,nodev,noexec,relatime ├─/proc proc proc rw,nosuid,nodev,noexec,relatime │ └─/proc/sys/fs/binfmt_misc systemd-1 autofs rw,relatime,fd=29,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=18031 ├─/dev udev devtmpfs rw,nosuid,relatime,size=441300k,nr_inodes=110325,mode=755,inode64 │ ├─/dev/pts devpts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 │ ├─/dev/shm tmpfs tmpfs rw,nosuid,nodev,inode64 │ ├─/dev/hugepages hugetlbfs hugetlbfs rw,relatime,pagesize=2M │ └─/dev/mqueue mqueue mqueue rw,nosuid,nodev,noexec,relatime └─/run tmpfs tmpfs rw,nosuid,nodev,noexec,relatime,size=99448k,mode=755,inode64 ├─/run/lock tmpfs tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k,inode64 ├─/run/credentials/systemd-sysusers.service │ none ramfs ro,nosuid,nodev,noexec,relatime,mode=700 └─/run/user/0 tmpfs tmpfs rw,nosuid,nodev,relatime,size=99444k,nr_inodes=24861,mode=700,inode64
TARGET SOURCE FSTYPE OPTIONS / /dev/sda ext4 rw,relatime,errors=remount-ro
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sda 8:0 0 24.5G 0 disk / sdb 8:16 0 512M 0 disk [SWAP]
How to Mount File Systems on Linux
You can mount file systems for a single session using the mount command, and permanently by editing /etc/fstab. Mounting needs to be done by an administrator, either by logging in as root or by using the sudo command. There are some cases where mounting is done automatically, like when you insert a USB flash drive. Here are a few examples using the mount command, plus the preparatory mkdir command to create the mount point.
Mount a Windows Floppy Disk
- This command is only necessary if the /mnt/floppy directory doesn’t already exist:
mount -t msdos /dev/fd0 /mnt/floppy
Mount a CD-ROM
mount -t iso9660 /dev/cdrom /mnt/cdrom
Mount a Disk Drive Permanently
/dev/sdc /mnt/disk-drive ext4 defaults 0 0
. /dev/sdc on /mnt/disk-drive type ext4 (rw,relatime) .
Mount a USB Drive
Most modern distros automatically mount USB drives when you insert them.
- If that doesn’t happen, create a mount point if it doesn’t already exist:
If the USB drive uses the exFAT file system, you may need to install the FUSE exFAT module and tools.
Mount an ISO File
- The example below assumes that the ISO file is in the /root directory and that you are logged in as root:
mount ~/my_image.iso /media/iso -o loop
Mount a Remote File System
The network file system (NFS) supports mounting remote file systems as shares for local access.
- If you don’t already have an NFS client, you need to install it: Ubuntu or Debian:
123.45.67.8:/my_share /media/nfs nfs defaults 0 0
Instead of using NFS to mount a remote file system, you can instead use SSHFS. It’s not as stable as NFS, but has fewer dependencies. SSHFS is part of FUSE, and is available for most Linux distros, macOS, and Windows.
Unmounting File Systems
- You can unmount a file system using the umount command. Either the device name or the mount point is sufficient to specify what you wish to unmount:
umount /media/nfs umount /media/iso umount /media/usb umount /dev/cdrom umount /dev/fd0
You can add the -l (lazy) switch to umount to instruct the system to unmount the device when it’s free. Alternatively, the -f (force) switch makes the system unmount the device right away, at the possible risk of corrupting the file system. The -f switch is primarily intended to unmount unreachable NFS shares.
Conclusion
Mounting a file system on Linux is generally a straightforward two-step process: create a mount point directory, and use the mount command to mount the device at the mount point. Unless the file system is in use, unmounting is even simpler, requiring only the umount command. File system mounting and unmounting requires you to be logged in as root, or use the sudo prefix to temporarily take on root privileges.
More Information
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
This page was originally published on Thursday, September 15, 2022.