I tried this to solve this issue:
def _unpack_generic_initrd(self): initrd_path = os.path.join( 'usr', 'lib', 'ubuntu-core-generic-initrd', 'initrd.img-core') initrd_unpacked_path = os.path.join(self.builddir, 'initrd-staging') if os.path.exists(initrd_unpacked_path): shutil.rmtree(initrd_unpacked_path) os.makedirs(initrd_unpacked_path)
with tempfile.TemporaryDirectory() as temp_dir: subprocess.check_call([ 'unsquashfs', self.os_snap, os.path.dirname(initrd_path)], cwd=temp_dir)
result = subprocess.check_call( 'file {} --mime-type'.format( os.path.join(temp_dir, 'squashfs-root', initrd_path)), cwd=initrd_unpacked_path) mime_type = result.split()[-1] decompressor = 'gzip' if "gzip" in mime_type: decompressor = 'gzip' elif "x-xz" in mime_type: decompressor = 'xz'
subprocess.check_call( 'cat {0} | {1} -dc | cpio -i'.format( os.path.join(temp_dir, 'squashfs-root', initrd_path), decompressor), shell=True, cwd=initrd_unpacked_path)
return initrd_unpacked_path
I tried this to solve this issue:
def _unpack_ generic_ initrd( self): core-generic- initrd' , 'initrd.img-core')
initrd_ unpacked_ path = os.path. join(self. builddir, 'initrd-staging') exists( initrd_ unpacked_ path):
shutil. rmtree( initrd_ unpacked_ path)
os.makedirs( initrd_ unpacked_ path)
initrd_path = os.path.join(
'usr', 'lib', 'ubuntu-
if os.path.
with tempfile. TemporaryDirect ory() as temp_dir:
subprocess .check_ call([
'unsquashfs' , self.os_snap, os.path. dirname( initrd_ path)],
cwd=temp_ dir)
result = subprocess. check_call(
'file {} --mime- type'.format(
os. path.join( temp_dir, 'squashfs-root', initrd_path)),
cwd=initrd_ unpacked_ path)
mime_ type = result.split()[-1]
decompress or = 'gzip'
decompressor = 'gzip'
decompressor = 'xz'
if "gzip" in mime_type:
elif "x-xz" in mime_type:
return initrd_ unpacked_ path