I only have access to the command line.
I need to backup my data (on the user folder) to a pen (USB DOK).

  • How can I mount a flash drive manually?
  • What should be the copy command?
share|improve this question
up vote 262 down vote accepted

1. Find what the drive is called

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:

sudo  mkdir /media/usb

3. Mount!

sudo mount /dev/sdb1 /media/usb

When you're done, just fire off:

sudo umount /media/usb

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.

share|improve this answer
2  
I can't vote up. :( Sorry. I missed my normal user. :( Can I please ask if cp -r * /media/usb will copy ALL files and folders ? – MEM Apr 29 '11 at 0:56
1  
I'd use rsync -- something like: rsync -avh ~/directory/ /media/usb/ – Oli Apr 29 '11 at 1:13
    
Thank you. Then I can perhaps burn a reconvery cd or somehting? – MEM Apr 29 '11 at 1:31
    
@user15301 I don't know for that. Sounds like something for another question! – Oli Apr 29 '11 at 1:44
10  
mount: you must specify the filesystem type – Cyle May 5 '14 at 17:41

For Ubuntu 14.04 you can use udisksctl

1.Find out the block device

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

2.Going by the size /dev/sdc1 seems to be the usb device I am looking to mount.

user@machine:~$ udisksctl mount -b /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.
share|improve this answer
    
This is the only solution that mounts the drive exactly the same way it would be if mounted using the GUI (via Nautilus for example). It mounts the drive under the user's name and uses the drive label for the final directory. The only caveat is that it requires to give the user's password and the user must know of the device. What would be great is to have a command that mounts any USB devices without questions. – Hans Deragon Jul 2 '17 at 11:43

You can also automatically mount USB devices on Ubuntu Server with the help of USBmount.

Make sure you run apt-get update/upgrade before starting the installation:

sudo apt-get update && sudo apt-get upgrade

Now install USBmount from the repositories:

sudo apt-get install usbmount

USBmount mounts all USB drives in /media/usb* (usb0, usb1, usb2 ...)

Now plug a USB drive and wait for it to be detected and mounted. As long as the host OS supports the File System it should be mounted.

To verify whether the USB drive was mounted correctly you can use df -h to view all available drives and their respective mount points

To un-mount a drive you can use umount.

sudo umount /media/usb0
share|improve this answer

I've found that the mount command (listed as first response/answer above) is great to have the system make the USB drive available for use. If I want to copy bunches of files and/or folders from the USB drive to my internal drive, I love to use the MC (Midnight Commander) interface! MC lets you work in two side-by-side panes, tab between each pane, use the different menus or "buttons" to copy/move/delete, etc bunches of files/folders, use filtering to only select certain files (with wild cards, etc.) Really great tool that take the sting out of console work. Should be available in your favorite repository!

share|improve this answer

Install pmount. Mounts disks in /media/

pmount /dev/sdb1
pumount /dev/sdb1

No sudo needed. 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.
share|improve this answer
2  
This is the best method here. Simple, doesn't need root. – Dan Ross Feb 11 '14 at 3:38
1  
I'll second that, I also like that it mounted my flash stick's files and folders with my regular user's name/group, and not root, meaning I didn't have to prefix 'sudo' to every command targeting the drive. – Big Rich Apr 15 '15 at 0:41
    
still needs root to install pmount – Doleron yesterday

That's simple. When I want to use a usb drive in terminal I do this:

Create a folder in /media with:

mkdir /media/mountDrive 

This folder will be used for the mount point. Use this command:

sudo mount /dev/sdd1 /media/mountDrive 

sdd1 is the first partition of my USB. Then you can navigate to folder you already mounted with

cd /media/mountDrive

If you want to list the files in drive you can use the ls command.

To unmount the drive you can use

sudo umount /dev/sdd1

Note that in my system the usb drive is /dev/sdd1, but in your system it may be something different. To find out what it is use the df command to see all disks connected at the present time.

share|improve this answer
    
I followed ur instructions and I mounted USB but the thing is that when i navigate to my USB through Terminal and do LS it shows nothing. Mount Drive name = MD – OmiPenguin Sep 1 '12 at 8:14
1  
Well I found a way. I just simply navigate to /Media folder and USB Folder was already available. My named my USB as a PENDRIVE so the complete path is /media/PENDRIVE And then I did ls and files appeared in Terminal. – OmiPenguin Sep 2 '12 at 19:36

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:

  1. What device it is (i.e. /dev/sdb1)
  2. what filesystem it uses.

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/<device> --method org.freedesktop.UDisks.Device.FilesystemMount "<filesystem>" []

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/<device> --method org.freedesktop.UDisks.Device.FilesystemUnmount []

N.B. the <device> 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 <device>.


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.

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.).

share|improve this answer
5  
how is this simpler? I got confused mid reading it – mojo706 Aug 27 '14 at 14:31
    
The 2015 way is gdbus introspect --system --dest org.freedesktop.UDisks2 --object-path /org/freedesktop/UDisks2/drives --recurse --only-properties – Nick Sandor Jun 10 '15 at 22:09

protected by Community Feb 9 '15 at 18:25

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.