USB Drive

Mounting external USB drive in the Linux terminal

Mounting external USB drive in the Linux terminal

Temporarily mount and unmount

Find the name of the block device to be mounted:

lsblk

Mount the block device. Assuming that you would like to mount /dev/sda1:

udisksctl mount --block-device /dev/sda1

You will be prompted your password, and the drive will be mounted to /media/user/drive assuming that user is the username of the current user, and drive is the name of the block device.

To unmount the block device:

udisksctl unmount --block-device /dev/sda1

Automatically mount as the current user at boot

Get the UUID of the block device:

sudo blkid

Create the mount directory. Assuming that you would like to mount to /media/user/drive:

sudo mkdir /media/user/drive

Change the owner to user. Assuming that the current user is user:

sudo chown user:user /media/user/usb/drive

Edit fstab:

sudo nano /etc/fstab

Add a new line at the end of the file. Assuming that the UUID is 12345678-90, and the filesystem is exfat:

PARTUUID=12345678-90 /media/user/drive exfat defaults,uid=user,gid=user,nofail 0 0

nofail tells the system to proceed with booting even if the specified filesystem fails to mount.

Save and exit, then test the configuration:

sudo mount -a

References

https://askubuntu.com/questions/37767/how-to-access-a-usb-flash-drive-from-the-terminal (https://askubuntu.com/a/37775)

ChatGPT

Content Licensed under CC BY-SA 4.0. Code licensed under the MIT License.
Last updated on Oct 15, 2024 07:14 UTC