Friday, February 20, 2015

Cerberus Alpha: Remastering the OS to Load the Program on Boot (Part 1)

Building a new iso for TinyCore was really easy enough, so the first thing I experimented with was adjusting boot behavior to what I wanted. The default option that I wanted was that Tiny Core would boot directly into a root command line interview. This is done using the boot code tinycore superuser. In ezremaster I made the mistake of entering only "superuser" instead of the whole phrase. With that fixed and the boot behavior working as desired, I set out to have the program run automatically. This proved quite the challenge.

When ezremaster creates the new OS for the .iso, it builds the actual folders that will go into the iso into a directory called "extract." Inside this is the actual system folders that will be extracted when the iso boots, such as /opt /etc and so on. What I did at first was to copy cerba.sh into the /extract/opt and modify bootlocal.sh with a line to start the script. Although later on I would need to start the script later in the boot process, this was not a problem yet. Modifying things this way caused the iso that was created to be "corrupt" and it would not boot at all.

Earlier in the project I had been able to modify the boot options by opening the iso and changing /boot/isolinux/isolinux,cfg, so I tried editing files inside the already built iso and rebuilding it with MagicISO. Specifically I went into /boot/core.gz/core.cpio where /opt is located. This idea didn't completely break the iso, but on boot I would get the errors "/boot/core.gz not found" (when core.gz was not named perfectly) or an error stating that there was a kernel panic.

After much searching I never found information on how to do what I wanted correctly. Fortunately, I eventually found the solution in ezremaster. In ezremaster there is an option to integrate backed up user data into the iso. Originally I didn't think this would work, but when I tried using this it did actually work. Here are the steps I had to follow to use this feature correctly to produce the iso with both the custom /opt data and :
Place cerba.sh in /opt of the running system
  • Edit /opt/bootlocal.sh to start /opt/cerba.sh (*)
  • In TinyCore's Control Panel, backup /opt/ as mydata.tgz somewhere
  • Use /mnt/sr0 (mounted CD) as base iso
  • Load mydata.tgz into ezremaster
  • Load extensions using "Extract TCZ in to initrd" option and "Run TCZ startup scripts in chroot now"
    • bash
    • nano
    • ncurses-utils
    • ntfs-3g (*)
  • Build the iso
* Later the correct place to boot from would be /etc/profile.d/cerba.sh and ntfs-3g was discovered to be needed

With all this work done, I finally had a working iso and it was correctly running cerba.sh from bootlocal.sh. Unfortunately, as it turns out, this was far too early in the boot sequence.

No comments:

Post a Comment