0

I am trying to copy the files on my ubuntu home directory to a USB flash drive. I am following these guidelines How to access a usb flash drive from the terminal?. When I run lsblk I get lsblk: failed to access sysfs directory: /sys/dev/block: No such file or directory. When I run sudo blkid I get nothing. When I run fdisk -l I get fdisk: cannot open /proc/partitions: No such file or directory. When I run cd media and ls I get nothing. I also ran lsusb, and I got unable to initialize libusb: -99. Ran usb-devices, got nothing. Same with dmesg | grep -i USB.

Getting kinda desperate. Help would be much appreciated.

Update: I run mkdir /mnt/c and sudo mount -t drvfs C: /mnt/c then ls /mnt/c and I got:

ls: cannot access 'DumpStack.log.tmp': Permission denied
ls: cannot access 'hiberfil.sys': Permission denied
ls: cannot access 'pagefile.sys': Permission denied
ls: cannot access 'swapfile.sys': Permission denied
'$Recycle.Bin'             Intel                  ProgramData                  Users          hpswsetup
'$WinREAgent'              OneDriveTemp           Programas                    Windows        pagefile.sys
'Documents and Settings'   PerfLogs               Recovery                     adobeTemp      swapfile.sys
 DumpStack.log            'Program Files'        'System Volume Information'   hiberfil.sys
 DumpStack.log.tmp        'Program Files (x86)'   System.sav                   hp

I guess what I did was mounting the whole windows system to WSL. How do I access my flash drive now?

muru
  • 197,895
  • 55
  • 485
  • 740

1 Answers1

1

It sounds from the comments like you are close, but I'm going to repeat everything here to be clear.

  • In Windows, identify the drive letter for your USB drive. It sounds like that is E:, but just in case, we're going to call it <drive_letter>: (that's the letter, followed by a colon).

  • In Windows, save an empty file from Notepad onto the USB drive so that we can confirm that it's correct later. You can call this file test.txt or anything else.

  • In Ubuntu in WSL:

    sudo mkdir /mnt/<drive_letter> # substitute your drive letter, with no colon
    # Don't worry if the above fails if the directory already exists
    

    sudo mount -t drvfs <drive_letter>: /mnt/<drive_Letter> -o uid=$(id -u $USER),gid=$(id -g $USER),metadata

    the first time, use the colon, the second time, no colon.

    ls /mnt/<drive_letter>

    Confirm that the file you saved from Notepad

    is in the drive. This means that you've

    mounted it correctly.

    That mounts the drive with your user/group as the owner, and adds the metadata option so that WSL can store Linux permissions on NTFS drives.

  • To copy over your user directory to that drive, you can use something like:

    sudo cp -axv ~ /mnt/<drive_letter>
    
    • -a: Archive recursively, including permissions
    • -x: Only copy files from the Ubuntu/WSL filesystem. Prevents copying from other Windows drives if you happened to create a symlink somewhere in your home directory.
    • -v: Verbose, so that you can see the filenames as they copy
NotTheDr01ds
  • 17,888
  • Thank you so very much for your answer! It was so helpful. I managed to copy everything to my flash drive so easily. Can you please tell me how do I do to download it to another PC? – Solar da Marta Aug 10 '22 at 10:35