import os import sys from dosdisk import DosDisk from grubshell import GrubShell from tempfile import mkstemp class GrubShellNetboot( GrubShell): """ see http://www.rrze.uni-erlangen.de/dienste/arbeiten-rechnen /linux/booten/grub.shtml """ exec_prefix= GrubShell.exec_prefix libdir= exec_prefix+os.sep+"lib" pkglibdir= libdir+os.sep+"grub" stage1 = pkglibdir+os.sep+"stage1" # stage2_netboot= pkglibdir+os.sep+"stage2.netboot" # Suse 9.2 stage2_netboot = "stage2.sis900" bootdir= "/boot" menu_lst = "menu.lst" ip_server = "10.0.2.3" ip_address = "10.0.2.5" ip_gateway = "10.0.2.1" ip_netmask = "255.255.255.0" # nd_kernel = "/kernel.80" # nd_initrd = "/initrd.80" nd_kernel = "/revoboot/test/vmlinuz" nd_initrd = "/revoboot/test/initrd" def __init__(self): self.disk = DosDisk() def boot_file(self,path): return self.bootdir+os.sep+ os.path.basename(path) def run(self, menu_lst = None, drive = None): self.make_menu_lst( menu_lst) if drive: self.disk= DosDisk( drive) self.disk.format() self.disk.mkdir(self.bootdir) user_menu_lst= self.menu_lst user_stage1= self.stage1 user_stage2= self.stage2_netboot boot_menu_lst= self.boot_file("menu.lst") boot_stage1= self.boot_file("stage1") boot_stage2= self.boot_file("stage2") self.disk.copy( user_menu_lst, boot_menu_lst) self.disk.copy( user_stage1, boot_stage1) self.disk.copy( user_stage2, boot_stage2) self.disk_floppy() device = self.disk.grubdevice() return self.run1([ "install"+ " "+device+boot_stage1+ " "+device+ " "+device+boot_stage2+ " "+device+boot_menu_lst ]) def disk_extra(self): pass def menu_local(self): return ("title Local" +"\n"+ "rootnoverify (0x80)" +"\n"+ "chainloader +1" +"\n"+ "boot" +"\n") def menu_network(self): return ("title Network" +"\n"+ ("ifconfig"+ " --server="+self.ip_server+ " --gateway="+self.ip_gateway+ " --mask="+self.ip_netmask+ " --address="+self.ip_address) +"\n"+ "root (nd)" +"\n"+ "kernel "+self.nd_kernel +"\n"+ "initrd "+self.nd_initrd +"\n"+ "boot" +"\n") def menu_floppy(self): return "" def disk_floppy(self): pass def make_menu_lst(self, menu_lst): if menu_lst is not None: self.menu_lst = menu_lst else: fd, self.menu_lst = mkstemp() os.write (fd, "timeout 30" +"\n"+ "default 0" +"\n"+ "fallback 1" +"\n"+ "\n"+ self.menu_local()+"\n"+ self.menu_network()+"\n"+ self.menu_floppy()+"\n") os.close(fd) class GrubShellNetbootFloppy(GrubShellNetboot): def __init__(self): GrubShellNetboot.__init__(self) self.fd_kernel = "/boot/vmlinuz" self.fd_initrd = "/boot/initrd" def menu_floppy(self): return ("title Floppy" +"\n"+ "root "+self.disk.grubdevice() +"\n"+ "kernel "+self.boot_file( self.fd_kernel) +"\n"+ "initrd "+self.boot_file( self.fd_initrd) +"\n"+ "boot" +"\n") def disk_floppy(self): # self.disk.copy( self.fd_kernel, self.boot_file( self.fd_kernel)) # self.disk.copy( self.fd_initrd, self.boot_file( self.fd_initrd)) pass if __name__ == "__main__": if len (sys.argv) > 1: GrubShellNetboot().run(sys.argv[1]) else: GrubShellNetboot().run() # print GrubError