- How to mount usb drive in a linux system
- Step 1: Plug-in USB drive to your PC
- Step 2 – Detecting USB Drive
- Step 3 – Creating Mount Point
- Step 4 – Delete a Directory in USB
- Step 5 – Formatting the USB
- Format vs Fat FileSystem
- Format NTFS FileSystem
- Format EXT4 FileSystem
- Detect and mount USB devices in Linux from console
- Overview
- Understanding
- Listing
- 1. Identify the newly attached device
- 1.1 Using blk commands
- 1.2 Inspect Kernel ring buffer
- 1.3 dev-by- directories
- 2. Mount the device
- 3. Make it permanent
- 3.1 Mount a pendrive just by specifying a directory
- 4. Remove pendrive
- Optional
- Set pendrive label
- Summary
- Resources
- Articles
- Subcategories
- USB storage devices (Русский)
- Contents
- Монтирование USB устройств
- Автоматическое монтирование с помощью udev
- USB storage devices
- Contents
- Auto-mounting with udisks
- Manual mounting
- Getting a kernel that supports usb_storage
- Identifying device
- Mounting USB memory
- As root
- Allow writing by regular users
- As normal user with fstab
- Mount tools
- Troubleshooting
- No USB storage devices are acknowledged by the system
- USB device detected but not mountable
- Device not shutting down after unmounting all partitions
How to mount usb drive in a linux system
Do you know “how to use USB memory sticks with Linux”, If you are not sure then this article describes “how to mount USB drive on a Linux system with command line interface”
Universal serial bus, or USB (also known as Flash drive), is an electronic communications protocol that is commonly used in computer accessories and other small devices. If you have an up-to-date Linux system and a modern Desktop environment, your device should show up on your desktop, with no need to open a console. There are few important factors which are involved in learning how to mount USB drive with Linux machine.
Following are the step by step instructions to understand further –
Step 1: Plug-in USB drive to your PC
Step 2 – Detecting USB Drive
After you plug in your USB device to your Linux system USB port, It will add new block device into /dev/ directory. To verify it, use the following command –
The sample output should be like this –
We can observe from the above result that, device boot, blocks, id and system format are displayed.
Step 3 – Creating Mount Point
To mount the USB, use the following command –
To create a directory in the mounted device, use the following commands –
The above command creates a directory called john in USB device.
Step 4 – Delete a Directory in USB
To delete a directory in USB, use the following command –
Step 5 – Formatting the USB
You should unmount the device first to format the USB device, then use the following command to unmount the device –
Now use either of the commands as per file system based on your requirement. To format a USB drive, users generally prefer VFAT or NTFS file systems because they can be easily mounted on Windows operating systems and Linux systems.
Format vs Fat FileSystem
To format USB with vFat File System, use the following command –
Format NTFS FileSystem
To format a USB Flash Drive with NTFS file system, use the following command –
Format EXT4 FileSystem
To format a USB with EXT4 file system, use the following command –
Congratulations! Now, you know “How to Mount USB Drive in a Linux System?”. We’ll learn more about these types of commands in our next Linux post. Keep reading!
Источник
Detect and mount USB devices in Linux from console
Mount pendrives with commands in the Linux terminal
Overview
This is a small guide to detect a newly attached device to an USB port and mount it in Linux.
We will explore different strategies that will help when some of the tools isn’t available.
First of all, some definitions:
Understanding
What does exactly mount means?
All files accessible in a Unix system are arranged in one big tree, the file hierarchy, rooted at /. These files can be spread out over several devices. The mount command serves to attach the filesystem found on some device to the big file tree. Conversely, the umount(8) command will detach it again. The filesystem is used to control how data is stored on the device or provided in a virtual way by network or another services.
To attach these new devices filesystems we use the mount command in the form: mount -t type device dir .
In the above command, Devices (block special devices 1 ) can be indicated in one of the following three ways:
- Filename
- using the filename that is associated with the device.
- e.g.: /dev/sdb2
- Filesystem label
- Using the label associated with the device.
- e.g.: PENDRIVE
- UUID
- Universally Unique IDentifier (UUID) Uniform Resource Namespace 2 .
- e.g.: ba108o135-80bf-1cci-b2za-082eafd02y0g
Listing
To list the currently mounted devices/filesystems, findmnt (find a filesystem).
For example, in Ubuntu 18.10 it shows:
There is also the old way, maintained for compatibility only but widely used: mount -l or just mount .
Now we have just connected a pendrive (flash drive), how do we know which label or UUID it has to be able to mount the filesystem?
1. Identify the newly attached device
After we plug a pendrive, we need a method to locate the new device so we can get its label or UUID .
The following list shows the available alternatives to do it, any of them would be help you find the device information, listing most complete and easier to use first.
1.1 Using blk commands
The command lsblk prints all block devices (except RAM disks) in a tree-like format by default.
We can have a look at it to try to spot the new device with the filesystem parameter: —fs to print info of each filesystem, LABELs and UUID s on available block devices.
To directly find out the connected pendrive, save the above listing in a temporal folder and then look for the differences with the same command after plugging the pendrive:
1.2 Inspect Kernel ring buffer
Immediately after plugging the device, we can examine the kernel ring buffer with the command dmesg
There we can look for the string of type sda , or sdb , etc, that will belong to the most recent connected device.
In this case we can spot the sda: sda1 sda2 line that indicates it has two partitions: sda1 and sda2 .
Then we use the command blkid -p device to find out its UUID , label and more properties.
1.3 dev-by- directories
And a similar approach can be done to know which one was plugged in, saving the list before and after plugging the device:
2. Mount the device
Which method should we use?
Device names depend on which (physical) slot you connect the device, and if there are other devices already attached or not, so the filename to refer to them may change over time.
Labels are more stable than filenames, but they may change or have the same name as other label.
We will mount it at /media/usb-stick .
For this, create the directory: sudo mkdir /media/usb-stick
And then mount it with one of these methods, preferably UUID :
3. Make it permanent
There is a special file /etc/fstab , in which each line describes:
- what devices are usually mounted,
- where,
- using which options.
After reboot each line will be mounted automatically if the device is connected.
As we are working mostly with pendrives, we should use the special option: nofail. This avoids reporting any errors for the device if it does not exist at booting time when it tries to mount them and probably the device won’t be plugged..
3.1 Mount a pendrive just by specifying a directory
Personally, I like to have each pendrive or device identified like /media/kingstone-2gb so I can easily mount it with the directory name after plugging it.
4. Remove pendrive
sudo umount /media/usb-stick
Optional
Set pendrive label
To set create or rename the label of a pendrive there are several programs:
- e2label — Change the label on an ext2/ext3/ext4 filesystem
- tune2fs — adjust tunable filesystem parameters on ext2/ext3/ext4 filesystems
- mke2fs — create an ext2/ext3/ext4 filesystem
To set a pendrive label as usb-stick
Or create filesystem:
And change the label
Summary
Summarizing the commands used above in a single list:
Resources
block special file: A block special file is normally distinguished from a character special file by providing access to the device in a manner such that the hardware characteristics of the device are not visible. http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_79 ↩︎
A Universally Unique IDentifier (UUID) URN Namespace https://tools.ietf.org/html/rfc4122 ↩︎
Marcelo Canina
Articles
- Adding a swap memory to Linux from command line in 6 steps April 2, 2020
- Free up space in Linux (Ubuntu) March 27, 2020
- Switch between languages in Linux with xkb. Write in multiple languages with same keyboard. March 21, 2020
- How to make Ubuntu display emojis February 12, 2020
- Detect and mount USB devices in Linux from console
- How to make screencasts in Ubuntu Linux January 21, 2019
- Using i3 window manager in Linux January 7, 2019
- Setting Up A Fresh Linux Server August 25, 2018
- How To Download A Website With Wget The Right Way June 30, 2017
- Replicate Installed Package Selections From One Ubuntu System To Another April 24, 2017
- Using Clamav Antivirus In Ubuntu January 25, 2017
- How to Type Spanish Characters, Accents and Symbols in Linux June 6, 2016
Subcategories
Ubuntu
- How to activate tap to click touchpad’s feature in Ubuntu in 4 steps March 4, 2021
- Difference between suspend and hibernate in Ubuntu and how to execute them from command line April 12, 2020
- Solving Google Chrome’s gpu-process error message in Ubuntu Linux January 7, 2019
- Solving Google Chrome’s secret service operation error message in Ubuntu Linux January 7, 2019
- Start Emacs In Ubuntu The Right Way June 10, 2017
Unix Shell
- Connect to a Bluetooth device from command line in Ubuntu Linux June 23, 2020
- Add Infolinks Script To An Existing Website From Console With Sed Command April 4, 2017
- How to change all files permissions to 644 and directories to 755 January 10, 2017
- Shell Redirect Output And Errors To The Null Device In Bash December 9, 2016
- Prevent Running Of Duplicate Cron Jobs December 8, 2016
- Delete All Backup Files Recursively In Bash November 28, 2016
- Bash Script to Find Out If MySQL Is Running Or Not November 9, 2016
A comprehensive guide to manually mount a USB pendrive in Linux.
Источник
USB storage devices (Русский)
В этом документе описываются способы использования различных USB накопителей в Linux. Это также касается и других устройств, таких как цифровые камеры или телефоны, которые распознаются как обычные USB накопители.
Contents
Монтирование USB устройств
Если у вас свежая система со стандартным ядром Arch и современная среда рабочего стола, USB устройство должно автоматически появляться на рабочем столе при подключении, и лезть в консоль не потребуется.
Если этого не произошло см. далее.
Автоматическое монтирование с помощью udev
См. Udev:Монтирование съёмных устройств. Простой способ настройки автомонтирования жестких дисков для однопользовательских систем с использованием udev заключается в следующем: создается файл /etc/udev/rules.d/automount.rules со следующим содержимым:
и исполняемый от root файл /usr/lib/udev/domount со следующим содержимым (необходимо вставить корректные для Вашей системы значения):
При подключении USB-диска происходит автомонтирование и открывается окно терминала. Чтобы размонтировать устройства, просто нажмите Ctrl + D в окне терминала. Место монтирования определяется в /etc/fstab или, при его отсутствии, создается на основе UUID раздела.
Чтобы ваш пароль не запрашивался при команде размонтирования, добавьте (заменить на ваше имя пользователя) имя_пользователя в /etc/sudoers с помощью команды visudo. См. Sudo (Русский)
Если терминал не появляется проверьте команду его запуска. Например, в xfce4, используется команда «Terminal -T -e
Источник
USB storage devices
This document describes how to use the popular USB memory sticks with Linux. However, it is also valid for other devices such as digital cameras that act as if they were just a USB storage device.
If you have an up-to-date system with the standard Arch kernel and a modern Desktop environment your device should just show up on your desktop, with no need to open a console.
Contents
Auto-mounting with udisks
This is the easiest and most frequently used method. It is used by many desktop environments, but can be used separately too.
See Udisks for detailed information, including list of mount helpers.
Manual mounting
Getting a kernel that supports usb_storage
If you do not use a custom-made kernel, you are ready to go, for all Arch Linux stock kernels are properly configured. If you do use a custom-made kernel, ensure it is compiled with SCSI-Support, SCSI-Disk-Support and usb_storage. If you use the latest udev, you may just plug your device in and the system will automatically load all necessary kernel modules.
Identifying device
The first thing one needs to access a storage device is its identifier assigned by kernel. See fstab#Identifying filesystems for details.
Mounting USB memory
You need to create the directory in which you are going to mount the device:
As root
This article or section is a candidate for merging with File_systems#Mount_a_file_system.
Mount the device as root with this command (do not forget to replace device_node by the path you found):
If mount does not recognize the file system of the device you can try to use the -t argument, see mount(8) for details. If mounting does not work, you can try to recreate the file system or even repartition the disk.
Allow writing by regular users
If you want non-root users to be able to write to the USB stick, you can issue the following command:
If it does not work, make sure that the file system is mountable and writable as root, see the previous section for details.
As normal user with fstab
See FAT#Writing to FAT32 as normal user if you want normal user to do the mount/unmount action.
Mount tools
Multiple mount tools facilitate mounting as a regular user.
Troubleshooting
No USB storage devices are acknowledged by the system
If you have connected your USB storage device to the computer and it is not listed by lsblk or dmesg, ensure that your BIOS has both XHCI Handoff and EHCI Handoff enabled.
USB device detected but not mountable
If you recently upgraded you kernel, the modules for USB storage for your currently running kernel were removed and replaced with modules for the newly installed kernel. These modules will not be loaded until you reboot and run the new kernel.
Device not shutting down after unmounting all partitions
This article or section needs expansion.
Failure to power off a device might result in:
- a hard disk drive not parking its head, making a faint scratching sound while spinning out and degrading the device [2], or
- a solid-state drive (especially older) not flushing its cache buffers or updating its mapping tables, and losing data [3].
When you unmount the partitions, the device is still powered on. You should ask the system to turn it off first in order to safely remove it: [4]
If you use udisks, you can use these commands: [5]
Источник