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?
I only have access to the command line.
I need to backup my data (on the user folder) to a pen (USB DOK).
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):
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!
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.
pmount
/pumount
Install
pmount
. Mounts disks in /media/No
sudo
needed.Replace "sdb1" with your specific device path. For more information see the manpage:
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
:From its size,
/dev/sdc1
seems to be the USB drive I want to mount.Use
udisksctl
to mount the device. Note that-b
==--block-device
(to reduce typing) but I prefer long options for documentation: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":In addition to using the standard
mount
command (which requires root) you can mount drives usingudisks
anddbus
with your standard user.To do this it is useful (but not required) to know a few things about the drive first:
/dev/sdb1
)Knowing these you can use a simple command to mount a drive from the command line.
this call should echo the path it is mounted at if the mount succeeds.
To unmount drives mounted in this way you can run:
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 putsdb2
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:
This will print out something like this:
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
These commands all work using the
dbus
messaging system, the same way thatNautilus
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 inPolicyKit
.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.).
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:
Now install USBmount from the repositories:
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 pointsTo un-mount a drive you can use umount.
That's simple. When I want to use a usb drive in terminal I do this:
Create a folder in
/media
with:This folder will be used for the mount point. Use this command:
sdd1
is the first partition of my USB. Then you can navigate to folder you already mounted withIf you want to list the files in drive you can use the
ls
command.To unmount the drive you can use
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 thedf
command to see all disks connected at the present time.I will not add about how to mount the drive. However since the asker also asked what the best command to use to copy the data over, I will answer that since it was not answered as far as I can tell.
I would recommend first creating a folder on the drive (even if it is empty) to back your stuff into to provide organization. Something along the lines of
mkdir <mountpath>/mybackup
should do it.Second, I would use rsync to copy everything over. Do something along the lines of
rsync -r ~/* <mountpoint>/mybackup
. You can also usecp -r
if you want, however, I have found that doing so doesn't do quite everything that you would expect all of the time.