Linux can open usb

How to access a usb flash drive from the terminal?

You’ll need to know what the drive is called to mount it. To do that fire off one of the following (ranked in order of my preference):

lsblk sudo blkid sudo fdisk -l 

You’re looking for a partition that should look something like: /dev/sdb1 . The more disks you have the higher the letter this is likely to be. Anyway, find it and remember what it’s called.

2. Create a mount point (optional)

This needs to be mounted into the filesystem somewhere. You can usually use /mnt/ if you’re being lazy and nothing else is mounted there but otherwise you’ll want to create a new directory:

3. Mount!

sudo mount /dev/sdb1 /media/usb 

When you’re done, just fire off:

This answer is almost 6 years old and while the core of it still works, things like fdisk -l aren’t the most user-friendly options. There are also new mechanisms in higher stacks for mounting devices in a sane and standard way which might not always be available.

So I’ve added some polish from the other answers. While you’re reading this footnote and you’re doing this on a desktop system, there definitely are arguments for using udisksctl , per wecac’s answer. This mounts in the same way the desktop does —creating your own /media/$USER/device directory— but I think there are still arguments for a static mountpoint, especially when you don’t want the path to change.

Udisks also relies on D-Bus, so might not be available everywhere.

the main disadvantage of this method is that it mounts the device as root. if the device is FAT formatted then the user won’t be able to write to it. the /media/$USER/device mountpoint will also always be the same

All answers assume that there magically appears a /dev/sdX after putting in the USB stick. What if it doesn’t? I see in the logs that it is detected, but no new /dev. lsusb show all the gory details too. Ie sudo lsusb -vs 15:2 | grep id gives idVendor 0x090c Silicon Motion, Inc. — Taiwan (formerly Feiya Technology Corp.) idProduct 0x1000 Flash Drive

@CarloWood I have faced a similar situation. In some logs, i think dmesg or something, I found that the drive was unable to power itself up. I just ended up using a different port for the drive. As far as i know there is not a way to mount a drive, whose device driver hasnt created a device file in /dev/

pmount / pumount

Install pmount . Mounts disks in /media/

pmount /dev/sdb1 pumount /dev/sdb1 

Replace «sdb1» with your specific device path. For more information see the manpage:

pmount ("policy mount") is a wrapper around the standard mount program which permits normal users to mount removable devices without a match- ing /etc/fstab entry. pmount is invoked like this: pmount device [ label ] This will mount device to a directory below /media if policy is met (see below). If label is given, the mount point will be /media/label, otherwise it will be /media/device. 

Thanks, I knew how to do the accepted answer but was looking for something a bit easier that didn’t leave me having to clear up empty folders myself.

Читайте также:  Adobe illustrator linux ubuntu

Use udisksctl from package= udisks2 (in both Ubuntu and Debian). Procedure is:

    Find the ID of the block device you want to mount, using lsblk :

user@machine:~$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 1.8T 0 disk ├─sda1 8:1 0 19.1M 0 part /boot/efi ├─sda2 8:2 0 1.8T 0 part └─sda3 8:3 0 16G 0 part [SWAP] sdb 8:16 0 931.5G 0 disk ├─sdb1 8:17 0 37M 0 part ├─sdb2 8:18 0 15.9G 0 part [SWAP] └─sdb3 8:19 0 915.7G 0 part / sdc 8:32 1 14.4G 0 disk └─sdc1 8:33 1 14.4G 0 part sdd 8:48 0 1.8T 0 disk └─sdd1 8:49 0 1.8T 0 part 
user@machine:~$ udisksctl mount --block-device /dev/sdc1 ==== AUTHENTICATING FOR org.freedesktop.udisks2.filesystem-mount === Authentication is required to mount Kingston DT microDuo 3C (/dev/sdc1) Multiple identities can be used for authentication: 1. XXXXX. (user) 2. . (YYYYY) Choose identity to authenticate as (1-2): 1 Password: ==== AUTHENTICATION COMPLETE === Mounted /dev/sdc1 at /media/user/USBDRIVELABEL. 

Addressing Hans Deragon’s comment below: you can also tell udisksctl to do —no-user-interaction . It does not attempt to authenticate the user, which usually «just works»:

user@machine:~$ udisksctl mount --block-device /dev/sdc1 --no-user-interaction # possibly some complaining here about I/O charset or need to run `fsck` Mounted /dev/sdc1 at /media/user/USBDRIVELABEL. 

In addition to using the standard mount command (which requires root) you can mount drives using udisks and dbus with your standard user.

To do this it is useful (but not required) to know a few things about the drive first:

Knowing these you can use a simple command to mount a drive from the command line.

gdbus call --system --dest org.freedesktop.UDisks --object-path /org/freedesktop/UDisks/devices/ --method org.freedesktop.UDisks.Device.FilesystemMount "" [] 

this call should echo the path it is mounted at if the mount succeeds.

To unmount drives mounted in this way you can run:

gdbus call --system --dest org.freedesktop.UDisks --object-path /org/freedesktop/UDisks/devices/ --method org.freedesktop.UDisks.Device.FilesystemUnmount [] 

N.B. the is simply the end of the path to it. So for example if what you want to mount is at /dev/sdb2 then you would put sdb2 in place of .

If you do not know which device it is or what filesystem it uses do not fear. You can easily print out all that information with this little command:

gdbus introspect --system --dest org.freedesktop.UDisks --object-path /org/freedesktop/UDisks/devices --recurse --only-properties | grep -E "(readonly .+ (IdLabel|IdType|Device(IsMounted|IsDrive|File) ).*|\>|.*\<)" 

This will print out something like this:

node /org/freedesktop/UDisks/devices < node /org/freedesktop/UDisks/devices/sda < interface org.freedesktop.UDisks.Device < readonly s IdLabel = ''; readonly s IdType = ''; readonly s IdUsage = ''; readonly b DeviceIsMounted = false; readonly s DeviceFile = '/dev/sda'; >; >; node /org/freedesktop/UDisks/devices/sda1 < interface org.freedesktop.UDisks.Device < readonly s IdLabel = 'SYSTEM'; readonly s IdType = 'ntfs'; readonly s IdUsage = 'filesystem'; readonly b DeviceIsMounted = false; readonly s DeviceFile = '/dev/sda1'; >; >; node /org/freedesktop/UDisks/devices/sda2 < interface org.freedesktop.UDisks.Device < readonly s IdLabel = 'Windows7'; readonly s IdType = 'ntfs'; readonly s IdUsage = 'filesystem'; readonly b DeviceIsMounted = true; readonly s DeviceFile = '/dev/sda2'; >; >; node /org/freedesktop/UDisks/devices/sda3 < interface org.freedesktop.UDisks.Device < readonly s IdLabel = 'Recovery'; readonly s IdType = 'ntfs'; readonly s IdUsage = 'filesystem'; readonly b DeviceIsMounted = false; readonly s DeviceFile = '/dev/sda3'; >; >; node /org/freedesktop/UDisks/devices/sda4 < interface org.freedesktop.UDisks.Device < readonly s IdLabel = ''; readonly s IdType = ''; readonly s IdUsage = ''; readonly b DeviceIsMounted = false; readonly s DeviceFile = '/dev/sda4'; >; >; node /org/freedesktop/UDisks/devices/sda5 < interface org.freedesktop.UDisks.Device < readonly s IdLabel = ''; readonly s IdType = 'ext4'; readonly s IdUsage = 'filesystem'; readonly b DeviceIsMounted = true; readonly s DeviceFile = '/dev/sda5'; >; >; node /org/freedesktop/UDisks/devices/sda6 < interface org.freedesktop.UDisks.Device < readonly s IdLabel = ''; readonly s IdType = 'swap'; readonly s IdUsage = 'other'; readonly b DeviceIsMounted = false; readonly s DeviceFile = '/dev/sda6'; >; >; node /org/freedesktop/UDisks/devices/sda7 < interface org.freedesktop.UDisks.Device < readonly s IdLabel = ''; readonly s IdType = 'ext4'; readonly s IdUsage = 'filesystem'; readonly b DeviceIsMounted = true; readonly s DeviceFile = '/dev/sda7'; >; >; node /org/freedesktop/UDisks/devices/sdb < interface org.freedesktop.UDisks.Device < readonly s IdLabel = ''; readonly s IdType = ''; readonly s IdUsage = ''; readonly b DeviceIsMounted = false; readonly s DeviceFile = '/dev/sdb'; >; >; node /org/freedesktop/UDisks/devices/sdb1 < interface org.freedesktop.UDisks.Device < readonly s IdLabel = 'USB DRIVE'; readonly s IdType = 'vfat'; readonly s IdUsage = 'filesystem'; readonly b DeviceIsMounted = false; readonly s DeviceFile = '/dev/sdb1'; >; >; node /org/freedesktop/UDisks/devices/sr0 < interface org.freedesktop.UDisks.Device < readonly s IdLabel = ''; readonly s IdType = ''; readonly s IdUsage = ''; readonly b DeviceIsMounted = false; readonly s DeviceFile = '/dev/sr0'; >; >; >; 

Those that have IdUsage = 'filesystem' may be mounted using the above command.

Читайте также:  Linux загружается только grub

This means that, for example, if i wanted to mount the device 'USB DRIVE' i would run the command

gdbus call --system --dest org.freedesktop.UDisks --object-path /org/freedesktop/UDisks/devices/sdb1 --method org.freedesktop.UDisks.Device.FilesystemMount "vfat" [] 

These commands all work using the dbus messaging system, the same way that Nautilus and other file managers auto-mount things. In these commands we are sending various objects (i.e. /org/freedesktop/. messages asking them to mount and unmount certain devices. They might or might not do this depending on the permissions one has been given in PolicyKit .

Using similar commands one can control almost every aspect of ones experience in Ubuntu and simulate most system programs and functions (i.e. shutdown, volume change, etc.).

Источник

How To Mount/Unmount USB Drive On Ubuntu And Other Linux Distros?

How To Mount/Unmount USB Drive On Ubuntu And Other Linux Distros?

I s your USB drive not showing on your Linux system? Are you unable to access your external disk drive? By mounting your USB drive to the Linux filesystem, you can resolve this issue. In this article, let’s look at how to mount and unmount the USB flash drives or external hard disks in Linux.

This article will go through both command line and graphical user interface (GUI) methods. The former method for mounting a USB drive works on all Linux distributions. However, if you’re a beginner and use Ubuntu or Ubuntu-based distributions, you can mount using the GUI application.

Why Is USB Not Detected In Linux?

If you plug in your USB device (aka USB sticks, thumb drives, and Pendrive) for the first time, Linux usually mounts it automatically. But sometimes, Linux fails to recognize and mount a USB drive to its filesystem. This is why you find the USB not showing on the Linux operating system.

Linux filesystem follows a tree directory structure with all files and folders attached to a single root directory. So, if you want to access and use external storage devices, first, you have to mount it to the Linux filesystem.

To mount a USB drive in Linux using a terminal, follow the step-by-step instructions given below. If you’re using Ubuntu Linux and aren’t familiar with the command line, skip the first method to the next one and mount and unmount the USB drive using the Ubuntu GUI application.

How To Mount USB Drive In Linux Using Command Line

1. Detect Plugged In USB Device

Once you plug in your USB device to your system USB port, run the following command to locate the USB device:

Running command to detect USB device

Now you can see the detected USB device named ‘sdb.’ Your device name may differ from mine, so you can find the device name matching its size.

You can also notice that the device ‘sdb’ has no mount point here. If you also find the same, it means the USB drive is not mounted to the Linux system. Hence, you can’t access your drive files and folders.

2. Create a Mount Point

To access the USB drive data, we’ve to create a directory that will act as a mount point in the Linux filesystem. Here, I’m creating a new directory at ‘/media’, where we’ll mount the device later.

However, creating a directory to mount and access a drive is an optional step; you can also directly attach it to the ‘/media’ directory.

Читайте также:  Linux setting date timezone

Creating a mount point

3. Mount USB Drive To Mount Point

We’re now ready to link the USB device to the Linux filesystem and access its data. We’ll use the ‘mount’ utility program to do the same. If you want to know about ‘mount,’ read its manual using:

About mount

If your USB disk drive has a FAT16 or FAT32 file system, you can mount the device by running the command:

sudo mount /dev/sdb /media/pendrive

Replace ‘sdb’ with your device name.

Running command to mount the USB device

Most USB flash drives use FAT16 or FAT32, while some external hard disks use NTFS. If you have a file system other than FAT, use a flag to specify file system type like ntfs-3g for NTFS.

sudo mount -t ntfs-3g /dev/sdb /media/pendrive

4. Check For The Device Mounted

If all goes well with the previous steps, you can now access your USB drive file and folders. You can check the status of the device using the same ‘lsblk’ command:

The device is mounted at a mount point

As you can see, the USB drive ‘sdb’ now has a mount point which means it is mounted at that location. So, navigate to the directory (mount point) where you can access your drive data.

How to Unmount USB Drive In Linux Using Command Line

Unmounting the USB device is just a one-line command using ‘umount’:

sudo umount /media/pendrive

Running command to detect the mounted USB device

You can see that the mount point has been removed, and you can again no longer access your USB drive.

Note: Most Linux distros configure the settings to automount the same USB drive to the system for future use. But if you’re again unable to access your USB device, you can either perform the same steps or manually set the device to automount. You can follow our article on how to automount partitions on boot.

How To Mount USB Drive On Ubuntu Using GUI

Mounting an external drive or USB flash drive using the GUI application is pretty straightforward. Several Linux distros already offer GUI applications for the same. Here, I’ll guide you to mount/unmount a USB drive on Ubuntu using the GUI application.

1. Open Disks Application

Open the Activities overview from the top left corner and search for the ‘Disks’ application.

Search For Disks

Click to open the app, and you will notice that it automatically displays the ‘Not Mounted’ status for connected USB devices.

Device Not Mounted

2. Mount A USB Device To Ubuntu Linux Filesystem

Just click on the play button to mount the USB drive, as pointed out in the picture below. It will automatically create a mount point and attach the device to it.

Click To Mount

3. Check For The Mounted Device

The moment you click on the play button, you’ll notice a drive icon pop up in your dock.

USB Drive Icon

If you click on the icon, it will open the USB drive in the file manager, where you can access all your drive data.

USB Drive Data

You can also see the USB drive status ‘Mounted’ with mount point location at ‘/media//’.

Mounted Device With Mount Point

4. Unmount USB drive On Ubuntu

Lastly, click on the same play button to detach or unmount the USB drive from the Ubuntu Linux system.

Unmount The USB Drive

So, that was how you could mount/unmount USB drives on Ubuntu and other distros using the Terminal and GUI. If you have any questions or find the guide difficult to follow, let us know in the comments section below.

Sarvottam Kumar

Sarvottam Kumar is a software engineer by profession with interest and experience in Blockchain, Angular, React and Flutter. He loves to explore the nuts and bolts of Linux and share his experience and insights of Linux and open source on the web/various prestigious portals.

Источник

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