-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?

8
  • What is the filesystem? Commented Oct 5, 2023 at 2:59
  • @KamilMaciorowski its a normal centos /dev/vda3 Commented Oct 5, 2023 at 6:14
  • 1
    That still does not answer what filesystem is used. You can show that by running mount |grep vda3 Commented Oct 5, 2023 at 6:18
  • @GeraldSchneider it shows a lot of output, but btrfs is probably what you are asking? Commented Oct 5, 2023 at 6:39
  • You could just edit the output into your question, but yes, btrfs sounds reasonable. Commented Oct 5, 2023 at 6:39

1 Answer 1

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?

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

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.