Make USB key writable

Home Page Forums Network Management ZeroShell Make USB key writable

This topic contains 1 reply, has 0 voices, and was last updated by  on 8 years, 1 month ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #43004

    on
    Member

    Hi,

    I wanted a version of ZeroShell that would be more open to modifications, so basically, how to change the partition 2 to be ext2 instead of iso9660, so it can be mounted read-write.

    I got inspiration from http://www.zeroshell.net/eng/forum/viewtopic.php?t=1911 but parts in it were not that straight forward to me, so after testing I propose my own, maybe more detailed, recipe.

    1) I get ZeroShell fully working on a USB key. Mine is 4GB, so I will take this opportunity to make the partitions biggers.

    2) I also get a hard disk attached to ZeroShell machine, with some partition on the disk.

    3) On that disk, I will also get a copy of ps_initrd.sh script (http://www.nigilist.ru/nit/ps_initrd.sh/).

    4) I boot a live CD Linux on that machine. I used Hiren, but it could be Ubuntu live CD, or any other.

    5) Mount the hard disk:

    mount /dev/sda1 /mnt

    Depending on what live CD you use, the hard disk appears before or after the USB key. In my case (Hiren) the disk appears as /dev/sda and the USB key as /dev/sdb.

    6) Create another mount directory:

    mkdir /mnt2

    7) Back-up everything from the USB key.

    dd if=/dev/sdb1 of=/mnt/part1.dd
    mount /dev/sdb1 /mnt2
    cd /mnt2
    tar cf /mnt/part1.tar .
    cd /
    umount /mnt2

    This will make 2 copies of /dev/sdb1 (the first partition of the USB key), one in dd format and the other in tar format. You should need only the tar format, but who knows.

    8) Repeat the step 7) for /dev/sdb2 and /dev/sdb3

    9) Re-partition the USB key: my choice is that the first partition should use the first 512K, the second partition is to use from 512K to 2M, and the third partition is using the 2M at the end of the USB key.
    In fact, I kept the first partition unchanged.

    fdisk /dev/sdb

    Remember my USB key is /dev/sdb.
    Then use what is necessary to delete partition 2 and 3 and recreate them.

    Be carefull You must not toggle the DOS mode in fdisk!

    10) Re-build the file systems in partitions 2 and 3:

    mkfs -t ext2 /dev/sdb2
    mkfs -t ext2 /dev/sdb3

    11) Restore the 2nd partition:

    mount /dev/sdb2 /mnt2
    cd /mnt2
    tar xfBp /mnt/part2.tar
    cd /
    umount /mnt2

    12) Repeat the step 11) with the partition /dev/sdb3.

    13) Now the tricky part, partition /dev/sdb2 has changed from iso9660 type to ext2, this must be reflected in some places.

    cd /mnt
    mkdir part1
    cd part1
    tar xf ../part1.tar
    /mnt/ps_initrd.sh initrd.gz open
    cd initrd.gz-image

    14) Edit the file /mnt/part1/initrd.gz-image/linuxrc. Change the line:

    if mount -t iso9660 /dev/sd${N}2 /cdrom  2>/dev/null ; then

    and replace iso9660 with ext2. The new line is:

    if mount -t ext2 /dev/sd${N}2 /cdrom  2>/dev/null ; then

    15) Finish that part and replace the original initrd.gz in the partition /dev/sdb1

    cd /mnt/part1
    /mnt/ps_initrd.sh initrd.gz close
    mount /dev/sdb1 /mnt2
    cp /mnt/part1/initrd.gz /mnt2
    umount /mnt2

    16) One more file to modify, it’s in partition 2, in /etc/fstab.

    cd /mnt
    mkdir part2
    cd part2
    tar xf ../part2.tar
    cd isolinux
    /mnt/ps_initrd.sh rootfs open
    cd rootfs-image

    17) Edit the file /mnt/part2/isolinux/rootfs-image/etc/fstab. Change the line:

    /dev/cdrom              /cdrom              iso9660 ro 0 0

    and replace iso9660 with ext2, and read-only with defaults. The new line is:

    /dev/cdrom              /cdrom              ext0 defaults 0 0

    18) Finish that part and replace the original rootfs in the partition /dev/sdb2

    cd /mnt/part2/isolinux
    /mnt/ps_initrd.sh rootfs close
    mount /dev/sdb2 /mnt2
    cp /mnt/part2/isolinux/rootfs /mnt2/isolinux
    umount /mnt2

    19) At that stage you should be able to reboot ZeroShell from your USB key. If something fail, restart a clean installation of ZeroSheel on your USB key 🙂

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.