WDTV Optware tips #1 – resizing opt.bin *updated*

Back in my post about Optware for the WDTV, I mentioned how I had limited opt.bin to 128MB and made a comment hinting about being able to resize it if you need. Well I was called out [sasa ; )] so heres the easy steps to resize your opt.bin to whatever you’d like. 128MB really isn’t that much after all.

Note: this will require either access to a Linux computer, cygwin shell with ext2fs tools, or if you have time and patience it can be executed straight on the WDTV using Zoranders ext3-boot. It will take a long time on the WDTV though.



Fire up whatever shell you’re going to use and navigate to the location of opt.bin. Lets check out how much space I have left.

$ cd /wdtv
$ mkdir optMount
$ mount -o loop opt.bin optMount
$ df ./opt
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/loop3 126931 111483 8895 93% /wdtv/opt
$ umount optMount

: O Gettin pretty tight! We need to extend this filesystem and give a lot more room to grow, but how to make the opt.bin file itself larger? There are two possible methods, copying to a new file with padding or expanding the file in place.

Method 1: copying
First we’ll create a new file that consists of our original opt.bin with a lot of zeroes appended to the end. I want my new opt.bin to be 512MB.

$ dd if=/dev/zero of=zeroes bs=1024k count=384
384+0 records in
384+0 records out
402653184 bytes (403 MB) copied, 10.6317 s, 37.9 MB/s

This creates the padding, 384MB, since opt.bin comes stock as 128MB. If you’d like something other than 512MB, then change 384 above to whatever you wish. Now to create the new image.

$ cat opt.bin zeroes > bigger.opt.bin
$ ls -la opt.bin bigger.opt.bin zeroes
-rw-r--r-- 1 b-rad b-rad 536870912 2009-03-09 17:12 bigger.opt.bin
-rw-r--r-- 1 b-rad b-rad 134217728 2009-03-02 22:08 opt.bin
-rw-r--r-- 1 b-rad b-rad 402653184 2009-03-09 17:11 zeroes

This combines the two files into a new file. Perfect, so now we have a new bin that is 512MB. But is it really 512MB?

$ mount -o loop bigger.opt.bin optMount
$ df optMount
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/loop3 126931 111483 8895 93% /wdtv/optMount
$umount optMount

No Its not. Although the file containing the filesystem is 512MB, the filesystem still thinks its 128MB because it hasn’t been told otherwise. So let us resize it to fill up the maximum size opt.bin can hold, using resize2fs.

$ resize2fs bigger.opt.bin
resize2fs 1.41.3 (12-Oct-2008)
Please run 'e2fsck -f bigger.opt.bin' first.

resize2fs rightly asks you to force check the integrity of your target filesystem before you extend it, using e2fsck.

$ e2fsck -f bigger.opt.bin
e2fsck 1.41.3 (12-Oct-2008)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
/lost+found not found. Create<y>? yes

Pass 4: Checking reference counts
Pass 5: Checking group summary information

bigger.opt.bin: ***** FILE SYSTEM WAS MODIFIED *****
bigger.opt.bin: 1500/32768 files (0.3% non-contiguous), 23102/131072 blocks

$ resize2fs bigger.opt.bin
resize2fs 1.41.3 (12-Oct-2008)
Resizing the filesystem on newImage.bin to 524288 (1k) blocks.
The filesystem on newImage.bin is now 524288 blocks long.

Note above I answered yes when asked to create lost+found.

Does bigger.opt.bin contain a file system with 512MB of space yet?

$ mount -o loop bigger.opt.bin optMount
$ df optMount
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/loop3 507748 112243 369293 24% /wdtv/optMount
$ umount optMount

: D Yes it does.

$ mv opt.bin opt.bin.small
$ mv bigger.opt.bin opt.bin
$ rm zeroes



Method 2: expanding opt.bin in place

This is a slightly more advanced method of expanding opt.bin, which accomplishes the same thing without any extra files.

$ cd /wdtv
$ ls -la opt.bin
-rw-r--r-- 1 b-rad b-rad 134217728 2009-03-02 22:08 opt.bin

This opt.bin starts out at 128MB like the one above. Now we’ll use dd again, but this time in append mode. This means that the zeroes will be added to the end of opt.bin.

NOTE: if something goes wrong here it could be bad, so make a backup copy first if you desire.

# dd if=/dev/zero of=opt.bin bs=1024k count=384 \
oflag=append conv=notrunc
384+0 records in
384+0 records out
402653184 bytes (403 MB) copied, 18.6361 s, 21.6 MB/s
$ ls -la opt.bin
-rw-r--r-- 1 b-rad b-rad 536870912 2009-03-12 17:05 opt.bin

Notice its the exact same size as using the first method, as it should be. Since we already know that the filesystem won’t realize its larger yet, we’ll do those steps right away.

$ e2fsck -f opt.bin
opt.bin: recovering journal
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
/lost+found not found. Create? yes


Pass 4: Checking reference counts
Pass 5: Checking group summary information


opt.bin: ***** FILE SYSTEM WAS MODIFIED *****

opt.bin: 1558/32768 files (7.8% non-contiguous), 24643/131072 blocks
$ resize2fs opt.bin
resize2fs 1.41.3 (12-Oct-2008)
Resizing the filesystem on opt.bin to 524288 (1k) blocks.
The filesystem on opt.bin is now 524288 blocks long.
$ mkdir optMount && mount -o loop opt.bin optMount && df optMount && umount optMount && rmdir optMount
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/loop6 507748 21261 460275 5% /wdtv/optMount

There you go, in place file system expansion. Just be extremely sure to umount opt.bin before doing these operations.

Now with two different methods of expansion I’ve covered all the bases, enjoy the new free space on your wdtv!


Sasa
March 13th, 2009 17:30

b-rad,

thanks a lot for writing this up! Worked perfectly.

-sasa

November 7th, 2009 13:02

after the listing of bigger.opt.bin, you mount in loop the file.

But i obtain this:
# mount -o loop bigger.opt.bin optMount
NTFS signature is missing.
Failed to mount ‘/dev/loop4′: Invalid argument
The device ‘/dev/loop4′ doesn’t seem to have a valid NTFS.
Maybe the wrong device is used? Or the whole disk instead of a
partition (e.g. /dev/sda, not /dev/sda1)? Or the other way around?

How to mount now !?

<<< edit: Did you check to see if it was mounted? You did not specify filesystem type so it went through all of them until it found the right one. –b-rad >>>

November 7th, 2009 13:12

Another problem: on your WDLXTV resize2fs is NOT installed and IS NOT on optware repository … where can I found this !?!?!?

<<< edit: Optware pckages are most often NOT a single binary. You’re looking for e2fsprogs, which contains all the similar binaries. –brad >>>

*Name
*Mail
Website
Comment