예제 #1
0
    def is_fat(self, partition):
        """ Returns True if the partition (str) is a fat32 partition. False if not. """

        part = lib.return_partition(partition)
        fs = part.fileSystem.type

        if fs in ("fat16", "fat32"):
            return True

        return False
예제 #2
0
	def install(self):
		""" Installs the bootloader on the specified device. """
		
		target = self.settings["target"]
		if not target:
			# No target, we should get one.
			try:
				target = self.modules_settings["partdisks"]["root"]
			except:
				# We can't get a target
				raise m.UserError("Please specify target device.")
		# Get partition
		part = lib.return_partition(target)
		if part == None:
			raise m.UserError("Target device %s not found." % target)
		
		directory = os.path.join(self.main_settings["target"], "syslinux")
		
		bootloader = self.settings["bootloader"]
		if not bootloader:
			# We should get the bootloader ourselves.
			# What this means? We need to check for the partition type and set the appropiate bootloader.
			
			fs = part.fileSystem.type
			if fs in ("fat32"):
				bootloader = "syslinux"
			elif fs in ("ext2","ext3","ext4"):
				args = "-i '%(location)s'" % {"location":target}
				bootloader = "extlinux"
		
		if bootloader == "syslinux":
			args = "-i -d '%(dir)s' '%(location)s'" % {"dir":directory,"location":target}
		elif bootloader == "extlinux":
			# Generate extlinux configuration file (FIXME)
			with open(os.path.join(directory, "extlinux.cfg"), "w") as f:
				f.write("include syslinux.cfg\n")
			
			# Install MBR (warning: we do not make backups! Are they needed on USB drives MBR?)
			# FIXME: maybe find a cooler way to do this?
			m.sexec("dd if=/usr/lib/extlinux/mbr.bin of='%s' bs=440 count=1" % lib.return_device(target))
			
			args = "-i '%(dir)s'" % {"dir":directory}
		
		verbose("Selected location: %s" % target)
					
		m.sexec("%(bootloader)s %(args)s" % {"bootloader":bootloader, "args":args})
		
		# Make partition bootable...
		verbose("Making partition bootable...")
		lib.setFlag(part, "boot")
		lib.commit(part, (target)) # Commit
예제 #3
0
	def start(self):
		""" Start override to unsquash. """
				
		if "partdisks" in self.modules_settings:
			settings = self.modules_settings["partdisks"]
		else:
			settings = self.settings
		
		# Mount root partition.
		root = settings["root"]

		# Ensure that is unmounted
		if os.path.ismount(self.main_settings["target"]):
			# Target mounted. Unmount
			lib.umount(path=self.main_settings["target"])
		if lib.is_mounted(root):
			# Partition mounted. Unmount
			lib.umount(path=root)
				
		# Then mount at TARGET
		lib.mount_partition(path=root, target=self.main_settings["target"])

		used = []
				
		# Mount every partition which has "useas" on it
		# Get changed.
		try:
			changed = self.modules_settings["partdisks"]["changed"]
		except:
			# Pass
			changed = {}
		
		mountpo = []
		changeslist = {}
				
		# Regenerate changed to sort it sanely
		for key, value in changed.items():
			if not "useas" in value["changes"]:
				# There isn't "useas" in changes; skipping this item
				continue

			mountpo.append(value["changes"]["useas"])
			changeslist[value["changes"]["useas"]] = key
		
		mountpo.sort()
				
		for point in mountpo:
						
			# Get correct partition
			key = changeslist[point]
			# Get value
			value = changed[key]
									
			# Get useas
			useas = value["changes"]["useas"]
			
			if useas in ("/","swap"):
				# Root or swap, do not use it
				continue
						
			# Mount key to mountpoint
			if lib.is_mounted(key):
				# Umount
				lib.umount(path=key)
			if useas == "/boot/efi":
				# If this is going to be the /boot/efi partition
				# we should make sure that it's going to have the
				# proper partition type set to EFI System Partition
				lib.prepareforEFI(lib.return_partition(key))
							
			# If we mount_on_install, simply set drop to False, as we should use it anyway
			if ("mount_on_install" in value["changes"] and value["changes"]["mount_on_install"]) or useas in ("/boot","/boot/efi"):
				# Create mountpoint
				mountpoint = self.main_settings["target"] + useas # useas begins with a /, so os.path.join doesn't work
				if not os.path.exists(mountpoint): os.makedirs(mountpoint)

				lib.mount_partition(path=key, target=mountpoint)
				# Partition will be used during unsquash, we should remember when linstaller will execute revert
				used.append(key)
				
		# Store used
		self.settings["used"] = used