How to copy files to usb in linux

How do I copy a file larger than 4GB to a USB flash drive?

Is the USB drive formatted with FAT32? That file system does not support files larger than 4GB. You have to format it differently then, e.g. as NTFS. Beware that formatting deletes all data on the drive.

6 Answers 6

This is due to FAT32 limitation. Files larger than 4GB cannot be stored on a FAT32 volume. Formatting the flash drive as exFAT or NTFS will resolve this issue.

WARNING: Back up your data. Formatting will delete all the data on your device.

Even though it is a Microsoft creation, there’s a lot to be said for exFAT. As others have noted it is handled by all three desktop OSs, therefore you will tend to maximize your interoperability. In addition it was designed for use on large flash drives. Citation: en.wikipedia.org/wiki/ExFAT In particular, because it can mark a file as contiguous, and thereby avoid having to touch the FAT, it works extremely efficiently in the OPs use case: handling a very large file.

If you don’t want to reformat your USB drive or need it to be FAT32 you can simply split your big file into parts. Most archive managers come with the split option and for the command line there’s split , e.g. for your case:

split -b4294967295 /path/to/input.file /path/to/pen/drive/output.file. 

See man split for the full documentation. This will create the following files:

4,0G output.file.aa 1,6G output.file.ab 

The filesize of output.file.aa matches exactly the maximum file size of your FAT32 formatted USB drive, which is 4 Gibibyte (GiB, that’s not the same as Gigabyte GB) minus 1 Byte.
Thanks to Gilles for this important addition.

Before you can access the file again you need to merge its parts first. On Linux systems you can do so with:

cat output.file.* > input.file 

If you’re afraid that this could sort the files incorrectly read In Bash, are wildcard expansions guaranteed to be in order?
The corresponding command on Windows systems is:

copy /b output.file.aa+output.file.ab input.file 

Along with many other useful GNU utilities split can be installed in Windows too, see GNU utilities for Win32.

I’d have upvoted for split even without the distinction between GiB and GB. But I’ll send an attaboy for that.

I upvoted because reformatting the drive just to be able to move one large file is a horrible answer when split exists precisely for this purpose and is not required on the receiving end. FAT32 is the lingua franca of USB drives for a reason.

I think -b 4095M would be far simpler and achieve the same as the bc command. In Bash one could also use shell arithmetic: $(((4<<30)-1)) .

Читайте также:  Linux and symbolic link

Problem: FAT32 has a 4GiB limit for file size

Different scenarios and files systems are examined looking for alternatives taking into account

Linux only

If you intend to use the drive only with Ubuntu (and other linux distros), it is a good idea to use a linux file system, for example ext4. This way you might get higher read/write speed (depending on which process is the bottleneck), and you will get higher flexibility concerning ownership and permissions.

  • You can use the GUI program gparted to create the ext4 file system.

Full compatibility with Linux, Windows and MacOS

Windows has problems with linux file systems, and I think MacOS has problems both with linux file systems and NTFS. So if you want ‘full compatibility’ for reading and writing, only FAT32, UDF and exFAT remain.

  • FAT32 has a 4GiB (gibibyte, base 2) limit for file size.
  • Can be created in all three operating systems.
  • Maintain (repair) in Windows, if you have access to Windows.
  • Can be maintained in Ubuntu with dosfsck , that comes with the package dosfstools ,
 sudo apt-get install dosfstools sudo dosfsck -a /dev/sdxn # least destructive option sudo dosfsck -r /dev/sdxn # more powerful option 

More about exFAT

Edit August 2021:

Since this answer was written, the support for exFAT is bundled in the new versions of standard Ubuntu, so you need no extra packages to run it.

end of edit

I have started to test exFAT in Ubuntu. I intend to edit this answer, when I have more experience of using it. Let us start with the following links,

ExFAT is a proprietary file system of Microsoft optimized for

> embedded systems because it is lightweight and is better suited for > solutions that have low memory and low power requirements, and can be > implemented in firmware. 

and this command line to install [read/write] support for exFAT in Ubuntu

sudo apt-get install exfat-utils exfat-fuse 
 sudo mkfs.exfat -n YOUR-LABEL /dev/sdxi 

where x is the drive letter and i is the partition number, for example /dev/sdb1 .

My first test results:

  • Creating the exFAT file system worked well in Ubuntu (16.04 LTS (64-bit), installed system with the Xenial kernel series (4.4.0-93-generic), up to date).
  • Writing and reading a file greater than 4 GiB were successful. Ubuntu and exFAT co-operated correctly and fast (I checked with md5sum and the speed was limited by the USB system).
  • Ubuntu and Windows could read what was created in the other operating system. (I have no MacOS for testing, and have to rely on the reports from other people.)

Windows

So if you want full read/write access from Ubuntu and Windows, I would suggest that you use NTFS, which has journaling and is very debugged and polished as the [proprietary] file system for Windows. (It is also possible to use exFAT.)

  • In Ubuntu you can use the GUI program gparted to create an NTFS file system.
  • In Windows it is easy to create NTFS and exFAT file systems (they are native).
  • UDF probably lacks tools to repair the file system,
  • FOSS
  • Maybe it is possible to find repair tools in Windows via this link: fsck tools for UDF, and there is some tool available as source code
  • Can be created in Ubuntu
  • Compatible with linux style links.
  • Compatible with linux style permissions. You can create and modify permissions of individual files (which is not possible with FAT and NTFS).
  • A UDF partition will not be prompted for formatting by Windows 10 (while the linux ext4 file system is affected, and can be destroyed by mistake).
  • How to create and use UDF: Using the UDF as a successor of FAT for USB sticks So, to use it, assuming your USB stick is /dev/sdx :
 sudo apt-get install udftools 
 sudo dd if=/dev/zero of=/dev/sdx1 bs=1M count=1 
 sudo mkudffs -b 512 --media-type=hd --lvid=my-label /dev/sdx1 

MacOS

Edit August 2021: HFS+ (journaled)

Since this answer was written, I discovered that Linux can read and write HFS+ (journaled), so use Disk Utility.app on your Mac to format the partition with HFS+ (journaled) in order to have a drive (for example an external drive) that can transfer or share data between Ubuntu and MacOS.

end of edit

In MacOS it is possible to use FAT32 and exFAT.

You can also use ext4 with a workaround, Ubuntu Server with an SSH server in a virtual machine. (I think the same workaround would work also with Windows.) This may be worthwhile when you intend to access a lot of files via the drive and its file system, but probably not with a small USB2 pendrive.

Источник

Copying files to a USB drive [closed]

This question was closed because it is not about an official Ubuntu flavor. It is not currently accepting answers.

This is not about an official Ubuntu flavor. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow.

Currently, i am trying to copy a directory with files that contain my works website from a Gentoo server to a USB drive. Ive combed through many pages of you youtube and google and cannot seem to get it to copy. Im sure there is something im dong wrong here, anyone have any ideas? cp -r /opt/biweb/app/ /data/dev/sdb1/ Edit: mount points

df-h Filesystem Size Used Avail Use% Mounted on /dev/sda3 31G 31G 0 100% / /dev/sda1 84m 9.5m 70m 12% /boot /dev/sdb1 68g 42g 23g 66% /data 

What happens when you run cp -r /opt/biweb/app/ /data/dev/sdb1/ and what exactly do you want to happen? Did you encounter any warning or error messages? Please reproduce them in their entirety in your question. You can select, copy and paste terminal content and most dialogue messages in Ubuntu. (see How do I ask a good question?)

2 Answers 2

Don’t forget the asterix (*)! The above command will copy everything in the /app folder into the /sdb1 folder.

If you want to copy the app folder itself into the destination, then do:

The above has no trailing slash after «app». This will copy the app folder as well as its contents.

Thanks for the help, but unfortunately neither option worked. I first got «specified destination directory does not exist». Second i got, «no such file or directory.»

Correct, it’s likely not /data/dev/sdb1/ but instead /dev/sdb1/ . I’ve edited my answer to reflect that.

The device description for the partition on the USB drive is

where x is the drive letter and n is the partition number, In your case it seems to be /dev/sdb1 . But you should not write directly to the device. Instead you should mount it and write to the file system at the mountpoint. First you should create a mountpoint, or use one that already exists. Text after # is a comment (not used as a command).

sudo mkdir /mnt/sdn # only the first time sudo mount /dev/sdxn /mnt/sdn 
sudo mkdir /mnt/sd1 sudo mount /dev/sdb1 /mnt/sd1 

You may want to make sure that you are allowed to write to the USB pendrive from a regular user by the following method,

sudo mkdir -p /mnt/sd1 # only if you want a new mountpoint sudo umount /dev/sdxn # general: only if already mounted (with bad permissions). sudo umount /dev/sdb1 # example sudo mount -o rw,users,umask=000 /dev/sdxn /mnt/sd1 # general: mount sudo mount -o rw,users,umask=000 /dev/sdb1 /mnt/sd1 # example ls -ld /mnt/sd1 # check permissions sudo bash -c "echo 'Hello World' > /mnt/sd1/hello.txt" # test writing with sudo cat /mnt/sd1/hello.txt # test reading (as user) ls -l /mnt/sd1 # check permissions of the content rm /mnt/sd1/hello.txt # test removing (as user) echo 'I am a user' > /mnt/sd1/user.txt # test writing (as user) 

Edit 1: Sometimes (I would even say often) the partition on the USB drive will be mounted automatically. You will find it with the following commands,

df -h sudo lsblk -f sudo lsblk -m 

The automatic mounting may or may not make it read-write for the regular user, but it will usually be possible to write with superuser privileges, with sudo .

You can inspect how it is mounted with the command

but it will display a lot of information (about everything that is mounted).

Edit 2: copying command

After finding out that the pendrive is automatically mounted on /data , the following command line should work, if [the partition in] the USB drive is mounted read/write and with permissions for your regular user ID.

It should create a directory /data/app on the USB drive with the content (the directory tree and the files). If it does not work, you can try the special mounting method, that I showed above, but modified for the current mountpoint,

sudo umount /data # unmount sudo mount -o rw,users,umask=000 /dev/sdb1 /data # mount with 'full' permissions 

Edit 3: Please edit your original question, where you can use formatting tools.

Источник

Оцените статью
Adblock
detector