Merge branch 'master' into devel

pull/276/head
Shinji Suzuki 6 years ago
commit fd656ebeab

3
.gitignore vendored

@ -95,6 +95,9 @@ ENV/
# Source file
multibootusb*.tar.gz
# Temp files
data/multibootusb/grub/menus.zip
# Setup file
multibootusb*.exe

@ -1,3 +1,9 @@
Version - 9.1.0
---------------
* Included missing EFI modules
* Fix for application crashing crashing on windows system
* New option to boot distros directly from ISOs. To availe this option, you need to copy ISO files in /multibootusb/iso
Version - 9.0.0
---------------
* Improved UEFI support

@ -309,7 +309,14 @@ def usage():
sys.exit(-1)
if __name__ == '__main__':
# Ensure to pack all menus to packaging directory
if os.path.exists(os.path.join('data', 'multibootusb', 'grub', 'menus.zip')):
os.remove(os.path.join('data', 'multibootusb', 'grub', 'menus.zip'))
shutil.make_archive(os.path.join('data', 'multibootusb', 'grub', 'menus'),
'zip', os.path.join('data', 'multibootusb', 'grub', 'menus'))
if platform.system() == 'Linux':
print('Converting line ending to Linux for proper functioning.')
os.system('dos2unix multibootusb')

@ -265,6 +265,13 @@ def copy_mbusb_dir_usb(usb_disk):
if not os.path.exists(os.path.join(usb_mount_path, 'multibootusb', 'iso')):
os.makedirs(os.path.join(usb_mount_path, 'multibootusb', 'iso'))
# Update the menu files from resource path to USB directory.
try:
with zipfile.ZipFile(resource_path(os.path.join('data', 'multibootusb', 'grub', 'menus.zip')), "r") as z:
z.extractall(os.path.join(usb_mount_path, 'multibootusb', 'grub', 'menus'))
except:
log('Unable to extract menu files to USB disk.')
return result
@ -488,6 +495,28 @@ class MemoryCheck():
totalMemory = os.popen("free -m").readlines()[1].split()[1]
return int(totalMemory)
def wmi_get_drive_info(usb_disk):
assert platform.system() == 'Windows'
import wmi
c = wmi.WMI()
for partition in c.Win32_DiskPartition():
logical_disks = partition.associators("Win32_LogicalDiskToPartition")
# Here, 'disk' is a windows logical drive rather than a physical drive
for disk in logical_disks:
if disk.Caption == usb_disk:
return (partition, disk)
raise RuntimeError('Failed to obtain drive information ' + usb_disk)
def get_physical_disk_number(usb_disk):
"""
Get the physical disk number as detected ny Windows.
:param usb_disk: USB disk (Like F:)
:return: Disk number.
"""
partition, logical_disk = wmi_get_drive_info(usb_disk)
log("Physical Device Number is %d" % partition.DiskIndex)
return partition.DiskIndex
if __name__ == '__main__':
log(quote("""Test-string"""))
log(has_digit("test-string-with-01-digit"))

@ -85,10 +85,11 @@ class Qemu(QtWidgets.QMainWindow, Ui_MainWindow):
ram = ""
if platform.system() == "Windows":
disk_number = self.get_physical_disk_number(qemu_usb_disk)
disk_number = get_physical_disk_number(qemu_usb_disk)
parent_dir = os.getcwd()
os.chdir(resource_path(os.path.join("data", "tools", "qemu")))
cmd = quote(qemu) + ' -L . -boot c' + ram + ' -hda //./PhysicalDrive' + disk_number
cmd = quote(qemu) + ' -L . -boot c' + ram \
+ ' -hda //./PhysicalDrive' + str(disk_number)
try:
log("Executing ==> " + cmd)
@ -156,21 +157,3 @@ class Qemu(QtWidgets.QMainWindow, Ui_MainWindow):
return qemu
@staticmethod
def get_physical_disk_number(usb_disk):
"""
Get the physical disk number as detected ny Windows.
:param usb_disk: USB disk (Like F:)
:return: Disk number.
"""
import wmi
c = wmi.WMI()
for physical_disk in c.Win32_DiskDrive():
for partition in physical_disk.associators("Win32_DiskDriveToDiskPartition"):
for logical_disk in partition.associators("Win32_LogicalDiskToPartition"):
if logical_disk.Caption == usb_disk:
# log physical_disk.Caption
# log partition.Caption
# log logical_disk.Caption
log("Physical Device Number is " + partition.Caption[6:-14])
return str(partition.Caption[6:-14])

@ -39,7 +39,6 @@ def gpt_part_table(usb_disk):
elif b'gpt' in _cmd_out:
return True
elif platform.system() == 'Windows':
win_usb_disk_no = str(usb.get_physical_disk_number(config.usb_disk))
if config.usb_gpt is True:
return True
elif config.usb_gpt is False:
@ -107,10 +106,10 @@ def syslinux_default(usb_disk):
if platform.system() == 'Linux':
mbr_install_cmd = 'dd bs=440 count=1 conv=notrunc if=' + mbr_bin + ' of=' + usb_disk[:-1]
else:
win_usb_disk_no = str(usb.get_physical_disk_number(config.usb_disk))
win_usb_disk_no = get_physical_disk_number(config.usb_disk)
_windd = resource_path(os.path.join("data", "tools", "dd", "dd.exe"))
_input = "if=" + mbr_bin
_output = 'of=\\\.\\physicaldrive' + win_usb_disk_no
_output = 'of=\\\.\\physicaldrive' + str(win_usb_disk_no)
mbr_install_cmd = _windd + ' ' + _input + ' ' + _output + ' count=1'
if usb_fs in extlinux_fs:
@ -299,42 +298,32 @@ def replace_grub_binary():
Default binaries will work for msdos partition table and therefore need not be replaced.
:return:
"""
grub_efi_bin_path = os.path.join(config.usb_mount, 'EFI', 'BOOT', 'bootx64.efi')
grub_efi_bin_gpt_path = os.path.join(config.usb_mount, 'EFI', 'BOOT', 'bootx64-gpt.efi')
grub_efi_bin_msdos_path = os.path.join(config.usb_mount, 'EFI', 'BOOT', 'bootx64-msdos.efi')
core_img_bin_path = os.path.join(config.usb_mount, 'multibootusb', 'grub', 'core.img')
core_img_bin_msdos_path = os.path.join(config.usb_mount, 'multibootusb', 'grub', 'core-msdos.img')
core_img_bin_gpt_path = os.path.join(config.usb_mount, 'multibootusb', 'grub', 'core-gpt.img')
if platform.system() in ['Linux', 'Windows']:
if gpt_part_table(config.usb_disk) is True:
log('Replacing efi binary with gpt compatible one...')
try:
shutil.copy(grub_efi_bin_gpt_path, grub_efi_bin_path)
except Exception as e:
log(e)
log('Failed to replace efi binary...')
log('Replacing core.img binary with gpt compatible one...')
try:
shutil.copy(core_img_bin_gpt_path, core_img_bin_path)
except Exception as e:
log(e)
log('Failed to replace efi binary...')
else:
log('Replacing efi binary with msdos compatible one...')
try:
# shutil.copy(core_img_bin_gpt_path, core_img_bin_path)
shutil.copy(grub_efi_bin_msdos_path, grub_efi_bin_path)
except Exception as e:
log(e)
log('Failed to replace efi binary...')
# There used to be msdos/gpt specific files installed and relevant
# ones were copied to target files. But those specific files were
# removed by commit ec0f8d95f98f65541c8734623d97f4bd3cbecf0f.
# Therefore, as of commit d3c7aa7dc72b3d442c854a6a89071d3f5995ec27,
# code segment below is effectively no-op.
if platform.system() not in ['Linux', 'Windows']:
return
ptype = gpt_part_table(config.usb_disk) and '-gpt.' or '-msdos.'
for dir_, fname in [
(os.path.join(config.usb_mount, 'EFI', 'BOOT'), 'bootx64.efi'),
(os.path.join(config.usb_mount, 'multibootusb', 'grub'), 'grub.img')
]:
base, ext = fname.split('.')
src = os.path.join(dir_, base + ptype + ext)
dst = os.path.join(dir_, fname)
if os.path.exists(src):
try:
log('Replacing core.img with msdos compatible one...')
shutil.copy(core_img_bin_msdos_path, core_img_bin_path)
log('Replacing %s with %s...' % (dst, src))
shutil.copy(src, dst)
except Exception as e:
log(e)
log('Failed to replace core.img binary...')
log('Failed to replace %s with %s...' % (dst, src))
if __name__ == '__main__':
if os.geteuid() != 0:

@ -106,7 +106,7 @@ def update_distro_cfg_files(iso_link, usb_disk, distro, persistence=0):
flags=re.I)
string = re.sub(r'linux_32=\"', 'linux_32=\"/multibootusb/' + iso_basename(iso_link), string,
flags=re.I)
string = re.sub(r'initrd_img=\"', 'linux_32=\"/multibootusb/' + iso_basename(iso_link), string,
string = re.sub(r'initrd_img=\"', 'initrd_img=\"/multibootusb/' + iso_basename(iso_link), string,
flags=re.I)
string = re.sub(r'initrd_img32=\"', 'initrd_img32=\"/multibootusb/' + iso_basename(iso_link), string,
flags=re.I)

@ -361,36 +361,12 @@ def gpt_device(dev_name):
:return: True if GPT else False
"""
if platform.system() == 'Windows':
try:
try:
from subprocess import DEVNULL
except ImportError:
DEVNULL = os.open(os.devnull, os.O_RDWR)
# DEVNULL = os.open(os.devnull, os.O_RDWR)
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
diskpart_cmd = 'wmic partition get name, type'
# We have to check using byte code else it crashes when system language is other than English
dev_no = get_physical_disk_number(dev_name).encode()
# Below line fails on onefile windows binary
# cmd_out = subprocess.check_output(diskpart_cmd, subprocess.SW_HIDE, startupinfo=startupinfo, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.DEVNULL)
cmd_out = subprocess.check_output(diskpart_cmd, subprocess.SW_HIDE, startupinfo=startupinfo, stdin=DEVNULL, stderr=DEVNULL)
gen.log(cmd_out)
cmd_spt = cmd_out.split(b'\r')
for line in cmd_spt:
# line = line('utf-8')
if b'#' + dev_no + b',' in line:
if b'GPT' not in line:
config.usb_gpt = False
gen.log('Device ' + dev_name + ' is a MBR disk...')
return False
else:
config.usb_gpt = True
gen.log('Device ' + dev_name + ' is a GPT disk...')
return True
except Exception as e:
gen.log(e)
partition, disk = gen.wmi_get_drive_info(dev_name)
is_gpt = partition.Type.startswith('GPT:')
gen.log('Device %s is a %s disk...' %
(dev_name, is_gpt and 'GPT' or 'MBR'))
config.usb_gpt = is_gpt
return is_gpt
if platform.system() == "Linux":
if gen.has_digit(dev_name):
_cmd_out = subprocess.check_output("parted " + dev_name[:-1] + " print", shell=True)
@ -482,22 +458,6 @@ def details(usb_disk_part):
return details
def get_physical_disk_number(usb_disk):
"""
Get the physical disk number as detected ny Windows.
:param usb_disk: USB disk (Like F:)
:return: Disk number.
"""
import wmi
c = wmi.WMI()
for physical_disk in c.Win32_DiskDrive():
for partition in physical_disk.associators("Win32_DiskDriveToDiskPartition"):
for logical_disk in partition.associators("Win32_LogicalDiskToPartition"):
if logical_disk.Caption == usb_disk:
# gen.log("Physical Device Number is " + partition.Caption[6:-14])
return str(partition.Caption[6:-14])
if __name__ == '__main__':
usb_devices = list_devices()
if usb_devices is not None:

@ -10,6 +10,7 @@ from distutils.core import setup
#from setuptools import setup, find_packages
import os
from scripts.gen import mbusb_version
import shutil
Version = mbusb_version()
@ -48,7 +49,8 @@ setup(
version=Version,
packages=['scripts', 'scripts.pyudev', 'scripts.pyudev.device', 'scripts.pyudev._ctypeslib', 'scripts.pyudev._os',
'scripts.gui', 'scripts.progressbar'],
#packages=find_packages(),
# packages=find_packages(),
include_package_data=True,
scripts=['multibootusb', 'multibootusb-pkexec'],
platforms=['Linux'],
url='http://multibootusb.org/',
@ -56,7 +58,8 @@ setup(
author='Sundar',
author_email='feedback.multibootusb@gmail.com',
description='Create multi boot live Linux on a USB disk...',
long_description='multibootusb is an advanced cross-platform application for installing/uninstalling Linux operating systems on to a single USB flash drives.',
long_description='multibootusb is an advanced cross-platform application for installing/uninstalling Linux operating \
systems on to a single USB flash drives.',
data_files=[("/usr/share/applications", ["data/multibootusb.desktop"]),
('/usr/share/pixmaps', ["data/tools/multibootusb.png"]),
('/usr/share/polkit-1/actions/', ['org.debian.pkexec.run-multibootusb.policy']),
@ -77,6 +80,7 @@ setup(
('/usr/share/multibootusb/data/multibootusb', ["data/multibootusb/syslinux.cfg"]),
('/usr/share/multibootusb/data/multibootusb', ["data/multibootusb/vesamenu.c32"]),
('/usr/share/multibootusb/data/multibootusb/grub', root_files('data/multibootusb/grub')),
('/usr/share/multibootusb/data/multibootusb/grub/i386-pc', get_data('data/multibootusb/grub')),
('/usr/share/multibootusb/data/multibootusb/grub/i386-pc', get_data('data/multibootusb/grub/i386-pc')),
('/usr/share/multibootusb/data/multibootusb/grub/x86_64-efi', get_data('data/multibootusb/grub/x86_64-efi')),
('/usr/share/multibootusb/data/tools/syslinux', get_data('data/tools/syslinux'))]
)

Loading…
Cancel
Save