OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Apr 18, 2024 4:37 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Simple os script for developing
PostPosted: Wed Mar 14, 2012 3:20 pm 
Offline
Member
Member
User avatar

Joined: Mon Nov 03, 2008 6:06 pm
Posts: 385
I just wrote a convenient bash script that anybody on a linux/unix based system my find useful you may want to add it to the eltorieto bootable cd/dvd tutorial for osdev
located at http://wiki.osdev.org/Bootable_El-Torito_CD_with_GRUB_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:
#!/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


Attachments:
File comment: For OS developers to easy their building process please rename from .txt to .sh
osbuild.txt [8.96 KiB]
Downloaded 42 times
Top
 Profile  
 
 Post subject: Re: Simple os script for developing
PostPosted: Wed Mar 14, 2012 3:43 pm 
Offline
Member
Member
User avatar

Joined: Mon Nov 03, 2008 6:06 pm
Posts: 385
I suppose your right but
Their are alot of ways to make this smaller
But I was trying to get it so anybody could use it and if they got an error then it would easily be fixable. By display messages (makeing it dummy proof)

In any case I figured I would share.
I see your script do that and a few extra things in alot less.

I am not so concerned about the size of my file though.
I think I will be putting in at the end away to not only build the images for the virtual machines but also run the virtual machine as well with the image as the last step.

Freeing up the user to have to setup the virtual machine or the virtual machine with the os image.

As well as providing a simple way to down load an emulator for each arch to test it for different archs

Provided of course you compile your kernel with a cross compiler for a specific arch.

Question curious won't grub have to be recompiled if you want to use grub for your bootloader for a specfic virtual machine that is not x86/64?

I would think so.
So I would also have to have a cross compiler as well as recompile grubs stage1,2, eltorito ,...etc for all the arch's

Correct me if I am wrong


Top
 Profile  
 
 Post subject: Re: Simple os script for developing
PostPosted: Wed Mar 14, 2012 4:40 pm 
Offline
Member
Member
User avatar

Joined: Thu Dec 21, 2006 7:42 pm
Posts: 1391
Location: Unknown. Momentum is pretty certain, however.
If they encounter an error they should be able to know/figure out how to fix it without the hand-holding of a useless script...especially the problems that this script checks for.

-JL

_________________
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io


Top
 Profile  
 
 Post subject: Re: Simple os script for developing
PostPosted: Wed Mar 14, 2012 6:35 pm 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 9:29 pm
Posts: 2426
Location: Canada
Ah, yes, yet another pointless shell script that incorrectly assumes bash is installed in /bin, if even at all.

What's the point of this? Surely the target audience can RTFM?

_________________
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.


Top
 Profile  
 
 Post subject: Re: Simple os script for developing
PostPosted: Wed Mar 14, 2012 8:52 pm 
Offline
Member
Member
User avatar

Joined: Thu Dec 21, 2006 3:03 am
Posts: 1029
Location: Hobart, Australia
Quote:
# This program is under the general public liciense so you can do whatever you want with it
# no restrictions


I'm sorry, what?! Those two lines are mutually exclusive. Even people who love the GPL would agree that it is full of restrictions.

_________________
My Personal Blog | My Software Company - Loop Foundry | My Github Page


Top
 Profile  
 
 Post subject: Re: Simple os script for developing
PostPosted: Wed Mar 14, 2012 10:22 pm 
Offline
Member
Member
User avatar

Joined: Mon Nov 03, 2008 6:06 pm
Posts: 385
Quote:
general public liciense


have to change that to public domain not gpl.
I was thinking one thing and writting another stupid me.
Anyway now that you guys made me look like a complete A-hole
I will with draw from this thread

:oops:


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot] and 283 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group