Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

I don't know where/how can I do this is order to access the pen, and then do the cp command.

How can we do this?

share|improve this question

4 Answers 4

up vote 51 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:

sudo fdisk -l

You're looking for a partition that should look something like: /dev/sdb1. Remember what it's called.

2. Create a mount point

Create a new directory in /media so you can mount the drive onto the filesystem:

sudo  mkdir /media/usb

3. Mount!

sudo mount /dev/sdb1 /media/usb

When you're done, just fire off:

sudo umount /media/usb
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
1  
mount: you must specify the filesystem type –  Cyle May 5 at 17:41

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
    
how is this simpler? I got confused mid reading it –  mojo706 Aug 27 at 14:31

Install pmount, and mount a disk in /media/ like this:

pmount /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.

To unmount, use pumount.

pumount /dev/sdb1
share|improve this answer
    
This is the best method here. Simple, doesn't need root. –  Dan Ross Feb 11 at 3:38

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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