Sie sind auf Seite 1von 4

Converting ZeroShell 2GB disk image to a 1GB disk image with installation

I installed a 1GB DiskOnModule in my Neoware CA10 which I intend to use as my router. The
installation image for ZeroShell-2.0-RC2 requires a 2GB target. After trying a few different methods
to convert the image to 1GB I was successful in resizing the 3rd volume's file system and partition.
This kept the master boot record and grub intact with no changes to the starting locations of the
partitions.
Here the steps I took to successfully convert the image to a 1GB image.
Source Host: Your PC running Linux (I am using Fedora 17 but any modern Linux will work)
You will need netcat, fdisk, losetup, e2fsprogs and dd
Target Host: ZeroShell router (I boot this under Trinity Rescue but others will work)
You will need netcat and fdisk
1) Boot the target host using a network enabled rescue environment that includes fdisk and netcat.
I used my favorite Trinity Rescue 3.4 that I installed on a USB stick using the Unetbootin
utility. (Note: If you use Trinity converted to a USB stick you have to specify the root location
during boot, which is sda1)
I start up the SSH host under Trinity and then open a shell prompt from my source host which
makes the installation much more pleasant.
2) On the target host run fdisk to determine the specs on the disk. Under Trinity, my
DiskOnModule maps to /dev/hda
#fdisk/dev/hda
Welcometofdisk(utillinux2.21).
Changeswillremaininmemoryonly,untilyoudecidetowritethem.
Becarefulbeforeusingthewritecommand.
Command(mforhelp):p
Disk/dev/hda:1048MB,1048190976bytes
255heads,63sectors/track,127cylinders,total2047248sectors
Units=sectorsof1*512=512bytes
Sectorsize(logical/physical):512bytes/512bytes
I/Osize(minimum/optimal):512bytes/512bytes
Diskidentifier:0xcf5090fb
DeviceBootStartEndBlocksIdSystem
Command(mforhelp):q

The important information to extract is the maximum extent of 1048190976 bytes. Divide this
by 512 to get 'sectors' (2047248) and divide by 1024 to get blocks (1023624). We'll use these
values later, if your target device size is different, you will want to use those values instead.

3) On the source host. Decompress the ZeroShell 2GB image.


zcat\
<ZeroShell2.0.RC2IDEUSBSATADisk2GB.img.gz\
>ZeroShell2.0.RC2IDEUSBSATADisk2GB.img

4) Load the 2GB image under fdisk to analyze the partition layout.
#fdiskZeroShell2.0.RC2IDEUSBSATADisk2GB.img
Welcometofdisk(utillinux2.21.2).
Changeswillremaininmemoryonly,untilyoudecidetowritethem.
Becarefulbeforeusingthewritecommand.
Command(mforhelp):p
DiskZeroShell2.0.RC2...:2017MB,2017419264bytes
255heads,63sectors/track,245cylinders,total3940272sectors
Units=sectorsof1*512=512bytes
Sectorsize(logical/physical):512bytes/512bytes
I/Osize(minimum/optimal):512bytes/512bytes
Diskidentifier:0xcf5090fb
DeviceBootStartEndBlocksIdSystem
ZeroShell2.0.RC2...12048983734816383Linux
ZeroShell2.0.RC2...298374128718359440583Linux
ZeroShell2.0.RC2...312871843887183130000083Linux
Command(mforhelp):q

The partition we are interested in resizing is the third partition. The start and end values are
represented in 512 byte sectors. The Blocks are 1024 bytes each.
Our target device has a size a maximum extent of 2047247 sectors so we will need to reduce the of
the file system in partition 3 from ( 3887183 - 1287184 + 1) * 512 = 1331200000 bytes or
1300000k to ( 2047247 - 1287184 + 1) * 512 = 389152768 bytes or 380032k.
5) We can map the third partition in the image to a loop device that will allow us to resize the file
system. The offset of the 3rd partition is (1287184 * 512) = 659038208 bytes and it's maximum size
is (1300000 * 1024) = 1331200000 bytes so we use the command:
losetupo659038208sizelimit1331200000\
/dev/loop3ZeroShell2.0.RC2IDEUSBSATADisk2GB.img

6) We can use the tune2fs from e2fsprogs to show us the information about the file system on the
partition.
#tune2fsl/dev/loop3|grep'Block'
Blockcount:325000
Blocksize:4096

So our file system size is (325000 * 4096) / 1024 = 1300000k which is exactly the same as the
partition size. We will need to resize this to 380032k in order for it to fit on our target storage
device.
7) Resize the file system on the 3rd partition
#e2fsckf/dev/loop3
#resize2fs/dev/loop3380032k
#losetupd/dev/loop3

8) Now we resize the partition. It may be possible to modify the partition using other partition
tools. With fdisk it is easy enough to delete and recreate the partition.
#fdiskZeroShell2.0.RC2IDEUSBSATADisk2GB.img
Welcometofdisk(utillinux2.21.2).
Changeswillremaininmemoryonly,untilyoudecidetowritethem.
Becarefulbeforeusingthewritecommand.
Command(mforhelp):d
Partitionnumber(14):3
Partition3isdeleted
Command(mforhelp):n
Partitiontype:
pprimary(2primary,0extended,2free)
eextended
Select(defaultp):p
Partitionnumber(14,default3):3
Firstsector(12871843940271,default1287184):1287184
Lastsector,+size{K,M,G}(12871843940271,default3940271):+380032K
Partition3oftypeLinuxandofsize371.1MiBisset
Command(mforhelp):w
Thepartitiontablehasbeenaltered!
Syncingdisks.

9) Now that we have resized the file system and the partition, we can resize the overall image
using dd.
ddif=ZeroShell2.0.RC2IDEUSBSATADisk2GB.img\
of=ZeroShell2.0.RC2IDEUSBSATADisk1GB.img\
bs=1024count=1023624

10) At this point it might be a good idea to re-map our new partition to a loop device and run a file
system check to make sure we did everything right. We use the old offset with our new sizelimit.
#losetupo659038208sizelimit389152768\
/dev/loop3ZeroShell2.0.RC2IDEUSBSATADisk1GB.img
#e2fsck/dev/loop3

If you've done all the math right for your target device, the result should return clean.
#losetupd/dev/loop3

11) Now we are ready to install our new image on the device. Remember Trinity maps my
DiskOnModule to /dev/hda
On the target we do:
nclp19000|bzip2d|ddof=/dev/hdabs=1024count=1023624

The on the source we do:


ddif=ZeroShell2.0.RC2IDEUSBSATADisk1GB.img\
bs=1024count=1023624|\
bzip2|\
nc{ip}19000

Where {ip} is the IP address of the target machine. Use ifconfig if you don't know what it is.
Notes:

If your source machines CPU isn't very powerful you might want to eliminate the bzip
commands from both sides.

Run the target command before the source command

There won't be any output.


12) After the command completes on the target you can reboot and ZeroShell should load.

Das könnte Ihnen auch gefallen