How do I resize a Linux filesystem data .bin file?
Clash Royale CLAN TAG#URR8PPP
up vote
6
down vote
favorite
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?
filesystem binary
add a comment |Â
up vote
6
down vote
favorite
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?
filesystem binary
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
add a comment |Â
up vote
6
down vote
favorite
up vote
6
down vote
favorite
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?
filesystem binary
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?
filesystem binary
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
add a comment |Â
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
add a comment |Â
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
.
Thedd
command doesn't overwrite the original contents
– George Udosen
Sep 2 at 8:57
1
@GeorgeUdosen No it does not. we are usingnotrunc
andappend
. 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 usingdd
to expand the file, why not just usetruncate
?
– Carcer
Sep 2 at 14:19
 |Â
show 3 more comments
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
.
Thedd
command doesn't overwrite the original contents
– George Udosen
Sep 2 at 8:57
1
@GeorgeUdosen No it does not. we are usingnotrunc
andappend
. 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 usingdd
to expand the file, why not just usetruncate
?
– Carcer
Sep 2 at 14:19
 |Â
show 3 more comments
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
.
Thedd
command doesn't overwrite the original contents
– George Udosen
Sep 2 at 8:57
1
@GeorgeUdosen No it does not. we are usingnotrunc
andappend
. 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 usingdd
to expand the file, why not just usetruncate
?
– Carcer
Sep 2 at 14:19
 |Â
show 3 more comments
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
.
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
.
edited Sep 3 at 6:42
answered Sep 2 at 8:45


Ravexina
27.3k146594
27.3k146594
Thedd
command doesn't overwrite the original contents
– George Udosen
Sep 2 at 8:57
1
@GeorgeUdosen No it does not. we are usingnotrunc
andappend
. 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 usingdd
to expand the file, why not just usetruncate
?
– Carcer
Sep 2 at 14:19
 |Â
show 3 more comments
Thedd
command doesn't overwrite the original contents
– George Udosen
Sep 2 at 8:57
1
@GeorgeUdosen No it does not. we are usingnotrunc
andappend
. 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 usingdd
to expand the file, why not just usetruncate
?
– 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
 |Â
show 3 more comments
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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