How use usb in linux

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.

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

Note: Before you decide that Arch Linux does not mount your USB device, be sure to check all available ports. Some ports might not share the same controller, preventing you from mounting the device.

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 File systems#Identify existing file systems for details.

Newly plugged-in devices are usually shown in the journal.

Mounting USB memory

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:

# mount -o gid=users,fmask=113,dmask=002 /dev/sda1 /mnt/usbstick

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 detected

If you have connected your USB storage device and it is not listed by lsblk but appears in the journal without being assigned a block device, see General troubleshooting#Cannot use some peripherals after kernel upgrade.

Читайте также:  Vnc linux to mac

Also ensure that your BIOS has both XHCI Handoff and EHCI Handoff enabled, but this is usually not an issue with most modern devices.

Device not shutting down after unmounting all partitions

This article or section needs expansion.

Reason: Please advise how to automatically shut down devices after unmounting (Discuss in Talk:USB storage devices)

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]

# echo 1 > /sys/block/disk_name/device/delete

If you use udisks, you can use these commands: [5]

$ udisksctl unmount -b /dev/sdXY $ udisksctl power-off -b /dev/sdX 

Device is detected but does not register as mountable

udev is shipped with a default set of rules, found in /usr/lib/udev/rules.d/ , including one for ignoring some specific devices for various reasons. Some hardware devices, such as digital cameras, portable recorders, etc., may format usb storage in a way that results in the ignore rules to be triggered. You can check if one of these rules was applied with the following command and then find the corresponding conditions in the defaults:

$ udevadm info --attribute-walk --name=device_name | grep UDISKS_IGNORE

If this is the case and your device has this property set to «1», you can override it with a custom rule, following the udev page.

Источник

How to Mount USB Drives in Linux? [The Easy Way]

Mounting USB Drives In Linux

When it comes to using Linux, effectively managing USB drives is a crucial skill for everyone, whether you’re just starting or a seasoned user. Linux’s many capabilities allow us to efficiently handle USB devices, but some users may not know where to start. But don’t worry – we’ve put together a complete guide to walk you through the process of easily mounting USB drives in Linux. This article will cover everything from identifying your USB drive to creating a mount point and finally mounting the block device. Whether you’re a beginner or an expert, this guide will give you the knowledge to easily access, manage, and unmount your USB drives like a pro. So let’s get started and unlock the full potential of USB drive management in Linux!

Steps to Mount USB Drives in Linux

Let’s go over the steps without any further delays. The entire process is straightforward, and I’ll walk you through it as a beginner.

Step 1: Plug In The USB Drive

USB Plug In Mount USB Drives in Linux

Plug the USB Drive in the correct USB Port (check for 2.x/3.x specific ports for better performance). Make sure your hardware is all fine, and just with that, we are done with Step 1!

Step 2: Identify Your USB Drive

To use our USB Device, first, we need to identify it. Now there are a couple of different commands which can be used here. However, we will go with trusty old fdisk in command line which lists our USB Drive along with its model name, the drive’s capacity, and much more!

Читайте также:  Connect to vpn pptp linux

Once the USB drive has been plugged in, it will be registered as a new block device in /dev/ directory ( Remember that everything in Linux is a file!). To list all block devices, we can type:

This should return something like follows :

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 931.5G 0 disk ├─sda1 8:1 0 512M 0 part /boot/efi ├─sda2 8:2 0 929G 0 part /var/lib/lxd/storage-pools/default └─sda3 8:3 0 2G 0 part [SWAP] sdb 8:16 1 57.3G 0 disk └─sdb1 8:17 1 57.3G 0 part

Here sda is the primary block device whereas sda1, sda2 an d sda3 are the various partitions where the components of the running Operating System are located. Next comes sdb, which represents our USB Drive as a block device. Likewise, sdb1 denotes the partition on the USB Drive in our case.

If you have multiple hard disks installed, it will be different. From the above output, we can also see the size of various partitions and their mount points. As one can see, our USB Drive is not mounted, but we’ll fix that in a minute.

Note that the name of our USB block device may be something other than sdb. Still, it’s almost always of the form sdX, where X usually is a smaller case alphabet like ‘b’, ‘c’, ‘d’, and so on but is seldom ‘a’ as it usually denotes the primary block device containing the Operating System. Also

Moving on, we can identify our USB Drive using the following :

In the output, we should get an output like this :

Disk /dev/loop0: 49.9 MiB, 52260864 bytes, 102072 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/loop1: 55.6 MiB, 58310656 bytes, 113888 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/loop2: 339.9 MiB, 356356096 bytes, 696008 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disklabel type: gpt Disk identifier: E3C13307-58B0-4C45-AD3F-DF4C1449D7D4 Device Start End Sectors Size Type /dev/sda1 227328 20971486 20744159 9.9G Linux filesystem /dev/sda14 2048 10239 8192 4M BIOS boot /dev/sda15 10240 227327 217088 106M EFI System Partition table entries are not in disk order.

From the given output, we can identify our USB Drive’s model, size, and other information which can help us pinpoint our USB Drive. Note the Block Name from here, which is /dev/sda in the given example is Linux Filesystem, had it been a windows system we would have seen ntfs file system. Now, lets proceed to the next step.

Output Of Fdisk L

Step 3: Creating A Mount Point

Now that we have identified which Block Device we want to mount, we would need a place to mount it to. Usually, we make a folder under /mnt directory using the mkdir command:

Читайте также:  Kali linux подключить bluetooth наушники

With this, we finally have a place to mount our block device. Onto the next step!

Step 4 : Mount The Block Device

Finally, we can now mount our USB Drive in the folder we made earlier! This can be easily done via the mount command. Following our example, remember that we had our USB Drive registered as the block device /dev/sdb? Remember how it had a partition /dev/sdb1? We cannot mount block devices, rather we shall mount this partition as follows:

$ sudo mount /dev/sdb1 /mnt/USB/

And now, we can access the contents of our USB Drive right as if it were just another folder on our Desktop. We can also change the ownership of the folder where we mounted our USB Drive as such :

After the above command, you no longer need to type sudo repeatedly whenever we move data to-and-from our USB Device! Just to validate that our USB Drive has been mounted correctly, we can return it to our good friend lsblk and it should show us an output like:

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 931.5G 0 disk ├─sda1 8:1 0 512M 0 part ├─sda2 8:2 0 929G 0 part /home └─sda3 8:3 0 2G 0 part [SWAP] sdb 8:16 1 57.3G 0 disk └─sdb1 8:17 1 57.3G 0 part /mnt/USB

As we can see, our USB Drive is mounted in the folder we previously created ( /mnt/USB ); hence, we have successfully mounted our USB Drive!

Bonus: How To Unmount USB Drive?

Once we finish all of our desired USB operations, unmounting our USB Drive before physically removing it from our machine is good practice. This can be achieved via the umount command that umounts media attached to the system. Just simply type in:

$ sudo umount [FOLDER WHERE DRIVE IS MOUNTED]

Staying consistent with our previous example, this would translate to:

With that, we are done and free to remove our physical media like usual!

Conclusion

To sum up, connecting a USB drive to a Linux system is an easy and effective process that can be done in four uncomplicated steps. These steps include plugging in the USB drive, identifying it, making a mount point, and finally mounting the block device. Once you have mastered these steps, you will have seamless access to the contents of your USB drive on your Linux system. Moreover, you will also learn how to safely unplug your USB drive after use to safeguard your data. This beginner-friendly guide enables Linux newcomers to effortlessly navigate the process and enjoy the advantages of using USB drives on their Linux devices.

Note that sometimes, the mount command fails to mount our USB Drive, primarily because of file types: The USB Drive might have a different file system than the Operating System. In such cases, the -t flag can be used to specify the type of file system you want to mount. For more information, check out the man pages for mount.

Источник

Оцените статью
Adblock
detector