Skip to content

Commit

Permalink
Add compression.erofs section to lorax.conf
Browse files Browse the repository at this point in the history
Set the default compression style to lzma and use the config values when
creating the erofs compressed rootfs.
  • Loading branch information
bcl committed Jul 15, 2024
1 parent 51d7da5 commit 04de3e5
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions src/pylorax/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ def configure(self, conf_file="/etc/lorax/lorax.conf"):
self.conf.set("compression", "args", "")
self.conf.set("compression", "bcj", "on")

self.conf.add_section("compression.erofs")
self.conf.set("compression.erofs", "type", "lzma")
self.conf.set("compression.erofs", "args", "")

# read the config file
if os.path.isfile(conf_file):
self.conf.read(conf_file)
Expand Down Expand Up @@ -210,6 +214,24 @@ def init_file_logging(self, logdir, logname="pylorax.log"):
fh.setLevel(logging.DEBUG)
logger.addHandler(fh)

def squashfs_args(self):
"""Return compression type and args for squashfs compression"""
compression = self.conf.get("compression", "type")
compressargs = self.conf.get("compression", "args").split() # pylint: disable=no-member
if self.conf.getboolean("compression", "bcj"):
if self.arch.bcj:
compressargs += ["-Xbcj", self.arch.bcj]
else:
logger.info("no BCJ filter for arch %s", self.arch.basearch)

return (compression, compressargs)

def erofs_args(self):
"""Return compression type and args for erofs compression"""
compression = self.conf.get("compression.erofs", "type")
compressargs = self.conf.get("compression.erofs", "args").split() # pylint: disable=no-member
return (compression, compressargs)

def run(self, dbo, product, version, release, variant="", bugurl="",
isfinal=False, workdir=None, outputdir=None, buildarch=None, volid=None,
domacboot=True, doupgrade=True, remove_temp=False,
Expand Down Expand Up @@ -348,34 +370,29 @@ def run(self, dbo, product, version, release, variant="", bugurl="",

logger.info("creating the runtime image")
runtime = "images/install.img"
compression = self.conf.get("compression", "type")
compressargs = self.conf.get("compression", "args").split() # pylint: disable=no-member
if self.conf.getboolean("compression", "bcj"):
if self.arch.bcj:
compressargs += ["-Xbcj", self.arch.bcj]
else:
logger.info("no BCJ filter for arch %s", self.arch.basearch)
if rootfs_type == "squashfs":
# Create a squashfs compressed rootfs.img
compression, compressargs = self.squashfs_args()
rc = rb.create_squashfs_runtime(joinpaths(installroot,runtime),
compression=compression, compressargs=compressargs,
size=size)
elif rootfs_type == "squashfs-ext4":
# Create an ext4 rootfs.img and compress it with squashfs
compression, compressargs = self.squashfs_args()
rc = rb.create_ext4_runtime(joinpaths(installroot,runtime),
compression=compression, compressargs=compressargs,
size=size)
elif rootfs_type == "erofs":
# Create a erofs compressed rootfs.img
# NOTE it does not support the same compression args as the other options
# so they are not passed to it.
compression, compressargs = self.erofs_args()
rc = rb.create_erofs_runtime(joinpaths(installroot,runtime),
compression=compression, compressargs=compressargs,
size=size)
elif rootfs_type == "erofs-ext4":
# Create an ext4 rootfs.img and compress it with erofs
# NOTE it does not support the same compression args as the other options
# so they are not passed to it.
compression, compressargs = self.erofs_args()
rc = rb.create_erofs_ext4_runtime(joinpaths(installroot,runtime),
compression=compression, compressargs=compressargs,
size=size)
else:
raise RuntimeError(f"{rootfs_type} is not a supported type for the root filesystem")
Expand Down

0 comments on commit 04de3e5

Please sign in to comment.