-1

I am trying to create a file with hole using the truncate command. I read up in some posts and one of the answers in this post says to use truncate command. Filesystem used is btrfs. This is the command

$: truncate -s 16K holes

$: du holes $: 16 holes $: stat holes File: holes Size: 16384 Blocks: 32 IO Block: 4096 regular file

As can be seen, its allocating 16 blocks...my understanding was that it will allocate 0 blocks as mentioned that answer as well. Did I make a mistake in understanding what truncate is doing?

Kusalananda
  • 333,661

1 Answers1

1

I can't reproduce your findings:

$ ls -la
total 24
drwxrwxr-x   2 tink tink  4096 2023-10-06 05:45 .
drwxr-x--- 180 tink tink 20480 2023-10-06 05:30 ..
$ truncate -s 16K holes
$ du holes
0   holes
$ stat holes
  File: holes
  Size: 16384       Blocks: 0          IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 46402746    Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/  tink)   Gid: ( 1000/  tink)
Access: 2023-10-06 05:46:36.012153267 +1300
Modify: 2023-10-06 05:46:36.012153267 +1300
Change: 2023-10-06 05:46:36.012153267 +1300
 Birth: -
$ 

Are you sure you're using btrfs (which supposedly supports sparseness, I can't confirm as I'm on ext4) and not something like vfat?

tink
  • 6,765
  • yes I am using btrfs...I get this filesystem name when I run mount | grep vda3. Is there any other way to know? – Shivanshu Arora Oct 06 '23 at 03:04
  • Then I'm at a loss. Most likely unrelated, but what virtualisation platform are you running your centos under? – tink Oct 06 '23 at 17:09