Sunday, October 8, 2017

linux - Used truncate to create huge file - df is not showing decrease in available space



I am trying to test a disk space monitor we have setup.
For that purpose, I ran truncate -s 125G /publish/data/bigFile which should claim enough space for the alert to be triggered.




However, df -h shows for that partition:
/dev/vdb1 196G 66G 121G 36% /publish/data
(which is to say, free space has not changed after running the truncate command.)



ls -lh on the file shows:
-rw-r--r-- 1 username users 126G Aug 7 11:27 /publish/data/bigFile



mount output for /publish/data:
/dev/vdb1 on /publish/data type ext4 (rw,relatime,data=ordered)




Edit: I also just realize, the numbers do not make sense:
196-66=130gb, so why df says 121gb free in the first place?


Answer



Can't see any documentation that supports it, but truncate must be creating a sparse file:



TEST
truncate -s 10G testfile



du testfile # shows the occupied size




   0  testfile


du -h --apparent-size # shows apparent size



   10G   testfile


From the du man page:





   --apparent-size
print apparent sizes, rather than disk usage;
although the apparent size is usually smaller, it
may be larger due to holes in ('sparse') files,
internal fragmentation, indirect blocks, and the
like




fallocate



Try using fallocate, it's very quick and does not create sparse files.



fallocate -l 125G filename

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...