This project is read-only.

How to make the iso bootable?

May 4, 2011 at 12:05 PM
Edited May 4, 2011 at 12:27 PM

Hi,

I am editing my existing bootcd.iso (which is bootable) and creating an new bootcd.iso with additional files programatically using DiscUtils classes.

But while booting with new bootcd.iso am not able to boot with the it. Any help to fix this problem is appreciated.

Thanks,

Praveen DS

May 4, 2011 at 6:52 PM

There are lot of things which can go wrong here.

which bootloader is used in iso file?

whats your code to create iso file?

May 5, 2011 at 4:39 AM

Am using the grub (our distro is SuSE linux).

Following is my piece of code: Here c:\\temp1 is the folder where my boot files and distro files are present...

         public static void PopulateFromFolder(CDBuilder builder, DirectoryInfo di, string basePath)
        {
            int lfc = 0;
            foreach (FileInfo file in di.GetFiles())
            {
                builder.AddFile(file.FullName.Substring(basePath.Length), file.FullName);
                lfc++;
            }
   
            foreach (DirectoryInfo dir in di.GetDirectories())
            {
                //builder.AddDirectory(dir.FullName.Substring(basePath.Length));
                PopulateFromFolder(builder, dir, basePath);
            }
           // rnc += lfc;
        }

        static void createNewISO()
        {
            CDBuilder builder = new CDBuilder();
            builder.UseJoliet = true;
            builder.VolumeIdentifier = "BOOTCD";
            builder.UpdateIsolinuxBootTable = true;
            DirectoryInfo di = new DirectoryInfo("C:\\temp1");

            PopulateFromFolder(builder, di, di.FullName);

            FileStream bw = new FileStream("C:\\Temp\\sample1.iso", FileMode.Create);
            Stream cdStream = builder.Build();
       
        //    builder.SetBootImage(cdStream, DiscUtils.Iso9660.BootDeviceEmulation.NoEmulation, 0);

            byte[] buffer = new byte[64 * 1024];
            int numBytes = buffer.Length; // cdStream.Read(buffer, 0, buffer.Length);
            while (numBytes != 0)
            {
                numBytes = cdStream.Read(buffer, 0, buffer.Length);
                bw.Write(buffer, 0, numBytes);
            }
            cdStream.Close();
            bw.Close();
           

           //builder.Build(@"C:\\Temp\\sample1.iso");
        }

May 5, 2011 at 5:29 PM

why are not you setting the bootimage file?

I have not tested but following should add the bootimage.

 FileStream   bootImage = File.Open("c:\\temp1\boot\i386\loader\isolinux.bin", FileMode.Open);

builder.SetBootImage( bootImage, DiscUtils.Iso9660.BootDeviceEmulation.NoEmulation, 0 );

 

May 9, 2011 at 5:48 AM

Thanks a lot.. That worked for me:)

Nov 24, 2014 at 10:16 AM
I have follow the above step to create a bootable disk and successfully created a bootable disk. But whenever i used the created bootable disk i get error :

Boot Failure. Reboot and select proper boot device.
Please help!!
Here is my code:
static void createNewISO(string dirloc,string ISOloc)
    {
        CDBuilder builder = new CDBuilder();
        builder.UseJoliet = true;
        builder.VolumeIdentifier = "BOOTCD";
        builder.UpdateIsolinuxBootTable = true;
        DirectoryInfo di = new DirectoryInfo(dirloc);

        PopulateFromFolder(builder, di, di.FullName);

        FileStream bw = new FileStream(ISOloc + ".iso", FileMode.Create);

        Stream cdStream = builder.Build();


        FileStream bootImage = File.Open(@"D:\Users\user_pc\Desktop\New folder\bootfix.bin", FileMode.Open);

        builder.SetBootImage(bootImage, DiscUtils.Iso9660.BootDeviceEmulation.NoEmulation, 0);
        bootImage.Close();
        byte[] buffer = new byte[64 * 1024];
        int numBytes = buffer.Length; // cdStream.Read(buffer, 0, buffer.Length);
        while (numBytes != 0)
        {
            numBytes = cdStream.Read(buffer, 0, buffer.Length);
            bw.Write(buffer, 0, numBytes);
        }
        cdStream.Close();
        bw.Close();

    }
Nov 24, 2014 at 11:54 AM
A couple of things I'd recommend...
  1. Put the call to builder.Build as the last thing before the loop doing cdStream.Read - right now, you're building the ISO before you set the boot image.
  2. Keep the bootImage stream open until you're done (so after the loop).
Ken
Nov 25, 2014 at 7:29 AM
Thanks for the reply.
I have tried whatever you suggested and getting error:

An exception of type 'System.OverflowException' occurred in DiscUtils.dll but was not handled in user code

Additional information: Arithmetic operation resulted in an overflow.