0

Is there a way to create a block device that is backed by a file that grows in size as the block device is written to?

I'm looking to use device mapper snapshots (ie: dmsetup create command that specifies snapshot as the type of item to create) and according to the documentation the snapshot needs to be stored on a block device. One way to create this block device is by using losetup to turn a file into a block device. However, that requires as fixed size file. I'm trying to figure out if there is any way to not need a fixed size file but instead have the file that backs the block device that backs the snapshot grow as the snapshot grows.

1 Answer 1

0

You can't do exactly what you want, but you can get yourself to a similar place by simply creating a very large backing file without actually allocating the disk space in advance.

For example, we can create a 1TB backing file like this:

truncate -s1T backingfile 

Look how big it is!

$ ls -lh backingfile -rw-r--r--. 1 lars lars 1.0T Sep 21 07:53 backingfile 

But it's not really consuming any disk space:

$ du -k backingfile 0 backingfile 

Configure this as a block device using losetup and use it as in your devicemapper configuration and disk space will only be consumed as it is written.

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.