located at http://wiki.osdev.org/Bootable_El-Torit ... RUB_Legacy
Currently this program only creates boot cd/dvds so you can use it to simple build your os to test on virtual machines like virtualbox quickly.
Later I am probably going to add functionality so you can create virtual HDD images , virtual floppies images , usb images ,...etc
Let me know how you like it by posting to this thread
Please let me know of any problems or ways you think it can improve the easy of use,..etc
Thanks and enjoy
Code: Select all
#!/bin/bash
# This is I simple bash script that will allow the OS developer
# To create bootable media ,floppy, cds ,dvds ,virtual HDD ,...etc with their OS kernel and other files/folders
# That the OS developer wants to create for testing on a virtual machine such as virtualPC ,
# boches , virtualbox , vmware ,...etc
#
# Copyright General Public (No Restrictions)
# This program is under the general public liciense so you can do whatever you want with it
# no restrictions
#
# written by motherbrain aka. blackbox
# warning the author takes no responsiblity for this script
# README FIRST BEFORE USING
###################################################################################################################################################
# Program Name is osbuild.sh
# you should name it this although any name will work inconsistences with some of the help menus or
# display messages would occur
# make sure to stay consistent name this file/code osbuild
# Also note: that this program must be set to executable using chmod or whatever less you choose to use for making a file executable
# run as either ./osbuild [options]...parameters or if not made executable bash osbuild [options]... parameters
# Remember bash must be installed to use this program obviously.
# TYPE osbuild --help to get help in useing
###################################################################################################################################################
if [ $1 == "--help" ]; then
echo ""
echo "osbuild is a simple bash script that allows you to make a bootable iso image with your kernel"
echo "**********************************************************************************"
echo "osbuild options are "
echo "--help to display this help menu"
echo "--purge isodir to remove the iso directory and iso file create by osbuild"
echo "or osbuild btitle kernel cdtitle kdir"
echo "where btitle = grub boot menu title (this is what is displayed on the boot menu list at boot time)"
echo "where kernel = the name of your kernel file"
echo "where cdtitle = the name of the bootable iso image"
echo "where kdir = the \"ABSOLUTE PATH\" of the directory where your kernel file exists"
echo "only forms of the osbuild command that works are"
echo "bash osbuild --help"
echo "bash osbuild --purge isodir"
echo "bash osbuild btitle kernel cdtitle kdir "
echo "if you do not have one of these forms then osbuild will not work"
echo ""
echo "please also note /usr/lib/grub/i386-pc/stage2_eltorito must exist on your machine"
echo "and genisoimage must be installed/in your PATH var"
echo "**********************************************************************************"
echo ""
exit
fi
# executed if you want to do a clean osbuild from scratch again
if [ $1 == "--purge" ]; then
if [ "$2" != "" ]; then
if [ -e $2 ]; then
rm -r "$2"
if [ -e "$2.iso" ]; then
rm -r "$2.iso"
fi
echo "purge completed"
exit
fi
echo "could not find the directory $2 so nothing had to be purged"
exit
fi
echo "nothing had to be purged"
exit
fi
#check to see if the depending genisoimage program is installed
if [ ! $(type -P genisoimage) > /dev/null ]; then
echo "you currently do not have genisoimage installed this script requires this to be installed"
echo "would you like to install it 1 for yes anything else for no"
read choice
if [ "$choice" == "1" ]; then
sudo apt-get install genisoimage
echo "genisoimage is installed now thank you"
else
echo "genisoimage won't be installed you will have to do it at a later time before you can use this program"
exit
fi
fi
#check to see that the depending file /usr/lib/grub/i386-pc/stage2_eltorito exists
if [ ! -e /usr/lib/grub/i386-pc/stage2_eltorito ]; then
echo
echo "*************************************************************************"
echo "you don't currently have file /usr/lib/grub/i386-pc/stage2_eltorito"
echo "you may need to install grub try \"sudo apt-get install grub\" first "
echo "If that doesn't work please google and find a copy of stage2_eltorito and places it in /usr/lib/grub/i386-pc/"
echo "if /usr/lib/grub/i386-pc/ does not exist to place stage2_eltorito in , then you will have to create it you will need to be sudo to do so"
echo "please do this first before using this program!"
echo "*************************************************************************"
echo ""
exit
fi
#add here any directories/files you want to copy to the new iso
if [ ! -e cdFoldersAndFiles ]; then
mkdir cdFoldersAndFiles
echo "cdFoldersAndFiles must have either been deleted or this is your first time running this program"
echo "Remember to copy all additional folders and files you want to include on the iso image into the cdFoldersAndFiles directory"
echo "This cdFoldersAndFiles directory is manual created for the programmer to add additional folders and files to the iso image if he needs to"
echo "Also note that this created folder is not deleted using purge or any other means meaning you have to manual delete it"
echo "With rm -r cdFoldersAndFiles but then again I am over killing this for an OS developer like yourselfs"
echo "The folder cdFoldersAndFiles itself is not copied to the iso image just whats contained in it"
echo "So if you ignore it or don't use it then their will be no additional stuff on the iso image other then the grub boot files and your kernel file"
echo -e "Press any Key to Continue after you are done copying files to cdFoldersAndFiles"
read tmp
echo ""
fi
#OS Build Variables
OS_BOOT_TITLE="$1"
OS_KERNEL_FILE="$2"
CD_DVD_TITLE="$3"
KERNEL_DIR="$4"
if [ "$OS_BOOT_TITLE" == "" -o "$OS_KERNEL_FILE" == "" -o "$CD_DVD_TITLE" == "" -o "$KERNEL_DIR" == "" ]; then
echo
echo "***********************************************************************************"
echo "must provide 4 parameters whitespaced delimited "
echo "first parameter is the boot title name on the grub menu list when booting your os"
echo "second parameter is the name of your kernel file"
echo "third parameter is the name of your cd/dvd iso"
echo "forth parameter is the absolute path of where your kernel is in"
echo "***********************************************************************************"
echo
exit
fi
#creating iso image structure
if [ ! -e $CD_DVD_TITLE ]; then
mkdir ./$CD_DVD_TITLE
mkdir ./$CD_DVD_TITLE/boot
mkdir ./$CD_DVD_TITLE/boot/grub
fi
if [ ! -e $CD_DVD_TITLE/boot ]; then
mkdir $CD_DVD_TITLE/boot
mkdir $CD_DVD_TITLE/boot/grub
fi
if [ ! -e $CD_DVD_TITLE/boot/grub ]; then
mkdir $CD_DVD_TITLE/boot/grub
fi
#write menu.lst file
if [ -e $CD_DVD_TITLE/boot/grub/menu.lst ]; then
rm -r $CD_DVD_TITLE/boot/grub/menu.lst
fi
#FOR BASH PROGRAMMERS OR HACKERS HERE IS WHERE YOU MAY WANT TO ADD MORE TO THE MENU.LST FILE
#THIS IS WHERE THE MENU.LST STUB FILE NEEDED FOR GRUB GETS CREATED AND BUILT
##########################################################################################################################
echo "default 0" >> $CD_DVD_TITLE/boot/grub/menu.lst
echo "#timeout 30" >> $CD_DVD_TITLE/boot/grub/menu.lst
echo "\n" >> $CD_DVD_TITLE/boot/grub/menu.lst
echo "#title Boot from hard disk" >> $CD_DVD_TITLE/boot/grub/menu.lst
echo "#chainloader (hd0)+1" >> $CD_DVD_TITLE/boot/grub/menu.lst
echo "title $OS_BOOT_TITLE" >> $CD_DVD_TITLE/boot/grub/menu.lst
echo "kernel /boot/$OS_KERNEL_FILE # Edit it to the filename of your kernel." >> $CD_DVD_TITLE/boot/grub/menu.lst
##########################################################################################################################
if [ ! -e $CD_DVD_TITLE/boot/grub/stage2_eltorito ]; then
cp /usr/lib/grub/i386-pc/stage2_eltorito $CD_DVD_TITLE/boot/grub/
fi
#add kernel to CD/DVD image
cp $KERNEL_DIR/$OS_KERNEL_FILE $CD_DVD_TITLE/boot/ > /dev/null
if [ $? != 0 ] ; then
echo -e "\e[00;31mUnable to copy your kernel to iso absolute directory $KERNEL_DIR does not exist or kernel file $OS_KERNEL_FILE is not in $KERNEL_DIR\e[00m"
echo -e "\e[00;31mPlease correct this before going any further and rerun this program\e[00m"
echo -e "\e[00;31mPlease Note: KERNEL_DIR must not contain any ending / and your kernel file must not begin with / \e[00m"
echo -e "\e[00;31mYou inputed for your KERNEL_DIR=$KERNEL_DIR and OS_KERNEL_FILE=$OS_KERNEL_FILE\e[00m"
echo -e "\e[00;31mcp $KERNEL_DIR/$OS_KERNEL_FILE $CD_DVD_TITLE/boot/ failed\e[00m"
echo -e "\e[00;31mFix this first and rerun the program\e[00m"
exit
fi
if [ "$(ls -A cdFoldersAndFiles)" ]; then
cp -r cdFoldersAndFiles/* -t "$CD_DVD_TITLE" > /dev/null
fi
#create bootable cd/dvd
genisoimage -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o "$CD_DVD_TITLE.iso" "$CD_DVD_TITLE"
echo -e "\e[01;32miso image is built and ready for testing!\e[00m"
echo -e "\e[01;32mGood Luck with your OS development\e[00m"
echo ""
echo -e "\e[01;32m \\ / \e[00m"
echo -e "\e[01;32m (000) \e[00m"
echo -e "\e[01;32m \\ / \e[00m"
echo -e "\e[01;32m U \e[00m"
echo -e "\e[01;32m / \\ \e[00m"
echo -e "\e[01;32m Alien Power :) \e[00m"
exit