def on_Qemu_Boot_usb_Click(self, usb_disk): """ Main function to boot a selected USB disk. :param usb_disk: Path to usb disk. :return: """ qemu = self.check_qemu_exist() if qemu is None: print "QEMU does not exist.\nPlease install qemu package to avail this feature." QtGui.QMessageBox.information(self, 'No QEMU...', 'Please install qemu to avail this feature.') else: ram = self.qemu_usb_ram() if ram is None: QtGui.QMessageBox.information(self, 'No ram...', 'No ram selected.\n\nPlease choose any ram value and click Boot USB.') else: if platform.system() == "Windows": disk_number = self.get_physical_disk_number(usb_disk) parent_dir = os.getcwd() os.chdir(gen_fun.resource_path(os.path.join("tools", "qemu"))) try: print "Executing ==> " + qemu + " -L . -boot c -m " + ram + " -hda //./PhysicalDrive" + disk_number subprocess.Popen("qemu-system-x86_64.exe -L . -boot c -m " + ram + " -hda //./PhysicalDrive" + disk_number, shell=True) except: QtGui.QMessageBox.information(self, 'Error...', 'Error booting USB\n' 'Unable to start QEMU.') os.chdir(parent_dir) elif platform.system() == "Linux": try: admin.adminCmd([qemu, '-hda', usb_disk[:-1], '-m', ram, '-vga std'], gui=True) except: QtGui.QMessageBox.information(self, 'Error...', 'Error booting USB\n\nUnable to start QEMU.')
def install_default(self): """ Install default syslinux/extlinux (version 4) on selected USB disk. """ if config.iso_link: self.iso = ISO(config.iso_link) filesystem = self.usb.get_usb(config.usb_disk).filesystem mbr_bin = gen_fun.resource_path(os.path.join("tools", "mbr.bin")) config.status_text = "Installing default syslinux..." if filesystem == "ext2" or filesystem == "ext3" or filesystem == "ext4" or filesystem == "Btrfs" or filesystem == "ntfs": if platform.system() == "Linux": syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "extlinux4") if os.access(syslinux_path, os.X_OK) is False: subprocess.call('chmod +x ' + syslinux_path, shell=True) path = os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb") quoted_exe = "\"" + syslinux_path.replace('"', '\\"') + "\"" quoted_path = "\"" + path.replace('"', '\\"') + "\"" quoted_mbusb = "\"" + gen_fun.mbusb_dir().replace('"', '\\"') + "\"" if filesystem == "ntfs": ext_fix = [] else: ext_fix = ["&&", "chattr", "-i", quoted_path + "/ldlinux.sys"] long_cmd = ["mkdir", "-p", quoted_path, "&&", "chown", "--reference", quoted_mbusb, quoted_path, "&&", quoted_exe, "--install", quoted_path] + ext_fix + \ ["&&", "echo", "Default Extlinux install is success...", "&&", "dd", "bs=440", "count=1", "conv=notrunc", "\"if=" + mbr_bin + "\"", "of=" + config.usb_disk[:-1], "&&", "echo", "mbr install is success...", "&&"] + self.set_boot_flag_cmd() return admin.adminCmd(long_cmd) == 0 elif filesystem == "vfat" or filesystem == "FAT32": if platform.system() == "Linux": syslinux = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux4")) if os.access(syslinux, os.X_OK) is False: subprocess.call(['chmod', '+x', syslinux]) quoted_exe = "\"" + syslinux.replace('"', '\\"') + "\"" long_cmd = [quoted_exe, "-i", "-d", "multibootusb", config.usb_disk, "&&", "echo", "Default syslinux install is success...", "&&", "dd", "bs=440", "count=1", "conv=notrunc", "\"if=" + mbr_bin + "\"", "of=" + config.usb_disk[:-1], "&&", "echo", "mbr install is success...", "&&"] + self.set_boot_flag_cmd() return admin.adminCmd(long_cmd) == 0 elif platform.system() == "Windows": syslinux = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux4.exe")) if subprocess.call(syslinux + ' -maf -d multibootusb ' + config.usb_disk, shell=True) == 0: print "\nDefault syslinux install is success...\n" return True else: print "\nFailed to install default syslinux...\n" return False
def install_distro(self): """ Install syslinux/extlinux on distro isolinux directory. """ self.iso = ISO(config.iso_link) filesystem = self.usb.get_usb(config.usb_disk).filesystem config.status_text = "Installing distro specific syslinux..." if self.iso.isolinux_bin_exist() is not True: print "Distro does not use isolinux/syslinux for booting ISO." else: self.iso.iso_extract_file( os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir"), "isolinux.bin") self.iso.iso_extract_file( os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir"), "ISOLINUX.BIN") syslinux_version = self.iso.isolinux_version( self.iso.isolinux_bin_path( os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir"))) if config.distro == "generic" or config.distro == "alpine": install_dir = self.usb.get_usb(config.usb_disk).mount distro_syslinux_install_dir = os.path.join( install_dir, self.iso.isolinux_bin_dir().strip("/")).replace( self.usb.get_usb(config.usb_disk).mount, "") distro_sys_install_bs = os.path.join( install_dir, self.iso.isolinux_bin_dir().strip("/"), config.distro + '.bs') else: install_dir = os.path.join( self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename()) distro_syslinux_install_dir = os.path.join( install_dir, self.iso.isolinux_bin_dir().strip("/")).replace( self.usb.get_usb(config.usb_disk).mount, "") distro_sys_install_bs = os.path.join( install_dir, self.iso.isolinux_bin_dir().strip("/"), config.distro + '.bs') if filesystem == "vfat" or filesystem == "FAT32": if syslinux_version == str(3): if config.distro == "generic" and self.iso.isolinux_bin_dir( ) == "/": option = "" else: option = " -d " else: if config.distro == "generic" and self.iso.isolinux_bin_dir( ) == "/": option = " -i " else: option = " -i -d " print "distro_syslinux_install_dir is " + distro_syslinux_install_dir print "distro_sys_install_bs is " + distro_sys_install_bs if platform.system() == "Linux": syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux") + syslinux_version if os.access(syslinux_path, os.X_OK) is False: subprocess.call('chmod +x ' + syslinux_path, shell=True) == 0 quoted_exe = "\"" + syslinux_path.replace('"', '\\"') + "\"" quoted_install_dir = distro_syslinux_install_dir.replace( '"', '\\"') quoted_bs = "of=\"" + distro_sys_install_bs.replace( '"', '\\"') + "\"" long_cmd = [ quoted_exe, option, quoted_install_dir, config.usb_disk, "&&", "dd", "count=1", "if=" + config.usb_disk, quoted_bs ] return admin.adminCmd(long_cmd) == 0 elif platform.system() == "Windows": syslinux_path = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin")) + \ "\syslinux" + syslinux_version + ".exe" distro_syslinux_install_dir = "/" + distro_syslinux_install_dir.replace( "\\", "/") distro_sys_install_bs = distro_sys_install_bs.replace( "/", "\\") print "\nExecuting ==> " + syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk + ' ' + \ distro_sys_install_bs + "\n" if subprocess.call(syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk + ' ' + distro_sys_install_bs, shell=True) == 0: print "\nSyslinux install was successful on distro directory...\n" else: print "\nFailed to install syslinux on distro directory...\n" elif filesystem == "ext2" or filesystem == "ext3" or filesystem == "ext4" or filesystem == "Btrfs" or filesystem == "ntfs": distro_syslinux_install_dir = os.path.join( install_dir, self.iso.isolinux_bin_dir().strip("/")) if platform.system() == "Linux": syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "extlinux") + syslinux_version if os.access(syslinux_path, os.X_OK) is False: subprocess.call('chmod +x ' + syslinux_path, shell=True) == 0 quoted_exe = "\"" + syslinux_path.replace('"', '\\"') + "\"" quoted_install_dir = distro_syslinux_install_dir.replace( '"', '\\"') quoted_bs = "of=\"" + distro_sys_install_bs.replace( '"', '\\"') + "\"" long_cmd = [ quoted_exe, "--install", quoted_install_dir, "&&", "dd", "count=1", "if=" + config.usb_disk, quoted_bs ] return admin.adminCmd(long_cmd) == 0
def install_default(self): """ Install default syslinux/extlinux (version 4) on selected USB disk. """ if config.iso_link: self.iso = ISO(config.iso_link) filesystem = self.usb.get_usb(config.usb_disk).filesystem mbr_bin = gen_fun.resource_path(os.path.join("tools", "mbr.bin")) config.status_text = "Installing default syslinux..." if filesystem == "ext2" or filesystem == "ext3" or filesystem == "ext4" or filesystem == "Btrfs" or filesystem == "ntfs": if platform.system() == "Linux": syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "extlinux4") if os.access(syslinux_path, os.X_OK) is False: subprocess.call('chmod +x ' + syslinux_path, shell=True) path = os.path.join( self.usb.get_usb(config.usb_disk).mount, "multibootusb") quoted_exe = "\"" + syslinux_path.replace('"', '\\"') + "\"" quoted_path = "\"" + path.replace('"', '\\"') + "\"" quoted_mbusb = "\"" + gen_fun.mbusb_dir().replace('"', '\\"') + "\"" if filesystem == "ntfs": ext_fix = [] else: ext_fix = [ "&&", "chattr", "-i", quoted_path + "/ldlinux.sys" ] long_cmd = ["mkdir", "-p", quoted_path, "&&", "chown", "--reference", quoted_mbusb, quoted_path, "&&", quoted_exe, "--install", quoted_path] + ext_fix + \ ["&&", "echo", "Default Extlinux install is success...", "&&", "dd", "bs=440", "count=1", "conv=notrunc", "\"if=" + mbr_bin + "\"", "of=" + config.usb_disk[:-1], "&&", "echo", "mbr install is success...", "&&"] + self.set_boot_flag_cmd() return admin.adminCmd(long_cmd) == 0 elif filesystem == "vfat" or filesystem == "FAT32": if platform.system() == "Linux": syslinux = gen_fun.resource_path( os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux4")) if os.access(syslinux, os.X_OK) is False: subprocess.call(['chmod', '+x', syslinux]) quoted_exe = "\"" + syslinux.replace('"', '\\"') + "\"" long_cmd = [ quoted_exe, "-i", "-d", "multibootusb", config.usb_disk, "&&", "echo", "Default syslinux install is success...", "&&", "dd", "bs=440", "count=1", "conv=notrunc", "\"if=" + mbr_bin + "\"", "of=" + config.usb_disk[:-1], "&&", "echo", "mbr install is success...", "&&" ] + self.set_boot_flag_cmd() return admin.adminCmd(long_cmd) == 0 elif platform.system() == "Windows": syslinux = gen_fun.resource_path( os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux4.exe")) if subprocess.call(syslinux + ' -maf -d multibootusb ' + config.usb_disk, shell=True) == 0: print "\nDefault syslinux install is success...\n" return True else: print "\nFailed to install default syslinux...\n" return False
def install_distro(self): """ Install syslinux/extlinux on distro isolinux directory. """ self.iso = ISO(config.iso_link) filesystem = self.usb.get_usb(config.usb_disk).filesystem config.status_text = "Installing distro specific syslinux..." if self.iso.isolinux_bin_exist() is not True: print "Distro doesnot use isolinux/syslinux for booting ISO." else: self.iso.iso_extract_file(os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir"), "isolinux.bin") self.iso.iso_extract_file(os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir"), "ISOLINUX.BIN") syslinux_version = self.iso.isolinux_version(self.iso.isolinux_bin_path(os.path.join(gen_fun.mbusb_dir(), "iso_cfg_ext_dir"))) if config.distro == "generic" or config.distro == "alpine": install_dir = self.usb.get_usb(config.usb_disk).mount distro_syslinux_install_dir = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/")).replace(self.usb.get_usb(config.usb_disk).mount, "") distro_sys_install_bs = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/"), config.distro + '.bs') else: install_dir = os.path.join(self.usb.get_usb(config.usb_disk).mount, "multibootusb", self.iso.iso_basename()) distro_syslinux_install_dir = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/")).replace(self.usb.get_usb(config.usb_disk).mount, "") distro_sys_install_bs = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/"), config.distro + '.bs') if filesystem == "vfat" or filesystem == "FAT32": if syslinux_version == str(3): if config.distro == "generic" and self.iso.isolinux_bin_dir() == "/": option = "" else: option = " -d " else: if config.distro == "generic" and self.iso.isolinux_bin_dir() == "/": option = " -i " else: option = " -i -d " print "distro_syslinux_install_dir is " + distro_syslinux_install_dir print "distro_sys_install_bs is " + distro_sys_install_bs if platform.system() == "Linux": syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "syslinux") + syslinux_version if os.access(syslinux_path, os.X_OK) is False: subprocess.call('chmod +x ' + syslinux_path, shell=True) == 0 quoted_exe = "\"" + syslinux_path.replace('"', '\\"') + "\"" quoted_install_dir = distro_syslinux_install_dir.replace('"', '\\"') quoted_bs = "of=\"" + distro_sys_install_bs.replace('"', '\\"') + "\"" long_cmd = [quoted_exe, option, quoted_install_dir, config.usb_disk, "&&", "dd", "count=1", "if=" + config.usb_disk, quoted_bs] return admin.adminCmd(long_cmd) == 0 elif platform.system() == "Windows": syslinux_path = gen_fun.resource_path(os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin")) + \ "\syslinux" + syslinux_version + ".exe" distro_syslinux_install_dir = "/" + distro_syslinux_install_dir.replace("\\", "/") distro_sys_install_bs = distro_sys_install_bs.replace("/", "\\") print "\nExecuting ==> " + syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk + ' ' + \ distro_sys_install_bs + "\n" if subprocess.call(syslinux_path + option + distro_syslinux_install_dir + ' ' + config.usb_disk + ' ' + distro_sys_install_bs, shell=True) == 0: print "\nSyslinux install was successful on distro directory...\n" else: print "\nFailed to install syslinux on distro directory...\n" elif filesystem == "ext2" or filesystem == "ext3" or filesystem == "ext4" or filesystem == "Btrfs" or filesystem == "ntfs": distro_syslinux_install_dir = os.path.join(install_dir, self.iso.isolinux_bin_dir().strip("/")) if platform.system() == "Linux": syslinux_path = os.path.join(gen_fun.mbusb_dir(), "syslinux", "bin", "extlinux") + syslinux_version if os.access(syslinux_path, os.X_OK) is False: subprocess.call('chmod +x ' + syslinux_path, shell=True) == 0 quoted_exe = "\"" + syslinux_path.replace('"', '\\"') + "\"" quoted_install_dir = distro_syslinux_install_dir.replace('"', '\\"') quoted_bs = "of=\"" + distro_sys_install_bs.replace('"', '\\"') + "\"" long_cmd = [quoted_exe, "--install", quoted_install_dir, "&&", "dd", "count=1", "if=" + config.usb_disk, quoted_bs] return admin.adminCmd(long_cmd) == 0