Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/source/commands/kiwi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ SYNOPSIS

kiwi-ng -h | --help
kiwi-ng [--profile=<name>...]
[--setenv=<variable=value>...]
[--temp-dir=<directory>]
[--type=<build_type>]
[--logfile=<filename>]
Expand All @@ -32,6 +33,7 @@ SYNOPSIS
[--config=<configfile>]
result <command> [<args>...]
kiwi-ng [--profile=<name>...]
[--setenv=<variable=value>...]
[--shared-cache-dir=<directory>]
[--temp-dir=<directory>]
[--target-arch=<name>]
Expand Down Expand Up @@ -143,6 +145,11 @@ GLOBAL OPTIONS
XML description. The option can be specified multiple times to
allow a combination of profiles.

--setenv=<variable=value>

export environment variable and its value into the caller
environment. This option can be specified multiple times

--shared-cache-dir=<directory>

Specify an alternative shared cache directory. The directory
Expand Down
9 changes: 7 additions & 2 deletions doc/source/working_with_images/custom_partitions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,17 @@ size="size_string"
specification mega-Byte is used.

mountpoint="path"
Mandatory mountpoint to mount the partition in the system.
Optional mountpoint to mount the partition in the system.

filesystem="btrfs|ext2|ext3|ext4|squashfs|xfs
Mandatory filesystem configuration to create one of the supported
Optional filesystem configuration to create one of the supported
filesystems on the partition.

label="string"
Optional filesystem label if a filesystem is provided. If no
label is specified the `name` identifier is set as filesystem
label

clone="number"
Optional setting to indicate that this partition should be
cloned `number` of times. A clone partition is content wise an
Expand Down
3 changes: 2 additions & 1 deletion kiwi/builder/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,7 @@ def _build_custom_parts_filesystem(
squashed_root_file = Temporary().new_file()
filesystem.create_on_file(
filename=squashed_root_file.name,
label=ptable_entry.label,
exclude=[Defaults.get_shared_cache_location()]
)
readonly_target = device_map[map_name].get_device()
Expand All @@ -1034,7 +1035,7 @@ def _build_custom_parts_filesystem(
)
else:
filesystem.create_on_device(
label=map_name.upper()
label=ptable_entry.label or map_name.upper()
)
filesystem_dict[map_name] = filesystem
return filesystem_dict
Expand Down
5 changes: 5 additions & 0 deletions kiwi/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"""
usage: kiwi-ng -h | --help
kiwi-ng [--profile=<name>...]
[--setenv=<variable=value>...]
[--temp-dir=<directory>]
[--target-arch=<name>]
[--type=<build_type>]
Expand All @@ -39,6 +40,7 @@
[--config=<configfile>]
result <command> [<args>...]
kiwi-ng [--profile=<name>...]
[--setenv=<variable=value>...]
[--shared-cache-dir=<directory>]
[--temp-dir=<directory>]
[--target-arch=<name>]
Expand Down Expand Up @@ -89,6 +91,9 @@
--profile=<name>
profile name, multiple profiles can be selected by passing
this option multiple times
--setenv=<variable=value>
export environment variable and its value into the caller
environment. This option can be specified multiple times
--shared-cache-dir=<directory>
specify an alternative shared cache directory. The directory
is shared via bind mount between the build host and image
Expand Down
25 changes: 25 additions & 0 deletions kiwi/filesystem/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
# along with kiwi. If not, see <http://www.gnu.org/licenses/>
#
import os
import uuid
import random
import logging
import copy
from functools import reduce
from typing import (
Dict, List, Optional
)
Expand Down Expand Up @@ -316,6 +319,28 @@ def set_property_readonly_root(self) -> None:
"""
raise NotImplementedError

def _generate_seed_uuid(self, label: str, random_bits: int = 128) -> str:
"""
Create random UUID. If SOURCE_DATE_EPOCH is present use
SOURCE_DATE_EPOCH + label name as seed
"""
sde = os.environ.get('SOURCE_DATE_EPOCH')
if sde:
label_seed = reduce(lambda x, y: x + y, map(ord, label))
epoch_seed = label_seed + int(sde)
log.info(
'Using UUID seed SOURCE_DATE_EPOCH:{0} + LABEL:{1}={2}'.format(
sde, label, label_seed
)
)
rd = random.Random()
rd.seed(epoch_seed)
return format(
uuid.UUID(int=rd.getrandbits(random_bits))
)
else:
return format(uuid.uuid4())

def _map_size(self, size: float, from_unit: str, to_unit: str) -> float:
"""
Return byte size value for given size and unit
Expand Down
17 changes: 10 additions & 7 deletions kiwi/filesystem/btrfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,26 @@ def create_on_device(
:param str uuid: UUID name
"""
device = self.device_provider.get_device()
call_args = self.custom_args['create_options'].copy()
if not uuid and label:
uuid = self._generate_seed_uuid(label)
if label:
self.custom_args['create_options'].append('-L')
self.custom_args['create_options'].append(label)
call_args.append('-L')
call_args.append(label)
if uuid:
self.custom_args['create_options'].append('-U')
self.custom_args['create_options'].append(uuid)
call_args.append('-U')
call_args.append(uuid)
if size:
self.custom_args['create_options'].append('--byte-count')
self.custom_args['create_options'].append(
call_args.append('--byte-count')
call_args.append(
self._fs_size(
size=self._map_size(
size, from_unit=unit, to_unit=defaults.UNIT.byte
), unit=defaults.UNIT.byte
)
)
Command.run(
['mkfs.btrfs'] + self.custom_args['create_options'] + [device]
['mkfs.btrfs'] + call_args + [device]
)

def set_uuid(self):
Expand Down
11 changes: 6 additions & 5 deletions kiwi/filesystem/erofs.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ def create_on_file(
self.filename = filename
exclude_options = []
compression = self.custom_args.get('compression')
call_args = self.custom_args['create_options'].copy()
if compression:
self.custom_args['create_options'].append('-z')
self.custom_args['create_options'].append(compression)
call_args.append('-z')
call_args.append(compression)

if exclude:
for item in exclude:
Expand All @@ -53,13 +54,13 @@ def create_on_file(
exclude_options.append(f'--exclude-regex={as_regex}')

if label:
self.custom_args['create_options'].append('-L')
self.custom_args['create_options'].append(label)
call_args.append('-L')
call_args.append(label)

Command.run(
[
'mkfs.erofs'
] + self.custom_args['create_options'] + exclude_options + [
] + call_args + exclude_options + [
self.filename, self.root_dir
]
)
13 changes: 8 additions & 5 deletions kiwi/filesystem/ext2.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ def create_on_device(
:param str uuid: UUID name
"""
device_args = [self.device_provider.get_device()]
call_args = self.custom_args['create_options'].copy()
if not uuid and label:
uuid = self._generate_seed_uuid(label)
if label:
self.custom_args['create_options'].append('-L')
self.custom_args['create_options'].append(label)
call_args.append('-L')
call_args.append(label)
if uuid:
self.custom_args['create_options'].append('-U')
self.custom_args['create_options'].append(uuid)
call_args.append('-U')
call_args.append(uuid)
if size:
device_args.append(
self._fs_size(
Expand All @@ -57,7 +60,7 @@ def create_on_device(
)
)
Command.run(
['mkfs.ext2'] + self.custom_args['create_options'] + device_args
['mkfs.ext2'] + call_args + device_args
)

def set_uuid(self):
Expand Down
13 changes: 8 additions & 5 deletions kiwi/filesystem/ext3.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ def create_on_device(
:param str uuid: UUID name
"""
device_args = [self.device_provider.get_device()]
call_args = self.custom_args['create_options'].copy()
if not uuid and label:
uuid = self._generate_seed_uuid(label)
if label:
self.custom_args['create_options'].append('-L')
self.custom_args['create_options'].append(label)
call_args.append('-L')
call_args.append(label)
if uuid:
self.custom_args['create_options'].append('-U')
self.custom_args['create_options'].append(uuid)
call_args.append('-U')
call_args.append(uuid)
if size:
device_args.append(
self._fs_size(
Expand All @@ -57,7 +60,7 @@ def create_on_device(
)
)
Command.run(
['mkfs.ext3'] + self.custom_args['create_options'] + device_args
['mkfs.ext3'] + call_args + device_args
)

def set_uuid(self):
Expand Down
13 changes: 8 additions & 5 deletions kiwi/filesystem/ext4.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ def create_on_device(
:param str uuid: UUID name
"""
device_args = [self.device_provider.get_device()]
call_args = self.custom_args['create_options'].copy()
if not uuid and label:
uuid = self._generate_seed_uuid(label)
if label:
self.custom_args['create_options'].append('-L')
self.custom_args['create_options'].append(label)
call_args.append('-L')
call_args.append(label)
if uuid:
self.custom_args['create_options'].append('-U')
self.custom_args['create_options'].append(uuid)
call_args.append('-U')
call_args.append(uuid)
if size:
device_args.append(
self._fs_size(
Expand All @@ -57,7 +60,7 @@ def create_on_device(
)
)
Command.run(
['mkfs.ext4'] + self.custom_args['create_options'] + device_args
['mkfs.ext4'] + call_args + device_args
)

def set_uuid(self):
Expand Down
14 changes: 9 additions & 5 deletions kiwi/filesystem/fat16.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# along with kiwi. If not, see <http://www.gnu.org/licenses/>

# project
from uuid import UUID
import kiwi.defaults as defaults

from kiwi.filesystem.base import FileSystemBase
Expand All @@ -42,12 +43,15 @@ def create_on_device(
:param str uuid: Volume Label, there is no real UUID on fat
"""
device_args = [self.device_provider.get_device()]
call_args = self.custom_args['create_options'].copy()
if not uuid and label:
uuid = self._generate_seed_uuid(label)
if label:
self.custom_args['create_options'].append('-n')
self.custom_args['create_options'].append(label)
call_args.append('-n')
call_args.append(label)
if uuid:
self.custom_args['create_options'].append('-i')
self.custom_args['create_options'].append(uuid)
call_args.append('-i')
call_args.append(f'{UUID(uuid).time_low:08X}')
if size:
device_args.append(
self._fs_size(
Expand All @@ -59,7 +63,7 @@ def create_on_device(
Command.run(
[
'mkdosfs', '-F16', '-I'
] + self.custom_args['create_options'] + device_args
] + call_args + device_args
)

def set_uuid(self):
Expand Down
14 changes: 9 additions & 5 deletions kiwi/filesystem/fat32.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# along with kiwi. If not, see <http://www.gnu.org/licenses/>

# project
from uuid import UUID
import kiwi.defaults as defaults

from kiwi.filesystem.base import FileSystemBase
Expand All @@ -42,12 +43,15 @@ def create_on_device(
:param str uuid: Volume Label, there is no real UUID on fat
"""
device_args = [self.device_provider.get_device()]
call_args = self.custom_args['create_options'].copy()
if not uuid and label:
uuid = self._generate_seed_uuid(label)
if label:
self.custom_args['create_options'].append('-n')
self.custom_args['create_options'].append(label)
call_args.append('-n')
call_args.append(label)
if uuid:
self.custom_args['create_options'].append('-i')
self.custom_args['create_options'].append(uuid)
call_args.append('-i')
call_args.append(f'{UUID(uuid).time_low:08X}')
if size:
device_args.append(
self._fs_size(
Expand All @@ -59,7 +63,7 @@ def create_on_device(
Command.run(
[
'mkdosfs', '-F32', '-I'
] + self.custom_args['create_options'] + device_args
] + call_args + device_args
)

def set_uuid(self):
Expand Down
Loading