0

I attempted to write a file to an ext4 voulume on an external USB hard disk drive:

$ dd if=/dev/zero of=file bs=1M count=10 iflag=fullblock oflag=direct
dd: failed to open 'file': Invalid argument

Then I tried it without oflag=direct and it worked.

Then I tried to write a file using the original command to an ext4 volume on an internal solid state drive and it worked.

Why couldn't dd write to the HDD?

1
  • 1
    I believe oflag=direct is valid when the of= argument specifies a device, but not when it specifies a file. Files need to go through the filesystem layers because to userland processes files are entities that are accessed via filesystems rather then directly via the storage device. Commented May 26 at 17:14

1 Answer 1

3

Was the filesystem mounted with the journal=data mount option, either explicitly or by setting the default mount options for that filesystem with tune2fs -o journal_data?

(To check, the full set of mount options for that filesystem should be listed in its line in /proc/mounts, or you can inspect the filesystem with tune2fs -l /dev/sd<SOMETHING> | grep "Default mount options" )

If so, you might find this warning in dmesg output at filesystem mount time:

EXT4-fs: Warning: mounting with data=journal disables delayed allocation, dioread_nolock, O_DIRECT and fast_commit support!

Apparently a data I/O operation in an ext4 filesystem cannot be both direct and journalled at the same time.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.