Example #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
Example #2
0
	def main(self):
		""" Main prompt. """

		self._reload(complete=False)
		self.header(_("Disk partitioning"))

		# Check if root and swap are preseeded.
		if self.settings["root"] and self.settings["swap"] != False:
			# They are. We can skip this step.
			
			## ROOT
			
			# Get an appropriate device object
			_root_dev = self.disks[lib.return_device(self.settings["root"]).replace("/dev/","")]
			# Get an appropriate partition object
			_root_par = _root_dev.getPartitionByPath(self.settings["root"])
			
			self.changed[self.settings["root"]] = {"obj":_root_par, "changes":{"useas":"/"}}
			###################################################################################
			
			## SWAP
			
			# Get an appropriate device object
			if not self.settings["swap"]:
				# Swap disabled
				self.settings["swap_noformat"] = True # Do not format swap, as it doesn't exist ;)
			else:
				# Get an appropriate partition object
				_swap_dev = self.disks[lib.return_device(self.settings["swap"]).replace("/dev/","")]
				_swap_par = _swap_dev.getPartitionByPath(self.settings["swap"])
				
				self.changed[self.settings["swap"]] = {"obj":_swap_par, "changes":{"useas":"swap"}}
			#######################################################################################
						
			# If root_filesystem is populated, we should format root with that filesystem.
			if self.settings["root_filesystem"]:
				# Format. Yay.
				# Set format.
				self.changed[self.settings["root"]]["changes"]["format"] = self.settings["root_filesystem"]
				self.changed[self.settings["root"]]["changes"]["format_real"] = self.settings["root_filesystem"]
				self.touched[lib.return_device(self.settings["root"])] = True
			
			if not self.settings["swap_noformat"]:
				# Format. Yay.
				# Set format.
				self.changed[self.settings["swap"]]["changes"]["format"] = "linux-swap(v1)"
				self.changed[self.settings["swap"]]["changes"]["format_real"] = "linux-swap(v1)"
				self.touched[lib.return_device(self.settings["swap"])] = True
			
			# Write to memory
			lib.write_memory(self.changed)
			
			# Commit.
			self.commit()

			verbose("Selected %s as root partition" % self.settings["root"])
			if self.settings["swap"]:
				verbose("Selected %s as swap partition" % self.settings["swap"])
			else:
				verbose("Swap disabled.")

			# Skip to next module
			return
		
		# If skip_to_selection == True, we need to skip the following block.
		if self.settings["skip_to_selection"] != True:
			self.print_devices_partitions()
			
			res = self.question(_("Do you want to change the partition table?"), default=False)
			if res:
				# We should change partition structure.
				res = self.edit_partitions()
				# Restart this module
				return self.main()
			else:
				# Check if root and swap are preseeded.
				self.partition_selection()
		else:
			# Run partition_selction()
			self.partition_selection()
			
		verbose("Selected %s as root partition" % self.settings["root"])
		if self.settings["swap"]:
			verbose("Selected %s as swap partition" % self.settings["swap"])
		else:
			verbose("Swap disabled.")
		
		verbose("Other changes: %s" % str(self.changed))
Example #3
0
	def partition_selection(self, warning=None, information=None):
		""" If root and swap aren't preseeded, prompts the user for a partition. """
		
		self.header(_("Select distribution specific drives"))
		
		if warning:
			warn(warning + "\n")
		if information:
			info(information + "\n")
		
		self.print_devices_partitions()
		
		if not self.settings["root"]:
			# No root specified. Prompt for one.
			choice = self.entry(_("Select your root partition"))
			# Check if choice is into disk's partition
			try:
				_root_dev = self.disks[lib.return_device(choice).replace("/dev/","")]
				_root_par = _root_dev.getPartitionByPath(choice)
				if not _root_par:
					# Wrong disk
					return self.partition_selection(warning=_("Wrong partition selected!"))
			except:
				# Wrong disk
				return self.partition_selection(warning=_("Wrong partition selected!"))
			
			self.changed[choice] = {"obj":_root_par, "changes":{"useas":"/"}}
			self.settings["root"] = choice
			
			if not self.settings["root_filesystem"] and not self.settings["root_noformat"]:
				# No filesystem for root specified.
				# Prompt for one.
				
				return self.edit_partitions_format(_root_par, self.changed[choice]["changes"], _return="partsel")
			elif not self.settings["root_noformat"]:
				self.changed[choice]["changes"]["format"] = self.settings["root_filesystem"]
				self.changed[choice]["changes"]["format_real"] = self.settings["root_filesystem"]
				self.touched[lib.return_device(choice)] = True

		if self.settings["swap"] == False:
			
			swaps = lib.swap_available(deep=True)
			if swaps == []:
				# No swap available
				warn(_("No swap partition available. Continuing without."))
				self.settings["swap"] = None
			else:
				# No swap specified. Prompt for one.
				choice = self.entry(_("Select your swap partition (press ENTER to not use swap)"), blank=True)
				if not choice:
					# Should not use swap. ok...
					self.settings["swap"] = None
					warn(_("No swap selected."))
				else:
					# Check if choice is into disk's partition
					_swap_par = False
					for part in swaps:
						if choice == part.path:
							_swap_par = part
					
					if not _swap_par:
						# No swap :/
						return self.partition_selection(warning=_("Wrong partition selected!"))
					
					self.changed[choice] = {"obj":_swap_par, "changes":{"useas":"swap"}}
					self.settings["swap"] = choice
					
					if not self.settings["swap_noformat"]:
						# Prompt for format.
						
						# Set format.
						self.changed[choice]["changes"]["format"] = "linux-swap(v1)"
						self.changed[choice]["changes"]["format_real"] = "linux-swap(v1)"
						self.touched[lib.return_device(self.settings["swap"])] = True
		
		if self.settings["root_noformat"]:
			# Do not alarm the user that we are going to format something -- as we will not format anything (if not swap)
			quest = _("Do you really want to continue?")
		else:
			quest = _("Do you really want to continue? This will destroy selected partitions.")
		
		res = self.question("\n" + quest, default=False)
		if res:	
			# Write to memory
			lib.write_memory(self.changed)
			
			# Commit.
			self.commit()
			
			return
		else:
			return self.main()