def submitted_select_target(self, ctx, form, data): print 'submitted_select_target' # XXX: target selection error messages as constants? fda = formalutils.FormDataAccessor(form, [], ctx) target = None recovery = False large_install = False try: target = form.data['selecttarget.target'] print 'selected target: %s' % target medium = mediahelper.get_media().get_medium_by_device_name(target) if medium.get_size() < constants.DISK_SIZE_MINIMUM: fda.add_error('selecttarget.target', 'Minimum target medium size is 2 GB') if medium.is_write_protected(): fda.add_error('selecttarget.target', 'Target medium is write-protected') if form.data.has_key('selecttarget.recovery'): recovery = form.data['selecttarget.recovery'] if medium.get_size() >= constants.DISK_SIZE_MINIMUM_FOR_LARGE_INSTALL: large_install = True except: fda.add_error('selecttarget.target', 'Target medium cannot be selected') fda.finalize_validation() root = livecddb.get_livecd_database_root() root.setS(ns_ui.targetDevice, rdf.String, target) root.setS(ns_ui.attemptRecovery, rdf.Boolean, recovery) root.removeNodes(ns_ui.previousConfigurationRdfXml) root.removeNodes(ns_ui.previousInstalledVersion) # Recovery check here if recovery: print 'attempting recovery from %s' % target try: prev_cfg, prev_version = installhelpers.recover_existing_configuration(target) if prev_cfg is not None: root.setS(ns_ui.previousConfigurationRdfXml, rdf.String, prev_cfg.encode('hex')) if prev_version is not None: root.setS(ns_ui.previousInstalledVersion, rdf.String, prev_version) else: pass else: raise Exception('did not find recovery data') except: print 'recovery failed' # Select installation model based on target size root.setS(ns_ui.installLargeDisk, rdf.Boolean, large_install) print livecddb.dump_livecd_database() request = inevow.IRequest(ctx) request.redirect(request.URLPath().sibling('installconfirm.html')) return ''
def submitted_select_target(self, ctx, form, data): print 'submitted_select_target' fda = formalutils.FormDataAccessor(form, [], ctx) try: target = form.data['selecttarget.target'] print 'selected target: %s' % target medium = mediahelper.get_media().get_medium_by_device_name(target) if medium.is_write_protected(): fda.add_error('selecttarget.target', 'Target medium is write-protected') except: fda.add_error('selecttarget.target', 'Target medium cannot be selected') fda.finalize_validation() livecddb.get_livecd_database_root().setS(ns_ui.targetDevice, rdf.String, target) print livecddb.dump_livecd_database() request = inevow.IRequest(ctx) request.redirect(request.URLPath().sibling('formatconfirm.html')) return ''
def create_and_format_fatdevice(self, device): """Repartition the device, create and format one FAT32 partition.""" self.debconf_progress_start(0, 100, '') self.debconf_progress_set(0) self.debconf_progress_info('Finding target device: %s' % device) m = mediahelper.get_media() target = m.get_medium_by_device_name(device) if target is None: self.error('failed to find formatting target device: %s' % device) raise Exception('failed to find formatting target device: %s' % device) # determine various parameters for later partitioning and fs setup part_fat = target.get_partition_devicename(1) partitions = [part_fat] disk_size = (target.size - constants.INSTALL_FATDEVICE_SAFETY_MARGIN) / 512 * 512 disk_end = '%ss' % ((disk_size / 512) - 1) # sectors fat_part_name = constants.INSTALL_FATDEVICE_PARTITION_NAME # XXX: this loop could share code with installer counterpart try: self.debconf_progress_info('Wiping target device: %s' % device) self.nuke_and_create_disklabel(device) time.sleep(1) # just in case self.debconf_progress_set(10) self.wait_for_partition_devices_to_disappear(partitions) self.debconf_progress_set(20) # See MBR and partition cylinder-alignment related notes above time.sleep(1) # just in case self.debconf_progress_set(30) self.debconf_progress_info('Creating partitions') parted_cmds = [['mkpart', 'primary', 'fat32', '63s', disk_end]] for i in parted_cmds: run_command(['/sbin/parted', '-s', device] + i, retval=runcommand.FAIL) self.debconf_progress_set(40) time.sleep(1) # just in case self.debconf_progress_set(50) self.wait_for_partition_devices_to_appear(partitions) self.debconf_progress_set(60) # Sleep for a while to ensure that there is no "flicker" of device nodes. # For some reason this happens with at least native hardware and USB sticks. # See #435. time.sleep(5) self.debconf_progress_set(70) self.debconf_progress_info('Creating partitions and filesystems') run_command(['/sbin/mkfs.vfat', '-n', fat_part_name, part_fat], retval=runcommand.FAIL) self.debconf_progress_set(90) except: self.error('failed to create partitions, exiting.') raise self.debconf_progress_set(100) self.debconf_progress_stop()
def create_filesystems(self, device): """Repartition the device, create filesystems and /etc/fstab.""" self.debconf_progress_start(0, 100, '') self.debconf_progress_set(0) self.debconf_progress_info('Finding target device: %s' % device) m = mediahelper.get_media() target = m.get_medium_by_device_name(device) if target is None: self.error('failed to find installation target device: %s' % device) raise Exception('failed to find installation target device: %s' % device) # determine various parameters for later partitioning and fs setup create_swap = True part_fat = None part_boot = None part_swap = None part_root = None if create_swap: if self.large_install: part_fat = target.get_partition_devicename(1) part_boot = target.get_partition_devicename(2) part_swap = target.get_partition_devicename(3) part_root = target.get_partition_devicename(4) partitions = [part_fat, part_boot, part_swap, part_root] else: part_fat = target.get_partition_devicename(1) part_swap = target.get_partition_devicename(2) part_root = target.get_partition_devicename(3) partitions = [part_fat, part_swap, part_root] else: if self.large_install: part_fat = target.get_partition_devicename(1) part_boot = target.get_partition_devicename(2) part_root = target.get_partition_devicename(3) partitions = [part_fat, part_boot, part_root] else: part_fat = target.get_partition_devicename(1) part_root = target.get_partition_devicename(2) partitions = [part_fat, part_root] disk_min_size = (constants.DISK_SIZE_MINIMUM - constants.DISK_SIZE_SAFETY_MARGIN ) / 512 * 512 # disk size with safety margin disk_size = (target.get_size() - constants.DISK_SIZE_SAFETY_MARGIN) / 512 * 512 # partition "end points" fat_end = '1MB' disk_min_end = '%ss' % (disk_min_size / 512) # sectors disk_end = '%ss' % (disk_size / 512) # sectors try: self.debconf_progress_info('Wiping target device: %s' % device) self.nuke_and_create_disklabel(device) # Just in case time.sleep(1) self.debconf_progress_set(5) self.wait_for_partition_devices_to_disappear(partitions) self.debconf_progress_set(10) # MBR is at sector 0, and the first partition should begin at sector 63. # This leaves sectors 1...62 as "no man's land" (31kiB) which is used # for Grub stage 1.5 # # See: http://en.wikipedia.org/wiki/GNU_GRUB # # XXX: currently partitions don't end at cylinder # boundaries. It would probably be best to round the # partitions up to cylinder boundaries, as a # "conservative" partitioning is typically done so. # However, this should not matter as long as we only run # Grub and Linux itself. # # NOTE: Even Windows Vista partitions USB sticks without # caring about cylinders. Probably not an issue anymore. # Just in case time.sleep(1) self.debconf_progress_set(15) # XXX: endpoint is exclusive in parted self.debconf_progress_info('Creating partitions') if create_swap: if self.large_install: boot_end = '256MB' swap_end = '768MB' parted_cmds = [ ['mkpart', 'primary', 'fat32', '63s', fat_end], ['mkpart', 'primary', 'ext2', fat_end, boot_end], [ 'mkpart', 'primary', 'linux-swap', boot_end, swap_end ], ['mkpart', 'primary', 'ext2', swap_end, disk_end], ['set', '2', 'boot', 'on'] ] else: swap_end = '512MB' parted_cmds = [ ['mkpart', 'primary', 'fat32', '63s', fat_end], ['mkpart', 'primary', 'linux-swap', fat_end, swap_end], ['mkpart', 'primary', 'ext2', swap_end, disk_min_end], ['set', '3', 'boot', 'on'] ] else: if self.large_install: boot_end = '256MB' parted_cmds = [ ['mkpart', 'primary', 'fat32', '63s', fat_end], ['mkpart', 'primary', 'ext2', fat_end, boot_end], ['mkpart', 'primary', 'ext2', boot_end, disk_end], ['set', '2', 'boot', 'on'] ] else: parted_cmds = [[ 'mkpart', 'primary', 'fat32', '63s', fat_end ], ['mkpart', 'primary', 'ext2', fat_end, disk_min_end], ['set', '2', 'boot', 'on']] for i in parted_cmds: run_command(['/sbin/parted', '-s', device] + i, retval=runcommand.FAIL) self.debconf_progress_set(20) # Just in case time.sleep(1) self.debconf_progress_set(25) self.wait_for_partition_devices_to_appear(partitions) self.debconf_progress_set(30) # Sleep for a while to ensure that there is no "flicker" of device nodes. # For some reason this happens with at least native hardware and USB sticks. # See #435. time.sleep(5) self.debconf_progress_set(55) self.debconf_progress_info('Creating partitions and filesystems') run_command([ '/sbin/mkfs.vfat', '-n', constants.PRODUCT_NAME.upper(), part_fat ], retval=runcommand.FAIL) self.debconf_progress_set(60) if part_swap is not None: run_command(['/sbin/mkswap', '-L', 'SWAP', part_swap], retval=runcommand.FAIL) if part_boot is not None: # XXX: opts here? run_command([ '/sbin/mkfs.ext3', '-L', 'ROOT', '-b', str(1024), '-i', str(4096), '-m', str(0), '-O', 'sparse_super,filetype,resize_inode,dir_index', '-v', part_boot ], retval=runcommand.FAIL) [rc, stdout, stderr] = run_command(['/sbin/dumpe2fs', part_boot]) self._log.info('dumpe2fs dump of boot filesystem:\n%s' % stdout) else: self._log.info('no boot partition, skipping mkfs') run_command([ '/sbin/mkfs.ext3', '-L', 'ROOT', '-b', str(1024), '-i', str(4096), '-m', str(0), '-O', 'sparse_super,filetype,resize_inode,dir_index', '-v', part_root ], retval=runcommand.FAIL) [rc, stdout, stderr] = run_command(['/sbin/dumpe2fs', part_root]) self._log.info('dumpe2fs dump of root filesystem:\n%s' % stdout) self.debconf_progress_set(95) except: self.error('failed to create partitions, exiting.') raise # Create targets and fstab. self.debconf_progress_info('Mounting target and creating fstab') # Note: not using -p because the target should not exist at this point (cleanup done) run_command([constants.CMD_MKDIR, '/target'], retval=runcommand.FAIL) run_command([constants.CMD_MKDIR, '/target-fat'], retval=runcommand.FAIL) run_command([constants.CMD_MOUNT, part_root, '/target'], retval=runcommand.FAIL) run_command([constants.CMD_MOUNT, part_fat, '/target-fat'], retval=runcommand.FAIL) if part_boot is not None: run_command([constants.CMD_MKDIR, '/target/boot'], retval=runcommand.FAIL) run_command([constants.CMD_MOUNT, part_boot, '/target/boot'], retval=runcommand.FAIL) # Write fstab now (it will not be overwritten by copy process) run_command([constants.CMD_MKDIR, '/target/etc/'], retval=runcommand.FAIL) fstab = textwrap.dedent("""\ # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 %(part_root)s / ext3 defaults,errors=remount-ro,noatime 0 1 """) if part_swap is not None: fstab += textwrap.dedent("""\ %(part_swap)s none swap sw 0 0 """) if part_boot is not None: fstab += textwrap.dedent("""\ %(part_boot)s /boot ext3 defaults 0 2 """) fstab = fstab % { 'part_swap': part_swap, 'part_root': part_root, 'part_boot': part_boot, 'part_fat': part_fat } helpers.write_file('/target/etc/fstab', fstab) self.debconf_progress_set(100) # XXX: cdrom to fstab? nope for now # /dev/hdc /media/cdrom0 iso9660 ro,user,noauto 0 0 self.debconf_progress_stop()
def render_bustype(self, ctx, data): target = livecddb.get_livecd_database_root().getS(ns_ui.targetDevice, rdf.String) medium = mediahelper.get_media().get_medium_by_device_name(target) return medium.get_human_readable_bus_type()
def render_sizebytes(self, ctx, data): target = livecddb.get_livecd_database_root().getS(ns_ui.targetDevice, rdf.String) medium = mediahelper.get_media().get_medium_by_device_name(target) return medium.get_size()
def recover_existing_configuration(target_dev): part_root = None try: mountpoint = '/target-recovery' print 'attempting recovery from %s, mountpoint %s' % (target_dev, mountpoint) m = mediahelper.get_media() target = m.get_medium_by_device_name(target_dev) if target is None: raise Exception('failed to find installation target device: %s' % target_dev) # try a number of partitions; we now have a variable partition scheme for i in xrange(1, 10): try: part_root = target.get_partition_devicename(i) if part_root is None: print 'failed to find partition %d from device: %s' % ( i, target_dev) continue print 'mounting partition %s for recovery' % part_root run_command([constants.CMD_UMOUNT, mountpoint]) # ignore errors run_command([constants.CMD_RMDIR, mountpoint]) # ignore errors run_command([constants.CMD_MKDIR, '-p', mountpoint], retval=runcommand.FAIL) run_command([constants.CMD_MOUNT, part_root, mountpoint], retval=runcommand.FAIL) print 'mounted ok' # XXX: here we assume "well known locations" exported_known_good = os.path.join( mountpoint, 'var', 'lib', 'l2tpgw', 'exported-rdf-database.xml') print 'looking for existing configuration at %s' % exported_known_good if os.path.exists(exported_known_good): print 'found existing exported known good file %s' % exported_known_good else: print 'did not find existing exported known good file %s, next partition' % exported_known_good continue f = None rdfxml = None try: f = open(exported_known_good, 'rb') rdfxml = f.read() finally: if f is not None: f.close() f = None # try to figure old version opportunistically ver_cache = os.path.join(mountpoint, 'var', 'lib', 'l2tpgw', 'version-info-cache') prev_version = None if os.path.exists(ver_cache): f = None try: f = open(ver_cache, 'rb') prev_version = f.read().strip() finally: if f is not None: f.close() f = None return rdfxml, prev_version except: print 'failed recovery check for one partition, this is quite normal' # no results after for loop print 'did not find existing exported known good file %s' % exported_known_good return None, None finally: run_command([constants.CMD_UMOUNT, mountpoint]) # ignore errors if mountpoint is not None: run_command([constants.CMD_RMDIR, '/%s/' % mountpoint]) # ignore errors return None, None
def _get_disks(self): # XXX: this now gets run multiple times... return mediahelper.get_media().get_disk_media_list()
def _get_disks(self): # XXX: this now gets run multiple times... return mediahelper.get_media().get_disk_media_list( ) # Note: ignore cdrom devices
def submitted_select_target(self, ctx, form, data): print 'submitted_select_target' # XXX: target selection error messages as constants? fda = formalutils.FormDataAccessor(form, [], ctx) target = None recovery = False large_install = False try: target = form.data['selecttarget.target'] print 'selected target: %s' % target medium = mediahelper.get_media().get_medium_by_device_name(target) if medium.get_size() < constants.DISK_SIZE_MINIMUM: fda.add_error('selecttarget.target', 'Minimum target medium size is 2 GB') if medium.is_write_protected(): fda.add_error('selecttarget.target', 'Target medium is write-protected') if form.data.has_key('selecttarget.recovery'): recovery = form.data['selecttarget.recovery'] if medium.get_size( ) >= constants.DISK_SIZE_MINIMUM_FOR_LARGE_INSTALL: large_install = True except: fda.add_error('selecttarget.target', 'Target medium cannot be selected') fda.finalize_validation() root = livecddb.get_livecd_database_root() root.setS(ns_ui.targetDevice, rdf.String, target) root.setS(ns_ui.attemptRecovery, rdf.Boolean, recovery) root.removeNodes(ns_ui.previousConfigurationRdfXml) root.removeNodes(ns_ui.previousInstalledVersion) # Recovery check here if recovery: print 'attempting recovery from %s' % target try: prev_cfg, prev_version = installhelpers.recover_existing_configuration( target) if prev_cfg is not None: root.setS(ns_ui.previousConfigurationRdfXml, rdf.String, prev_cfg.encode('hex')) if prev_version is not None: root.setS(ns_ui.previousInstalledVersion, rdf.String, prev_version) else: pass else: raise Exception('did not find recovery data') except: print 'recovery failed' # Select installation model based on target size root.setS(ns_ui.installLargeDisk, rdf.Boolean, large_install) print livecddb.dump_livecd_database() request = inevow.IRequest(ctx) request.redirect(request.URLPath().sibling('installconfirm.html')) return ''
def create_and_format_fatdevice(self, device): """Repartition the device, create and format one FAT32 partition.""" self.debconf_progress_start(0, 100, '') self.debconf_progress_set(0) self.debconf_progress_info('Finding target device: %s' % device) m = mediahelper.get_media() target = m.get_medium_by_device_name(device) if target is None: self.error('failed to find formatting target device: %s' % device) raise Exception('failed to find formatting target device: %s' % device) # determine various parameters for later partitioning and fs setup part_fat = target.get_partition_devicename(1) partitions = [ part_fat ] disk_size = (target.size - constants.INSTALL_FATDEVICE_SAFETY_MARGIN) / 512 * 512 disk_end = '%ss' % ((disk_size / 512) - 1) # sectors fat_part_name = constants.INSTALL_FATDEVICE_PARTITION_NAME # XXX: this loop could share code with installer counterpart try: self.debconf_progress_info('Wiping target device: %s' % device) self.nuke_and_create_disklabel(device) time.sleep(1) # just in case self.debconf_progress_set(10) self.wait_for_partition_devices_to_disappear(partitions) self.debconf_progress_set(20) # See MBR and partition cylinder-alignment related notes above time.sleep(1) # just in case self.debconf_progress_set(30) self.debconf_progress_info('Creating partitions') parted_cmds = [ ['mkpart', 'primary', 'fat32', '63s', disk_end] ] for i in parted_cmds: run_command(['/sbin/parted', '-s', device] + i, retval=runcommand.FAIL) self.debconf_progress_set(40) time.sleep(1) # just in case self.debconf_progress_set(50) self.wait_for_partition_devices_to_appear(partitions) self.debconf_progress_set(60) # Sleep for a while to ensure that there is no "flicker" of device nodes. # For some reason this happens with at least native hardware and USB sticks. # See #435. time.sleep(5) self.debconf_progress_set(70) self.debconf_progress_info('Creating partitions and filesystems') run_command(['/sbin/mkfs.vfat', '-n', fat_part_name, part_fat], retval=runcommand.FAIL) self.debconf_progress_set(90) except: self.error('failed to create partitions, exiting.') raise self.debconf_progress_set(100) self.debconf_progress_stop()
def create_filesystems(self, device): """Repartition the device, create filesystems and /etc/fstab.""" self.debconf_progress_start(0, 100, '') self.debconf_progress_set(0) self.debconf_progress_info('Finding target device: %s' % device) m = mediahelper.get_media() target = m.get_medium_by_device_name(device) if target is None: self.error('failed to find installation target device: %s' % device) raise Exception('failed to find installation target device: %s' % device) # determine various parameters for later partitioning and fs setup create_swap = True part_fat = None part_boot = None part_swap = None part_root = None if create_swap: if self.large_install: part_fat = target.get_partition_devicename(1) part_boot = target.get_partition_devicename(2) part_swap = target.get_partition_devicename(3) part_root = target.get_partition_devicename(4) partitions = [part_fat, part_boot, part_swap, part_root] else: part_fat = target.get_partition_devicename(1) part_swap = target.get_partition_devicename(2) part_root = target.get_partition_devicename(3) partitions = [part_fat, part_swap, part_root] else: if self.large_install: part_fat = target.get_partition_devicename(1) part_boot = target.get_partition_devicename(2) part_root = target.get_partition_devicename(3) partitions = [part_fat, part_boot, part_root] else: part_fat = target.get_partition_devicename(1) part_root = target.get_partition_devicename(2) partitions = [part_fat, part_root] disk_min_size = (constants.DISK_SIZE_MINIMUM - constants.DISK_SIZE_SAFETY_MARGIN) / 512 * 512 # disk size with safety margin disk_size = (target.get_size() - constants.DISK_SIZE_SAFETY_MARGIN) / 512 * 512 # partition "end points" fat_end = '1MB' disk_min_end = '%ss' % (disk_min_size / 512) # sectors disk_end = '%ss' % (disk_size / 512) # sectors try: self.debconf_progress_info('Wiping target device: %s' % device) self.nuke_and_create_disklabel(device) # Just in case time.sleep(1) self.debconf_progress_set(5) self.wait_for_partition_devices_to_disappear(partitions) self.debconf_progress_set(10) # MBR is at sector 0, and the first partition should begin at sector 63. # This leaves sectors 1...62 as "no man's land" (31kiB) which is used # for Grub stage 1.5 # # See: http://en.wikipedia.org/wiki/GNU_GRUB # # XXX: currently partitions don't end at cylinder # boundaries. It would probably be best to round the # partitions up to cylinder boundaries, as a # "conservative" partitioning is typically done so. # However, this should not matter as long as we only run # Grub and Linux itself. # # NOTE: Even Windows Vista partitions USB sticks without # caring about cylinders. Probably not an issue anymore. # Just in case time.sleep(1) self.debconf_progress_set(15) # XXX: endpoint is exclusive in parted self.debconf_progress_info('Creating partitions') if create_swap: if self.large_install: boot_end = '256MB' swap_end = '768MB' parted_cmds = [ ['mkpart', 'primary', 'fat32', '63s', fat_end], ['mkpart', 'primary', 'ext2', fat_end, boot_end], ['mkpart', 'primary', 'linux-swap', boot_end, swap_end], ['mkpart', 'primary', 'ext2', swap_end, disk_end], ['set', '2', 'boot', 'on'] ] else: swap_end = '512MB' parted_cmds = [ ['mkpart', 'primary', 'fat32', '63s', fat_end], ['mkpart', 'primary', 'linux-swap', fat_end, swap_end], ['mkpart', 'primary', 'ext2', swap_end, disk_min_end], ['set', '3', 'boot', 'on'] ] else: if self.large_install: boot_end = '256MB' parted_cmds = [ ['mkpart', 'primary', 'fat32', '63s', fat_end], ['mkpart', 'primary', 'ext2', fat_end, boot_end], ['mkpart', 'primary', 'ext2', boot_end, disk_end], ['set', '2', 'boot', 'on'] ] else: parted_cmds = [ ['mkpart', 'primary', 'fat32', '63s', fat_end], ['mkpart', 'primary', 'ext2', fat_end, disk_min_end], ['set', '2', 'boot', 'on'] ] for i in parted_cmds: run_command(['/sbin/parted', '-s', device] + i, retval=runcommand.FAIL) self.debconf_progress_set(20) # Just in case time.sleep(1) self.debconf_progress_set(25) self.wait_for_partition_devices_to_appear(partitions) self.debconf_progress_set(30) # Sleep for a while to ensure that there is no "flicker" of device nodes. # For some reason this happens with at least native hardware and USB sticks. # See #435. time.sleep(5) self.debconf_progress_set(55) self.debconf_progress_info('Creating partitions and filesystems') run_command(['/sbin/mkfs.vfat', '-n', constants.PRODUCT_NAME.upper(), part_fat], retval=runcommand.FAIL) self.debconf_progress_set(60) if part_swap is not None: run_command(['/sbin/mkswap', '-L', 'SWAP', part_swap], retval=runcommand.FAIL) if part_boot is not None: # XXX: opts here? run_command(['/sbin/mkfs.ext3', '-L', 'ROOT', '-b', str(1024), '-i', str(4096), '-m', str(0), '-O', 'sparse_super,filetype,resize_inode,dir_index', '-v', part_boot], retval=runcommand.FAIL) [rc, stdout, stderr] = run_command(['/sbin/dumpe2fs', part_boot]) self._log.info('dumpe2fs dump of boot filesystem:\n%s' % stdout) else: self._log.info('no boot partition, skipping mkfs') run_command(['/sbin/mkfs.ext3', '-L', 'ROOT', '-b', str(1024), '-i', str(4096), '-m', str(0), '-O', 'sparse_super,filetype,resize_inode,dir_index', '-v', part_root], retval=runcommand.FAIL) [rc, stdout, stderr] = run_command(['/sbin/dumpe2fs', part_root]) self._log.info('dumpe2fs dump of root filesystem:\n%s' % stdout) self.debconf_progress_set(95) except: self.error('failed to create partitions, exiting.') raise # Create targets and fstab. self.debconf_progress_info('Mounting target and creating fstab') # Note: not using -p because the target should not exist at this point (cleanup done) run_command([constants.CMD_MKDIR, '/target'], retval=runcommand.FAIL) run_command([constants.CMD_MKDIR, '/target-fat'], retval=runcommand.FAIL) run_command([constants.CMD_MOUNT, part_root, '/target'], retval=runcommand.FAIL) run_command([constants.CMD_MOUNT, part_fat, '/target-fat'], retval=runcommand.FAIL) if part_boot is not None: run_command([constants.CMD_MKDIR, '/target/boot'], retval=runcommand.FAIL) run_command([constants.CMD_MOUNT, part_boot, '/target/boot'], retval=runcommand.FAIL) # Write fstab now (it will not be overwritten by copy process) run_command([constants.CMD_MKDIR, '/target/etc/'], retval=runcommand.FAIL) fstab = textwrap.dedent("""\ # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 %(part_root)s / ext3 defaults,errors=remount-ro,noatime 0 1 """) if part_swap is not None: fstab += textwrap.dedent("""\ %(part_swap)s none swap sw 0 0 """) if part_boot is not None: fstab += textwrap.dedent("""\ %(part_boot)s /boot ext3 defaults 0 2 """) fstab = fstab % {'part_swap':part_swap, 'part_root':part_root, 'part_boot':part_boot, 'part_fat':part_fat} helpers.write_file('/target/etc/fstab', fstab) self.debconf_progress_set(100) # XXX: cdrom to fstab? nope for now # /dev/hdc /media/cdrom0 iso9660 ro,user,noauto 0 0 self.debconf_progress_stop()
def recover_existing_configuration(target_dev): part_root = None try: mountpoint = '/target-recovery' print 'attempting recovery from %s, mountpoint %s' % (target_dev, mountpoint) m = mediahelper.get_media() target = m.get_medium_by_device_name(target_dev) if target is None: raise Exception('failed to find installation target device: %s' % target_dev) # try a number of partitions; we now have a variable partition scheme for i in xrange(1, 10): try: part_root = target.get_partition_devicename(i) if part_root is None: print 'failed to find partition %d from device: %s' % (i, target_dev) continue print 'mounting partition %s for recovery' % part_root run_command([constants.CMD_UMOUNT, mountpoint]) # ignore errors run_command([constants.CMD_RMDIR, mountpoint]) # ignore errors run_command([constants.CMD_MKDIR, '-p', mountpoint], retval=runcommand.FAIL) run_command([constants.CMD_MOUNT, part_root, mountpoint], retval=runcommand.FAIL) print 'mounted ok' # XXX: here we assume "well known locations" exported_known_good = os.path.join(mountpoint, 'var', 'lib', 'l2tpgw', 'exported-rdf-database.xml') print 'looking for existing configuration at %s' % exported_known_good if os.path.exists(exported_known_good): print 'found existing exported known good file %s' % exported_known_good else: print 'did not find existing exported known good file %s, next partition' % exported_known_good continue f = None rdfxml = None try: f = open(exported_known_good, 'rb') rdfxml = f.read() finally: if f is not None: f.close() f = None # try to figure old version opportunistically ver_cache = os.path.join(mountpoint, 'var', 'lib', 'l2tpgw', 'version-info-cache') prev_version = None if os.path.exists(ver_cache): f = None try: f = open(ver_cache, 'rb') prev_version = f.read().strip() finally: if f is not None: f.close() f = None return rdfxml, prev_version except: print 'failed recovery check for one partition, this is quite normal' # no results after for loop print 'did not find existing exported known good file %s' % exported_known_good return None, None finally: run_command([constants.CMD_UMOUNT, mountpoint]) # ignore errors if mountpoint is not None: run_command([constants.CMD_RMDIR, '/%s/' % mountpoint]) # ignore errors return None, None
def _get_disks(self): # XXX: this now gets run multiple times... return mediahelper.get_media().get_disk_media_list() # Note: ignore cdrom devices