In our previous post “using a file as a storage device” adrian asked a question to us : is it possible to extend the size on the ‘filename’ file? We searched on it and figured out the answer. Let’s roll 🙂
Lets say you create a file name /newfile of size 200MB and format it, after a while you want to extend the file size. To do that do the following
Step 1. Lets say you want to increase the file size by 100MB
dd oflag=append conv=notrunc if=/dev/zero of=/newfile bs=1MB count=100
Now, the file is 100MB larger.
Step 2. Run file system check on the file
fsck -f /newfile
Step 3. Now if you formatted the file system in ext2,3 or 4, you can resize it by using
resize2fs /newfile.
If you are unable to understand this post fully , please visit using file as a storage device first and check out the comments too . Thanks to adrian for comment 🙂
Its possible to increase size more fast?
Yes, there is. You could just create a sparse file.
dd if=/dev/zero of=/newfilefile bs=1 count=0 seek=200M
After that run fsck and resize2fs.
This method is good. But I think it would be safer to goto :
1.Run level 1
2. Unmount the partition
3. Increase the file size by ‘fsadm’
4. Run file system check
5. Then mount the partition.
By this I think the data would be safe.
Excellent post thanks for sharing. Extending the size of a storage file has numerous benefits.
I use an image file and encrypt its contents with cryptsetup. The commands to mount it are:
losetup /dev/loop3 /home/public/image.file
cryptsetup -c aes -h ripemd160 -s 256 create ataday /dev/loop3
mount -t ext3 /dev/mapper/ataday /home/norman
Is it possible to extend the file /home/public/image.file with dd fsck and resize2fs as you indicate above and still have it work with cryptsetup?
I tried to find out a way to do just that, so far no success. If anyone know how to, please post.
I will let you know if i find a solution Leon
thanks man! keep up the good work 🙂