24

How to properly copy files from hard drive to USB flash drive in tty4 terminal?(mount, copy, unmount, exit, etc)

P.S.Can no exit from tty4 terminal via Ctrl+Alt+F7 command, only with Alt+SysRq+B(kernel restart).

2 Answers 2

30
  1. Plug in the device

  2. lsblk to find the device name of your usb device. Naming is /dev/sdXY. Where X is any english letter and Y is integer, typically 1.

If the device was mounted, you will see the mountpoint, for example:

NAME         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb            8:0    1 15.2G  0 disk 
└─sdb1         8:1    1 15.2G  0 part /media/me/4C45-110F

If not, mount it. Follow to the step #3

  1. udisksctl mount -b /dev/sdXY , device name same as in previous step. (/dev/sdb1 in my example) The mount folder will be reported back to you to use in the next step. For example, suppose lsblk tells me this:

    sdc 8:32 1 7.5G 0 disk └─sdc1 8:33 1 7.5G 0 part

Then I will do the following:

$ udisksctl mount -b /dev/sdc1                                                 
Mounted /dev/sdc1 at /media/xieerqi/A669-34EF.

You can see it automatically created /media/xieerqi/A669-34EF folder and mounted my pen drive there. Also , big advantage is that you do not need sudo.

  1. Use rsync or cp or mv to get your files to the folder reported in step 3. Consult manual pages on usage of these commands. cp and mv are simplest. mv FILE DESTINATION - in my example (where FILE is the thing you want to move to the drive)

    mv FILE /media/me/4C45-110F
    

rsync is the best for backup however.

For example, to backup TESTDIR to my usb drive, I can do this:

$ rsync -av /home/xieerqi/TESTDIR/ /media/xieerqi/A669-34EF/~                  
sending incremental file list
created directory /media/xieerqi/A669-34EF/~
./
file1
file2
file3

sent 228 bytes  received 125 bytes  706.00 bytes/sec
total size is 0  speedup is 0.00
  1. udisksctl unmount -b /dev/sdXY. Remove the device

Example

$ udisksctl unmount -b /dev/sdc1
Unmounted /dev/sdc1.

NOTE: some drives mount to directories that have names with spaces. If you run rsync or mv with not quoted names like that, your data will not be copied to correct destination. Always quote pathnames that have spaces in them.

8
  • What is purpose of udisksctl command? I just saw several examples without udisksctl. Also, what is -b option?
    – minto
    Commented Jul 25, 2016 at 20:30
  • 1
    udisksctl is part of udisks package, and comes by default with Ubuntu. Basically , it's a utility for doing all the basic actions like mounting , unmounting , checking info about a disk, but without need for running sudo. Such utilities as mount require superuser privilleges to work. -b option stands for block-device, which is what /dev/sdXY is classified as. Every hard-drive or usb drive is classified as block device Commented Jul 25, 2016 at 20:41
  • No need to use` sudo mkdir /media/usbstick ` command before mounting? Some manuals use this command.
    – minto
    Commented Jul 26, 2016 at 9:21
  • @minto udisksctl does it automatically for you. I will be adding more examples later, so you will see how it works Commented Jul 26, 2016 at 9:30
  • One important note: if USB stick inserted into USB port, it already mounted , I assume. Command lsblk show sdb -> sdb1. In this case, if I run udisksctl mount -b /dev/sdb1, it return error "device already mounted..."
    – minto
    Commented Jul 28, 2016 at 20:20
13

In my case the above answer was no working so i tried this. My system config is Ubuntu 14.04, while updating to 16.06 LTS, suddenly it stopped to work so to copy my important files , I used my pen-drive to copy.

1. List the Mount device:

lsblk

2. Create a mount point :

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

4. Copy

 rsync -av /home/android/Testproject/ /media/usb/ 

5.Un-Mount
When you're done, just fire off:

sudo umount /media/usb
1
  • Perfect! Thank you! But as I wanted to copy the files that are on my USB I did sth like this instead rsync -av /media/usb/ /home/android/Testproject/ Commented Jun 13, 2022 at 8:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .