9

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

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

  • What is purpose of udisksctl command? I just saw several examples without udisksctl. Also, what is -b option? – minto Jul 25 '16 at 20:30
  • 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 – Sergiy Kolodyazhnyy Jul 25 '16 at 20:41
  • No need to use` sudo mkdir /media/usbstick ` command before mounting? Some manuals use this command. – minto Jul 26 '16 at 9:21
  • @minto udisksctl does it automatically for you. I will be adding more examples later, so you will see how it works – Sergiy Kolodyazhnyy Jul 26 '16 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 Jul 28 '16 at 20:20
4

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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