def build_live_fs(self): try: # update package manifest self.log.info('Updating Package list...') #os.system('chroot %s dpkg -l > %s/live/packages.txt' % (self.__live_fs_dir, self.__iso_fs_dir)) os.system( 'chroot %s dpkg-query -W --showformat=\'${Package} ${Version}\' > %s/live/packages.txt' % (self.__live_fs_dir, self.__iso_fs_dir)) self.log.info('Building squash filesystem: %s' % (self.__live_fs_filename)) if squash_tools.create_squash_fs( mksquashfs_cmd=self.__mksquash, source_dir=self.__live_fs_dir, dest_filename=self.__live_fs_filename, overwrite=True): if os.path.exists(self.__live_fs_filename): self.log.debug('Live squash filesystem complete: %s' % (self.__live_fs_filename)) return True else: self.log.error( 'Error creating squash filesystem; check log for details...' ) return False else: self.log.error( 'Error creating squash filesystem; check log for details...' ) return False except Exception, d: self.log.error('Error creating squash filesystem: %s : %s' % (self.__live_fs_filename, d)) return False
def build_live_fs(self): try: self.log.debug('Creating sparse image...') tmpImgDir = tempfile.mkdtemp() tmpSquashDir = tmpImgDir + os.sep + 'LiveOS' tmpMntDir = tempfile.mkdtemp() os.makedirs(tmpSquashDir) # default fedora uses a 3GB image -- larger takes longer to boot and live env runs slower os.system('dd if=/dev/zero of=%s/ext3fs.img bs=1M count=0 seek=3072' % (tmpSquashDir)) os.system('mkfs.ext3 -F %s' % (os.path.join(tmpSquashDir, 'ext3fs.img'))) # mount fs_tools.mount(os.path.join(tmpSquashDir, 'ext3fs.img'), tmpMntDir) # copy files os.system('rsync -a %s/ %s/' % (self.__live_fs_dir, tmpMntDir)) # TODO: relabel filesystem for selinux #self.log.info('Performing relabel on filesystem (selinux)...') #os.system('chroot %s /sbin/fixfiles relabel' % (tmpMntDir)) self.log.info('Building squash filesystem: %s' % (self.__live_fs_filename)) if squash_tools.create_squash_fs(mksquashfs_cmd=self.__mksquash, source_dir=tmpImgDir, dest_filename=self.__live_fs_filename, overwrite=True): if os.path.exists(self.__live_fs_filename): self.log.debug('Live squash filesystem complete: %s' % (self.__live_fs_filename)) return True else: self.log.error('Error creating squash filesystem; check log for details...') return False else: self.log.error('Error creating squash filesystem; check log for details...') return False except Exception, d: self.log.error('Error creating squash filesystem: %s : %s' % (self.__live_fs_filename, d)) return False
def build_live_fs(self): try: self.log.debug('Creating sparse image...') tmpImgDir = tempfile.mkdtemp() tmpSquashDir = tmpImgDir + os.sep + 'LiveOS' tmpMntDir = tempfile.mkdtemp() os.makedirs(tmpSquashDir) os.system('dd if=/dev/zero of=%s/ext3fs.img bs=1M count=0 seek=4096' % (tmpSquashDir)) os.system('mkfs.ext3 -F %s' % (os.path.join(tmpSquashDir, 'ext3fs.img'))) # mount fs_tools.mount(os.path.join(tmpSquashDir, 'ext3fs.img'), tmpMntDir) # copy files os.system('rsync -a %s/ %s/' % (self.__live_fs_dir, tmpMntDir)) self.log.info('Building squash filesystem: %s' % (self.__live_fs_filename)) if squash_tools.create_squash_fs(mksquashfs_cmd=self.__mksquash, source_dir=tmpImgDir, dest_filename=self.__live_fs_filename, overwrite=True): if os.path.exists(self.__live_fs_filename): self.log.debug('Live squash filesystem complete: %s' % (self.__live_fs_filename)) return True else: self.log.error('Error creating squash filesystem; check log for details...') return False else: self.log.error('Error creating squash filesystem; check log for details...') return False except Exception, d: self.log.error('Error creating squash filesystem: %s : %s' % (self.__live_fs_filename, d)) return False
def build_live_fs(self): try: self.log.debug('Creating sparse image...') tmpImgDir = tempfile.mkdtemp() tmpSquashDir = tmpImgDir + os.sep + 'LiveOS' tmpMntDir = tempfile.mkdtemp() os.makedirs(tmpSquashDir) os.system('dd if=/dev/zero of=%s/ext3fs.img bs=1M count=0 seek=8192' % (tmpSquashDir)) os.system('mkfs.ext3 -F %s' % (os.path.join(tmpSquashDir, 'ext3fs.img'))) # mount fs_tools.mount(os.path.join(tmpSquashDir, 'ext3fs.img'), tmpMntDir) # copy files os.system('rsync -a %s/ %s/' % (self.__live_fs_dir, tmpMntDir)) self.log.info('Building squash filesystem: %s' % (self.__live_fs_filename)) if squash_tools.create_squash_fs(mksquashfs_cmd=self.__mksquash, source_dir=tmpImgDir, dest_filename=self.__live_fs_filename, overwrite=True): if os.path.exists(self.__live_fs_filename): self.log.debug('Live squash filesystem complete: %s' % (self.__live_fs_filename)) return True else: self.log.error('Error creating squash filesystem; check log for details...') return False else: self.log.error('Error creating squash filesystem; check log for details...') return False except Exception, d: self.log.error('Error creating squash filesystem: %s : %s' % (self.__live_fs_filename, d)) return False
def testCreateSquashFs(self): self.assertTrue( squash_tools.create_squash_fs(source_dir=self.squash_root, dest_filename=self.squash_file, overwrite=True)) self.assertTrue(os.path.exists(self.squash_file), 'Squash file does not exist...') self.assertTrue(len(self.squash_file) != 0)
def testExtractSquashFs(self): self.assertTrue( squash_tools.create_squash_fs(source_dir=self.squash_root, dest_filename=self.squash_file, overwrite=True)) self.assertTrue( squash_tools.extract_squash_fs(filename=self.squash_file, dest_dir=self.tmp_squash_dir), 'Error extracting squash filesystem...') self.assertTrue( os.listdir(self.tmp_squash_dir) != 0, 'Error extracting squash filesystem: directory empty...')
def build_live_fs(self): try: self.log.debug('Creating sparse image...') tmpImgDir = tempfile.mkdtemp() tmpSquashDir = tmpImgDir + os.sep + 'LiveOS' tmpMntDir = tempfile.mkdtemp() os.makedirs(tmpSquashDir) # default fedora uses a 3GB image -- larger takes longer to boot and live env runs slower os.system( 'dd if=/dev/zero of=%s/ext3fs.img bs=1M count=0 seek=3072' % (tmpSquashDir)) os.system('mkfs.ext3 -F %s' % (os.path.join(tmpSquashDir, 'ext3fs.img'))) # mount fs_tools.mount(os.path.join(tmpSquashDir, 'ext3fs.img'), tmpMntDir) # copy files os.system('rsync -a %s/ %s/' % (self.__live_fs_dir, tmpMntDir)) # TODO: relabel filesystem for selinux #self.log.info('Performing relabel on filesystem (selinux)...') #os.system('chroot %s /sbin/fixfiles relabel' % (tmpMntDir)) self.log.info('Building squash filesystem: %s' % (self.__live_fs_filename)) if squash_tools.create_squash_fs( mksquashfs_cmd=self.__mksquash, source_dir=tmpImgDir, dest_filename=self.__live_fs_filename, overwrite=True): if os.path.exists(self.__live_fs_filename): self.log.debug('Live squash filesystem complete: %s' % (self.__live_fs_filename)) return True else: self.log.error( 'Error creating squash filesystem; check log for details...' ) return False else: self.log.error( 'Error creating squash filesystem; check log for details...' ) return False except Exception, d: self.log.error('Error creating squash filesystem: %s : %s' % (self.__live_fs_filename, d)) return False
def build_live_fs(self): try: # update package manifest self.log.info('Updating Package list...') #os.system('chroot %s dpkg -l > %s/live/packages.txt' % (self.__live_fs_dir, self.__iso_fs_dir)) os.system('chroot %s dpkg-query -W --showformat=\'${Package} ${Version}\' > %s/live/packages.txt' %(self.__live_fs_dir, self.__iso_fs_dir)) self.log.info('Building squash filesystem: %s' % (self.__live_fs_filename)) if squash_tools.create_squash_fs(mksquashfs_cmd=self.__mksquash, source_dir=self.__live_fs_dir, dest_filename=self.__live_fs_filename, overwrite=True): if os.path.exists(self.__live_fs_filename): self.log.debug('Live squash filesystem complete: %s' % (self.__live_fs_filename)) return True else: self.log.error('Error creating squash filesystem; check log for details...') return False else: self.log.error('Error creating squash filesystem; check log for details...') return False except Exception, d: self.log.error('Error creating squash filesystem: %s : %s' % (self.__live_fs_filename, d)) return False
def build_live_fs(self): try: # update package manifest self.log.info('Updating Package manifests...') #os.system('chroot %s dpkg -l | awk \'{print $2\" \"$3}\' | tail -n +6 > %s/casper/filesystem.manifest' % (self.__live_fs_dir, self.__iso_fs_dir)) os.system('chroot %s dpkg-query -W --showformat=\'${Package} ${Version}\n\' > %s/casper/filesystem.manifest' %(self.__live_fs_dir, self.__iso_fs_dir)) os.system('sed -ie \'/ubiquity/d\' %s/casper/filesystem.manifest' % (self.__iso_fs_dir)) shutil.copy('%s/casper/filesystem.manifest' % (self.__iso_fs_dir), '%s/casper/filesystem.manifest-desktop' % (self.__iso_fs_dir)) self.log.info('Building squash filesystem: %s' % (self.__live_fs_filename)) if squash_tools.create_squash_fs(mksquashfs_cmd=self.__mksquash, source_dir=self.__live_fs_dir, dest_filename=self.__live_fs_filename, overwrite=True): if os.path.exists(self.__live_fs_filename): self.log.debug('Live squash filesystem complete: %s' % (self.__live_fs_filename)) return True else: self.log.error('Error creating squash filesystem; check log for details...') return False else: self.log.error('Error creating squash filesystem; check log for details...') return False except Exception, d: self.log.error('Error creating squash filesystem: %s : %s' % (self.__live_fs_filename, d)) return False
def build_live_fs(self): try: # update package manifest self.log.info('Updating Package manifests...') #os.system('chroot %s dpkg -l | awk \'{print $2\" \"$3}\' | tail -n +6 > %s/casper/filesystem.manifest' % (self.__live_fs_dir, self.__iso_fs_dir)) os.system('chroot %s dpkg-query -W --showformat=\'${Package} ${Version}\n\' > %s/casper/filesystem.manifest' %(self.__live_fs_dir, self.__iso_fs_dir)) os.system('sed -ie \'/ubiquity/d\' %s/casper/filesystem.manifest' % (self.__iso_fs_dir)) shutil.copy('%s/casper/filesystem.manifest' % (self.__iso_fs_dir), '%s/casper/filesystem.manifest-desktop' % (self.__iso_fs_dir)) self.log.info('Building squash filesystem: %s' % (self.__live_fs_filename)) if squash_tools.create_squash_fs(mksquashfs_cmd=self.__mksquash, source_dir=self.__live_fs_dir, dest_filename=self.__live_fs_filename, overwrite=True): if os.path.exists(self.__live_fs_filename): self.log.debug('Live squash filesystem complete: %s' % (self.__live_fs_filename)) return True else: self.log.error('Error creating squash filesystem; check log for details...') return False else: self.log.error('Error creating squash filesystem; check log for details...') return False except Exception, d: self.log.error('Error creating squash filesystem: %s : %s' % (self.__live_fs_filename, d)) return False
def testExtractSquashFs(self): self.assertTrue(squash_tools.create_squash_fs(source_dir=self.squash_root, dest_filename=self.squash_file, overwrite=True)) self.assertTrue(squash_tools.extract_squash_fs(filename=self.squash_file, dest_dir=self.tmp_squash_dir), 'Error extracting squash filesystem...') self.assertTrue(os.listdir(self.tmp_squash_dir) != 0, 'Error extracting squash filesystem: directory empty...')
def testCreateSquashFs(self): self.assertTrue(squash_tools.create_squash_fs(source_dir=self.squash_root, dest_filename=self.squash_file, overwrite=True)) self.assertTrue(os.path.exists(self.squash_file), 'Squash file does not exist...') self.assertTrue(len(self.squash_file) != 0)