예제 #1
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
예제 #2
0
파일: cli.py 프로젝트: odioso/linstaller
	def commit(self, interactive=False):
		""" Commits all the changes to the disks. """
		
		if interactive:
		
			self.header(_("Commit changes"))
			
			print(_("This table is going to be applied:"))
			print
			
			self.print_devices_partitions()
			
			print
			
			print(_("%(warning)s: This will COMMIT ALL THE CHANGES YOU'VE DONE on the physical disks.") % {"warning":bold(_("WARNING"))})
			print(_("This is the last time that you can check your new partition table."))
			print(_("If you continue, you CAN'T RESTORE THE OLD TABLE!") + "\n")
			
			result = self.question(_("Do you really want to continue?"), default=False)
		else:
			result = True

		if result:
			# Ok, continue.
			lst, dct = lib.device_sort(self.changed)
			for key in lst:
				try:
					obj = dct[key]["obj"]
					cng = dct[key]["changes"]
				except:
					verbose("Unable to get a correct object/changes from %s." % key)
					continue # Skip.
								
				verbose("Committing changes in %s" % key)
				
				# If working in a Virtual freespace partition, pyparted will segfault.
				# The following is a workaround, but should be fixed shortly.
				#                FIXME
				#           FIXME     FIXME
				#      FIXME    ______     FIXME
				# FIXME        |      |         FIXME
				# FIXME        |      |               FIXME
				# FIXME FIXME FIXME FIXME FIXME FIXME FIXME
				# ------------------------------------------
				# Figure 1: A FIXME big like an house.
				if "-1" in key:
					continue				

				# New partition table?
				if "newtable" in cng:
					progress = lib.new_table(obj, cng["newtable"])
					info(_("Creating new partition table on %s...") % key)
					status = progress.wait()
					if status != 0:
						# Failed ...
						if interactive:
							return self.edit_partitions(warning=_("FAILED: new partition table in %s") % key)
						else:
							raise m.CmdError(_("FAILED: new partition table in %s") % key)
					
					# Clear touched, as only this action can be done if we do not own a disk.
					del self.touched[obj.path]


				# Commit on the disk.
				lib.commit(obj, self.touched)
								
				# Should format?
				if "format_real" in cng:
					# If this is going to be the swap partition, if swap_nofromat is setted, we should not format.
					#if "useas" in cng and cng["useas"] == "swap" and self.settings["swap_noformat"]:
					#	continue
					# Yes.
					progress = lib.format_partition_for_real(obj, cng["format_real"])
					info(_("Formatting %s...") % key)
					status = progress.wait()
					if status != 0:
						# Failed ...
						if interactive:
							return self.edit_partitions(warning=_("FAILED: formatting %s") % key)
						else:
							raise m.CmdError(_("FAILED: formatting %s") % key)
								
				# Check if it is root or swap
				if "useas" in cng:
					if cng["useas"] == "/":
						# Preseed
						self.settings["root"] = key
						self.settings["root_noformat"] = True
					elif cng["useas"] == "swap":
						# Preseed
						self.settings["swap"] = key
						self.settings["swap_noformat"] = True
				
		# Preseed *all* changes
		self.settings["changed"] = self.changed
		
		# Reload.
		self._reload(complete=False) # Preserve useas.
		
		# Return.
		if interactive: return self.edit_partitions()