How do I resize a Linux filesystem data .bin file?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
6
down vote

favorite
1












I have a 2 MB file: root.bin, that is a Linux rev 1.0 ext2 filesystem, and I would like to expand it so that I can put more files in it, but it does not just resize like I thought it would. How do I resize it, preferably keeping the files on it, to a specific size?







share|improve this question






















  • Is your specific confusion that you have increased the size of the file, but the filesystem it contains doesn't seem to have changed to match?
    – Carcer
    Sep 2 at 14:22














up vote
6
down vote

favorite
1












I have a 2 MB file: root.bin, that is a Linux rev 1.0 ext2 filesystem, and I would like to expand it so that I can put more files in it, but it does not just resize like I thought it would. How do I resize it, preferably keeping the files on it, to a specific size?







share|improve this question






















  • Is your specific confusion that you have increased the size of the file, but the filesystem it contains doesn't seem to have changed to match?
    – Carcer
    Sep 2 at 14:22












up vote
6
down vote

favorite
1









up vote
6
down vote

favorite
1






1





I have a 2 MB file: root.bin, that is a Linux rev 1.0 ext2 filesystem, and I would like to expand it so that I can put more files in it, but it does not just resize like I thought it would. How do I resize it, preferably keeping the files on it, to a specific size?







share|improve this question














I have a 2 MB file: root.bin, that is a Linux rev 1.0 ext2 filesystem, and I would like to expand it so that I can put more files in it, but it does not just resize like I thought it would. How do I resize it, preferably keeping the files on it, to a specific size?









share|improve this question













share|improve this question




share|improve this question








edited Sep 2 at 8:54









Ravexina

27.3k146594




27.3k146594










asked Sep 2 at 7:51









Noah Cain

333




333











  • Is your specific confusion that you have increased the size of the file, but the filesystem it contains doesn't seem to have changed to match?
    – Carcer
    Sep 2 at 14:22
















  • Is your specific confusion that you have increased the size of the file, but the filesystem it contains doesn't seem to have changed to match?
    – Carcer
    Sep 2 at 14:22















Is your specific confusion that you have increased the size of the file, but the filesystem it contains doesn't seem to have changed to match?
– Carcer
Sep 2 at 14:22




Is your specific confusion that you have increased the size of the file, but the filesystem it contains doesn't seem to have changed to match?
– Carcer
Sep 2 at 14:22










1 Answer
1






active

oldest

votes

















up vote
10
down vote



accepted










We will try to make your two MB root.bin file to a 12 MB to demonstrate the steps.




Create a copy of your file (just in case for backup purpose):



cp root.bin 12mb.bin


Run this command to add 10M to the file size:



dd if=/dev/zero of=12mb.bin bs=1MiB count=10 conv=notrunc oflag=append


Now 12mb.bin is not 2M any more, actually its size is 12M.



Run:



e2fsck -f 12mb.bin


to check the filesystem on the file, then run:



resize2fs 12mb.bin


Done. mount it somewhere:



sudo mount 12mb.bin /mnt


check the size:



df -h --output=size /mnt/
Size
12M


And the existence of files:



ls /mnt



We can also use losetup to act with the file like a block device:



sudo losetup -f 12mb.bin


then:



sudo losetup -l | grep -i "12mb.bin" | awk 'print $1'
/dev/loop0


and we can resize /dev/loop0.






share|improve this answer






















  • The dd command doesn't overwrite the original contents
    – George Udosen
    Sep 2 at 8:57






  • 1




    @GeorgeUdosen No it does not. we are using notrunc and append. and it shouldn't right?
    – Ravexina
    Sep 2 at 8:57











  • Your right sorry I am accessing from mobile didn't see those options almost thought you were using some esoteric code. Always nice to follow your answer always a teaching moment for me
    – George Udosen
    Sep 2 at 9:01










  • Thanks, that's very nice of you :)
    – Ravexina
    Sep 2 at 9:19






  • 1




    Rather than using dd to expand the file, why not just use truncate?
    – Carcer
    Sep 2 at 14:19











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1071308%2fhow-do-i-resize-a-linux-filesystem-data-bin-file%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
10
down vote



accepted










We will try to make your two MB root.bin file to a 12 MB to demonstrate the steps.




Create a copy of your file (just in case for backup purpose):



cp root.bin 12mb.bin


Run this command to add 10M to the file size:



dd if=/dev/zero of=12mb.bin bs=1MiB count=10 conv=notrunc oflag=append


Now 12mb.bin is not 2M any more, actually its size is 12M.



Run:



e2fsck -f 12mb.bin


to check the filesystem on the file, then run:



resize2fs 12mb.bin


Done. mount it somewhere:



sudo mount 12mb.bin /mnt


check the size:



df -h --output=size /mnt/
Size
12M


And the existence of files:



ls /mnt



We can also use losetup to act with the file like a block device:



sudo losetup -f 12mb.bin


then:



sudo losetup -l | grep -i "12mb.bin" | awk 'print $1'
/dev/loop0


and we can resize /dev/loop0.






share|improve this answer






















  • The dd command doesn't overwrite the original contents
    – George Udosen
    Sep 2 at 8:57






  • 1




    @GeorgeUdosen No it does not. we are using notrunc and append. and it shouldn't right?
    – Ravexina
    Sep 2 at 8:57











  • Your right sorry I am accessing from mobile didn't see those options almost thought you were using some esoteric code. Always nice to follow your answer always a teaching moment for me
    – George Udosen
    Sep 2 at 9:01










  • Thanks, that's very nice of you :)
    – Ravexina
    Sep 2 at 9:19






  • 1




    Rather than using dd to expand the file, why not just use truncate?
    – Carcer
    Sep 2 at 14:19















up vote
10
down vote



accepted










We will try to make your two MB root.bin file to a 12 MB to demonstrate the steps.




Create a copy of your file (just in case for backup purpose):



cp root.bin 12mb.bin


Run this command to add 10M to the file size:



dd if=/dev/zero of=12mb.bin bs=1MiB count=10 conv=notrunc oflag=append


Now 12mb.bin is not 2M any more, actually its size is 12M.



Run:



e2fsck -f 12mb.bin


to check the filesystem on the file, then run:



resize2fs 12mb.bin


Done. mount it somewhere:



sudo mount 12mb.bin /mnt


check the size:



df -h --output=size /mnt/
Size
12M


And the existence of files:



ls /mnt



We can also use losetup to act with the file like a block device:



sudo losetup -f 12mb.bin


then:



sudo losetup -l | grep -i "12mb.bin" | awk 'print $1'
/dev/loop0


and we can resize /dev/loop0.






share|improve this answer






















  • The dd command doesn't overwrite the original contents
    – George Udosen
    Sep 2 at 8:57






  • 1




    @GeorgeUdosen No it does not. we are using notrunc and append. and it shouldn't right?
    – Ravexina
    Sep 2 at 8:57











  • Your right sorry I am accessing from mobile didn't see those options almost thought you were using some esoteric code. Always nice to follow your answer always a teaching moment for me
    – George Udosen
    Sep 2 at 9:01










  • Thanks, that's very nice of you :)
    – Ravexina
    Sep 2 at 9:19






  • 1




    Rather than using dd to expand the file, why not just use truncate?
    – Carcer
    Sep 2 at 14:19













up vote
10
down vote



accepted







up vote
10
down vote



accepted






We will try to make your two MB root.bin file to a 12 MB to demonstrate the steps.




Create a copy of your file (just in case for backup purpose):



cp root.bin 12mb.bin


Run this command to add 10M to the file size:



dd if=/dev/zero of=12mb.bin bs=1MiB count=10 conv=notrunc oflag=append


Now 12mb.bin is not 2M any more, actually its size is 12M.



Run:



e2fsck -f 12mb.bin


to check the filesystem on the file, then run:



resize2fs 12mb.bin


Done. mount it somewhere:



sudo mount 12mb.bin /mnt


check the size:



df -h --output=size /mnt/
Size
12M


And the existence of files:



ls /mnt



We can also use losetup to act with the file like a block device:



sudo losetup -f 12mb.bin


then:



sudo losetup -l | grep -i "12mb.bin" | awk 'print $1'
/dev/loop0


and we can resize /dev/loop0.






share|improve this answer














We will try to make your two MB root.bin file to a 12 MB to demonstrate the steps.




Create a copy of your file (just in case for backup purpose):



cp root.bin 12mb.bin


Run this command to add 10M to the file size:



dd if=/dev/zero of=12mb.bin bs=1MiB count=10 conv=notrunc oflag=append


Now 12mb.bin is not 2M any more, actually its size is 12M.



Run:



e2fsck -f 12mb.bin


to check the filesystem on the file, then run:



resize2fs 12mb.bin


Done. mount it somewhere:



sudo mount 12mb.bin /mnt


check the size:



df -h --output=size /mnt/
Size
12M


And the existence of files:



ls /mnt



We can also use losetup to act with the file like a block device:



sudo losetup -f 12mb.bin


then:



sudo losetup -l | grep -i "12mb.bin" | awk 'print $1'
/dev/loop0


and we can resize /dev/loop0.







share|improve this answer














share|improve this answer



share|improve this answer








edited Sep 3 at 6:42

























answered Sep 2 at 8:45









Ravexina

27.3k146594




27.3k146594











  • The dd command doesn't overwrite the original contents
    – George Udosen
    Sep 2 at 8:57






  • 1




    @GeorgeUdosen No it does not. we are using notrunc and append. and it shouldn't right?
    – Ravexina
    Sep 2 at 8:57











  • Your right sorry I am accessing from mobile didn't see those options almost thought you were using some esoteric code. Always nice to follow your answer always a teaching moment for me
    – George Udosen
    Sep 2 at 9:01










  • Thanks, that's very nice of you :)
    – Ravexina
    Sep 2 at 9:19






  • 1




    Rather than using dd to expand the file, why not just use truncate?
    – Carcer
    Sep 2 at 14:19

















  • The dd command doesn't overwrite the original contents
    – George Udosen
    Sep 2 at 8:57






  • 1




    @GeorgeUdosen No it does not. we are using notrunc and append. and it shouldn't right?
    – Ravexina
    Sep 2 at 8:57











  • Your right sorry I am accessing from mobile didn't see those options almost thought you were using some esoteric code. Always nice to follow your answer always a teaching moment for me
    – George Udosen
    Sep 2 at 9:01










  • Thanks, that's very nice of you :)
    – Ravexina
    Sep 2 at 9:19






  • 1




    Rather than using dd to expand the file, why not just use truncate?
    – Carcer
    Sep 2 at 14:19
















The dd command doesn't overwrite the original contents
– George Udosen
Sep 2 at 8:57




The dd command doesn't overwrite the original contents
– George Udosen
Sep 2 at 8:57




1




1




@GeorgeUdosen No it does not. we are using notrunc and append. and it shouldn't right?
– Ravexina
Sep 2 at 8:57





@GeorgeUdosen No it does not. we are using notrunc and append. and it shouldn't right?
– Ravexina
Sep 2 at 8:57













Your right sorry I am accessing from mobile didn't see those options almost thought you were using some esoteric code. Always nice to follow your answer always a teaching moment for me
– George Udosen
Sep 2 at 9:01




Your right sorry I am accessing from mobile didn't see those options almost thought you were using some esoteric code. Always nice to follow your answer always a teaching moment for me
– George Udosen
Sep 2 at 9:01












Thanks, that's very nice of you :)
– Ravexina
Sep 2 at 9:19




Thanks, that's very nice of you :)
– Ravexina
Sep 2 at 9:19




1




1




Rather than using dd to expand the file, why not just use truncate?
– Carcer
Sep 2 at 14:19





Rather than using dd to expand the file, why not just use truncate?
– Carcer
Sep 2 at 14:19


















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1071308%2fhow-do-i-resize-a-linux-filesystem-data-bin-file%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

What does second last employer means? [closed]

List of Gilmore Girls characters

Confectionery