Computer Help for the New and Veteran User for Linux

Bootable Partitions


  1. Partition Image: Recovery system on Bootable CD. How to edit it and make new ISO.

    Answer: Partition Image is a great way to Backup your System. The only problem I had is it did not include my favorite editor: Nano. Did not include Less so you could see files better that might be long. So if you used cat it would scroll all the way to the bottom. Hdparm did not work either (after got it working though, I must say it did not speed it up much). I also wanted to make a new folder with Help Files in it. Lot of times you forget how to use some commands and put some better vi and emacs help in there.

    Needless to say. I ran into trouble editing the iso and I won't go into all that, but had to learn some new tricks that haven't had to deal with before. Took me awhile to get my new iso to boot correctly. I will briefly mention the errors when they become relevent.

    First of all, say you do want to make some changes to Partition Image. If you want to add a new kernel I don't have that here, but what I do have will help you still to make the ISO. I put the process into 3 scripts that I tested. Works like a charm. The first thing you need to do if you want to edit it is Extract the iso. I had some trouble with the initrd.img. Could mount the iso with /dev/loop but that initrd.img would give me trouble for some reason. The only consistent way I could extract it was doing it from the CD. So I assume that you have burned the CD and just want to make changes to it. If not, then burn the CD first.

    This first script will take the mount the cdrom and cp the files to your home folder, then mount the initrd.img on the loop device and extract the initrd.img folders to another folder so you can modify it. Actually this wasn't the hardest part. The only hard part about this mounting the initrd.img to extract it. Just about any other way would tell me wrong fs type.

    Script to extract from CD and expand initrd.img. Modify to suit your needs. There are no checks in this script to see if your root, folders already exist,..

    #!/bin/bash
    # http://webpages.charter.net/decibelshelp
    # Had trouble mounting the image when I extracted it from the
    # iso so just combined all and get it from the burnt cd.
    # Extracted files and image from CD = extractediso in HOME folder.
    # Extracted initrd.img file = imageextracted in extractediso.
    # You need to be root probably.
    #
    HOME="/home/decibels" # base HOME to use. I used my HOME.
    EXTISO="extractediso" # easier to see where you have stuff.
    EXTIMG="imageextracted" # easier to see where you have stuff.
    CDROM="/mnt/cdrom" # your cdrom mount point
    #
    mount $CDROM
    cd $HOME
    mkdir $HOME/$EXTISO
    # copy the cdrom files
    cp -av $CDROM/* $HOME/$EXTISO
    cd $HOME/$EXTISO/isolinux
    # remove the initrd.img and get it to mount from cdrom.
    rm initrd.img
    mkdir image
    mkdir $EXTIMG
    gunzip -c $CDROM/isolinux/initrd.img > $HOME/$EXTISO/isolinux/initrd.img
    # mount initrd.img on loop dev
    mount initrd.img image -o loop
    # copy the folders from the expanded image
    cp -av image/* $EXTIMG
    umount image
    umount $CDROM
    rm -rf image
    # remove initrd.img so you don't get confused with new one later.
    rm initrd.img # will remake it later.
    echo
    echo "You now have a extracted iso in ~/extractediso and"
    echo "extracted initrd.img in ~/extractediso/isolinux/imageextracted"
    echo "Edit the extracted image how you want."
    echo "Then you can run the next script to recreate the initrd.img"
    echo

    Now you can edit the extracted initrd.img to suit your needs. After you have changed it to what you want run the next script to remake the initrd.img like it was before (well, maybe a little bigger). If you are going to do too much make sure you have enough memory. Partition Image runs in RAM, if it didn't you wouldn't be able to use it and also backup your system unless you had two CD Drives. Once it starts you can take the CD out and put in your Backups to reinstall your system. So it is important not to get crazy here and add lots of stuff.

    If you are wanting to include some small program that you think will be helpful you might want to make sure you have the library for it. Since I included Nano, Less and Hdparm also had to include the libraries they needed. They weren't on the PartImage initrd.img. So I used ldd command: example: ldd /usr/bin/nano that listed some libraries that it uses. Actually it listed 3 files like this:

    ldd /usr/bin/nano
          libncurses.so.5 => /lib/libncurses.so.5 (0x40025000)
          libc.so.6 => /lib/libc.so.6 (0x4006c000)
          /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

    In this instance and for Less & Hdparm they were the same libraries. Also, the files it listed above are just symlinks in this instance. So I copied them and the actual files they pointed to to the expanded initrd.img /lib folder. Your milage may differ based on what programs you want to include and updates to libraries in the future.

    #!/bin/bash
    # http://webpages.charter.net/decibelshelp
    # Recreated the modified initrd.img and put in /
    # Extracted files and image from CD = extractediso HOME
    # Extracted initrd.img file = imageextracted
    # You need to be root.
    #
    HOME="/home/decibels" # base HOME to use. I used my HOME.
    EXTISO="extractediso" # easier to see where you have stuff.
    EXTIMG="imageextracted" # easier to see where you have stuff.
    SIZE="60960" # change size if want, it will be smaller when done anyway.
                 # this is to make sure you have enough.
    #
    cd / # changing to Root
    mkdir disks # change name in Root tree to what you want.
    mkdir disks/isolinux
    mkdir initrd
    # create a new ext2 filesystem of initrd.img
    dd if=/dev/zero of=initrd.img bs=1k count=$SIZE
    mke2fs -i 1024 -b 1024 -m 5 -F -v initrd.img
    mount initrd.img initrd -t ext2 -o loop
    # copy the files to new image
    cp -av $HOME/$EXTISO/isolinux/$EXTIMG/* initrd
    umount initrd
    # gzip it up
    gzip --best initrd.img
    cp initrd.img.gz disks/isolinux/initrd.img
    rm initrd.img.gz
    rm -rf initrd
    echo
    echo " You now have a compressed initrd.img with your added stuff"
    echo " in the ROOT TREE in /disks/isolinux."
    echo " Don't forget to edit the isolinux.cfg file to add ramdisk_size= "
    echo " to the append line if need more ram before you run next script."
    echo

    Next need to go to the folder where the cdrom files were put, in this example ~/extractediso/isolinux folder and edit the ISOLINUX.CFG OR go to /disk/isolinux. I would get errors about: ' attempt to access beyond end of device,... want=49156 , limit=40960 ' until I added this. The stuff I added needed more RAM. So added ramdisk_size=60000 to the append line like below

    append initrd=initrd.img ramdisk_size=60000 load_ramdisk=1 prompt_ramdisk=0 rw root=/dev/ram vga=787

    If don't and make the iso anyway and get the 'beyond end of device' errors OR 'unable to open console', than redo and put that in there. You can test it with this once you have it working, put in enough that you can boot it. The command df -h /dev/ram will show the memory usage. The original CD shows 36M used, 39M size and 1.2M available. Then when you get yours booting correctly do the df command and see what size it has listed for yours. Then you can go back and enter that amount if you want to lower it. Mine showed size as 52M, so I lowered it to that.

    Finally need to put all the files in place in /disks in the ROOT Tree. Actually can do anywhere, think mkisofs has a few problems with recursive folders, but I have done it in other places not too embedded. Put them in the same places they are in the extractediso folder. Copy over everything but the extracted image of initrd.img. The initrd.img file is already in /disk/isolinux. Once you have those files in place you can run the last script to make the new ISO. Change the name in the script if you want.

    #!/bin/bash
    # http://webpages.charter.net/decibelshelp
    # Burn the iso. Added stuff to initrd.img you might
    # want to make sure you increase your ramdisk_size in
    # the append line of isolinux.cfg
    # Extracted files and image from CD = extractediso HOME
    # Extracted initrd.img file = imageextracted
    # You need to be root.
    #
    ## Don't forget to copy the other files from extractediso
    ## over to /disk. Copy all but the imageextracted folder.
    cd /disks
    # Left here for future reference incase change kernel.
    # would need to cd /disks/isolinux to do.
    #rdev vmlinuz /dev/fd0
    #rdev -r vmlinuz 49152
    #rdev -R vmlinuz 0
    #
    # make the new iso and put in root.
    mkisofs -o /partimage-0.6.2-bootcd-new.iso -b isolinux/isolinux.bin \
    -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
    -boot-info-table -J -R -V disks .
    #
    echo
    echo " You now have a partimage-0.6.2-bootcd-new.iso file in your"
    echo " ROOT Tree. You can burn it to CD."
    echo

    You can now use a CDBurner to burn it to CD. The ISO is already bootable so no need to configure the burner for making a eltorito bootable disk. It will burn bootable. Try out the CD when done and see if get any errors that stop you. If get any reread the tutorial. Mine worked great.




Decibels

Valid XHTML 1.0!