Simple mounting question I can't seem to find the answer to.

Hi all,

I frequently mount an external hard drive using 'sudo mount /dev/...' and occasionally it (the drive) gets physically disconnected for whatever reason. Ok, so let's say it was mounted using /dev/sda1 for example. lsblk now says, upon reconnecting the device, that is in /dev/sdb1. How can I free up /dev/sda1 again without having to restart the computer?

Posted Apr 16, 2015, 9:32 PM UTC

36
c_biscuit•

u/shortbaldman is almost right, but you don't want to be using the mount command with a UUID, at least I don't.

What you do want is to add it into /etc/fstab. You still have to get the UUID ( use blkid )

$ sudo blkid

/dev/sda1: UUID="d528cd34-79f9-4fd1-87e0-b2522476c1ab" TYPE="ext4" 

/dev/sda5: UUID="11118601-1e0a-429a-ae0d-ef1dd98272e6" TYPE="swap" 

/dev/sda6: UUID="0ca0dfca-8a20-4341-8fb4-153f373b8195" TYPE="ext4"

Now, create a line is fstab that looks something like this ( using my example above )

UUID="0ca0dfca-8a20-4341-8fb4-153f373b8195"  /home/username/terabyte  ext4  user,noauto  0 0

What we are saying is for the device with this UUID, it mounts to /home/username/terabyte, users are allowed to mount it, do not try to mount at boot or when a mount -a is issued, the filetype is ext4 ( in this example ), and the last two numbers indicate whether it should be dumped ( no ) and whether fsck will try to check it at boot ( no )

Now, in order to mount it, all you have to do is plug it in and type mount ~/terabyte.

This goes a little off of exactly what you were asking, but u/NicroHobak already answered your exact question. I think this is a cleaner way to do it.

3
oopsleonOP•

Great, thank you for the suggestions. The result of all the help is my problem is now fixed and I've learned some new stuff about mounting. I'm satisfied.

1
usernamedottxt•

Umount can be used on a file path.

umount -l /media/myexternal for example.

2
oopsleonOP•

The file I always use is ~/terabyte. Currently, my HD is mounted to this in the form 'mount /dev/sdb1 ~/terabyte', so I don't want to unmount that. It was previously mounted in the same folder using /dev/sda1, and it's 'ghost' still appears to be using /dev/sda1.

edit: I tried your suggestion anyway after properly unmounting the HD, so that only sda1 was taken up. Upon entering your command, reinserting the HD, and typing 'lsblk', the HD is now even further shifted down into /dev/sdc1. Perhaps I am misunderstanding your suggestion, but it appears to have made the issue worse.

2
NicroHobak•

When a drive is mounted, it essentially gets assigned a directory location in the file system. When you have something mounted, then you have a physical disconnect without a clean umount command, the system will leave a lingering, stale mount in its place. In order to "free" up that directory location again, you have to inform the operating system that it's no longer in use...and you can do this by telling the system about the mounted directory location, you don't have to use the drive's device file (/dev/sd[a-z][0-9]).

You can do this with u/usernamedottxt's suggestion -- umount with the '-l' switch for a "lazy" unmount (lazy in this case just tells the OS to free the mount right now, but do the actual clean-up later when possible). If you omit the '-l' switch, the umount command will take a long time as the OS waits on the physical drive to respond (which probably won't happen...so it will take a while then report a timeout error). The man page for mount/umount has more info.

3
shortbaldman•

If you want an external drive to always mount easily, you're better off using the device's UUID instead of the /dev/sdx nomenclature

Get the UUID with the 'blkid' command, then use the UUID discovered in the 'mount' commandline.

 sudo mount UUID=de89db4a-1a7e-45ae-9322-ce81c816d7d2 /mount_point
1