Skip to content

Commit

Permalink
add btrfs_set_default_volume attribute
Browse files Browse the repository at this point in the history
By default kiwi runs btrfs set-default on the volume that is
considered the default volume according to the btrfs settings
and defaults. btrfs_set_default_volume="false" allows
to deactivate this action. Along with the change also the
misleading name of the btrfs_create_toplevel_subvolume has
been changed to root_is_subvolume
  • Loading branch information
schaefi committed Jul 27, 2023
1 parent f8f1c00 commit 8e90ede
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 69 deletions.
18 changes: 13 additions & 5 deletions doc/source/image_description/elements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,19 @@ btrfs_quota_groups="true|false":
Boolean parameter to activate filesystem quotas if
the filesystem is `btrfs`. By default quotas are inactive.

btrfs_create_toplevel_subvolume="true|false":
Tell kiwi to nest all subvolumes below a toplevel volume.
The name of this toplevel volume is by default set to: `@`
The name of the toplevel volume can be changed via
a volume entry of the form
btrfs_set_default_volume="true|false":
Tell kiwi to explicitly make a volume the default volume
This can be either `/` or the root subvolume or the root
snapshot depending on the specified btrfs configuration
attributes. By default btrfs_set_default_volume is set to: true
If no default volume should be set, this attribute can be
used to turn it off

btrfs_root_is_subvolume="true|false":
Tell kiwi to create a root volume to host (/) inside.
The name of this subvolume is by default set to: `@`.
The name of the subvolume can be changed via a volume entry
of the form:

.. code:: xml
Expand Down
7 changes: 5 additions & 2 deletions kiwi/builder/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,12 @@ def create_disk(self) -> Result:
'root_is_readonly_snapshot':
self.xml_state.build_type.
get_btrfs_root_is_readonly_snapshot(),
'create_toplevel_subvolume':
'root_is_subvolume':
self.xml_state.build_type.
get_btrfs_create_toplevel_subvolume(),
get_btrfs_root_is_subvolume(),
'set_default_volume':
self.xml_state.build_type.
get_btrfs_set_default_volume(),
'quota_groups':
self.xml_state.build_type.get_btrfs_quota_groups(),
'resize_on_boot':
Expand Down
33 changes: 23 additions & 10 deletions kiwi/schema/kiwi.rnc
Original file line number Diff line number Diff line change
Expand Up @@ -1433,15 +1433,27 @@ div {
sch:param [ name = "attr" value = "btrfs_quota_groups" ]
sch:param [ name = "types" value = "oem" ]
]
k.type.btrfs_create_toplevel_subvolume =
## Tell kiwi to nest all subvolumes below a toplevel volume.
## The name of this toplevel volume is by default set to: '@'
## The name of the toplevel volume can be changed via
## a volume entry of the form '<volume name="@root=TOPLEVEL_NAME"/>'
## By default the creation of a toplevel volume is set to: true
attribute btrfs_create_toplevel_subvolume { xsd:boolean }
>> sch:pattern [ id = "btrfs_create_toplevel_subvolume" is-a = "image_type"
sch:param [ name = "attr" value = "btrfs_create_toplevel_subvolume" ]
k.type.btrfs_set_default_volume.attribute =
## Tell kiwi to explicitly make a volume the default volume
## This can be either (/) or the root subvolume or the root
## snapshot depending on the specified btrfs configuration
## attributes. By default btrfs_set_default_volume is set to: true
## If no default volume should be set, this attribute can be
## used to turn it off
attribute btrfs_set_default_volume { xsd:boolean }
>> sch:pattern [ id = "btrfs_set_default_volume" is-a = "image_type"
sch:param [ name = "attr" value = "btrfs_set_default_volume" ]
sch:param [ name = "types" value = "oem" ]
]
k.type.btrfs_root_is_subvolume.attribute =
## Tell kiwi to create a root volume to host (/) inside.
## The name of this subvolume is by default set to: '@'
## The name of the subvolume can be changed via
## a volume entry of the form '<volume name="@root=NAME"/>'
## By default the creation of a root subvolume is set to: true
attribute btrfs_root_is_subvolume { xsd:boolean }
>> sch:pattern [ id = "btrfs_root_is_subvolume" is-a = "image_type"
sch:param [ name = "attr" value = "btrfs_root_is_subvolume" ]
sch:param [ name = "types" value = "oem" ]
]
k.type.btrfs_root_is_snapshot.attribute =
Expand Down Expand Up @@ -2229,7 +2241,8 @@ div {
k.type.bootprofile.attribute? &
k.type.btrfs_quota_groups.attribute? &
k.type.btrfs_root_is_snapshot.attribute? &
k.type.btrfs_create_toplevel_subvolume? &
k.type.btrfs_root_is_subvolume.attribute? &
k.type.btrfs_set_default_volume.attribute? &
k.type.btrfs_root_is_readonly_snapshot.attribute? &
k.type.compressed.attribute? &
k.type.devicepersistency.attribute? &
Expand Down
38 changes: 28 additions & 10 deletions kiwi/schema/kiwi.rng
Original file line number Diff line number Diff line change
Expand Up @@ -2093,17 +2093,32 @@ By default the quota system is inactive</a:documentation>
<sch:param name="types" value="oem"/>
</sch:pattern>
</define>
<define name="k.type.btrfs_create_toplevel_subvolume">
<attribute name="btrfs_create_toplevel_subvolume">
<a:documentation>Tell kiwi to nest all subvolumes below a toplevel volume.
The name of this toplevel volume is by default set to: '@'
The name of the toplevel volume can be changed via
a volume entry of the form '&lt;volume name="@root=TOPLEVEL_NAME"/&gt;'
By default the creation of a toplevel volume is set to: true</a:documentation>
<define name="k.type.btrfs_set_default_volume.attribute">
<attribute name="btrfs_set_default_volume">
<a:documentation>Tell kiwi to explicitly make a volume the default volume
This can be either (/) or the root subvolume or the root
snapshot depending on the specified btrfs configuration
attributes. By default btrfs_set_default_volume is set to: true
If no default volume should be set, this attribute can be
used to turn it off</a:documentation>
<data type="boolean"/>
</attribute>
<sch:pattern id="btrfs_create_toplevel_subvolume" is-a="image_type">
<sch:param name="attr" value="btrfs_create_toplevel_subvolume"/>
<sch:pattern id="btrfs_set_default_volume" is-a="image_type">
<sch:param name="attr" value="btrfs_set_default_volume"/>
<sch:param name="types" value="oem"/>
</sch:pattern>
</define>
<define name="k.type.btrfs_root_is_subvolume.attribute">
<attribute name="btrfs_root_is_subvolume">
<a:documentation>Tell kiwi to create a root volume to host (/) inside.
The name of this subvolume is by default set to: '@'
The name of the subvolume can be changed via
a volume entry of the form '&lt;volume name="@root=NAME"/&gt;'
By default the creation of a root subvolume is set to: true</a:documentation>
<data type="boolean"/>
</attribute>
<sch:pattern id="btrfs_root_is_subvolume" is-a="image_type">
<sch:param name="attr" value="btrfs_root_is_subvolume"/>
<sch:param name="types" value="oem"/>
</sch:pattern>
</define>
Expand Down Expand Up @@ -3192,7 +3207,10 @@ kiwi-ng result bundle ...</a:documentation>
<ref name="k.type.btrfs_root_is_snapshot.attribute"/>
</optional>
<optional>
<ref name="k.type.btrfs_create_toplevel_subvolume"/>
<ref name="k.type.btrfs_root_is_subvolume.attribute"/>
</optional>
<optional>
<ref name="k.type.btrfs_set_default_volume.attribute"/>
</optional>
<optional>
<ref name="k.type.btrfs_root_is_readonly_snapshot.attribute"/>
Expand Down
55 changes: 29 additions & 26 deletions kiwi/volume_manager/btrfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ def post_init(self, custom_args):
self.custom_args['root_label'] = 'ROOT'
if 'root_is_snapshot' not in self.custom_args:
self.custom_args['root_is_snapshot'] = False
if 'set_default_volume' not in self.custom_args:
self.custom_args['set_default_volume'] = True
if 'root_is_readonly_snapshot' not in self.custom_args:
self.custom_args['root_is_readonly_snapshot'] = False
if 'create_toplevel_subvolume' not in self.custom_args:
self.custom_args['create_toplevel_subvolume'] = None
if 'root_is_subvolume' not in self.custom_args:
self.custom_args['root_is_subvolume'] = None
if 'quota_groups' not in self.custom_args:
self.custom_args['quota_groups'] = False

Expand Down Expand Up @@ -444,18 +446,18 @@ def set_property_readonly_root(self):
)

def _has_root_volume(self) -> bool:
has_root_volume = bool(self.custom_args['create_toplevel_subvolume'])
if self.custom_args['create_toplevel_subvolume'] is None:
# toplevel volume not explicitly configured, will
has_root_volume = bool(self.custom_args['root_is_subvolume'])
if self.custom_args['root_is_subvolume'] is None:
# root volume not explicitly configured, will
# be enabled by default but this is going to change
# in the future. Print a deprecation message to inform
# the user about a potential behavior change
log.warning("Implicitly creating a toplevel volume")
log.warning("Implicitly creating root volume")
log.warning(
"--> Future versions of kiwi will not do this anymore"
)
log.warning(
"--> Please specify btrfs_create_toplevel_subvolume true|false"
"--> Please specify btrfs_root_is_subvolume true|false"
)
has_root_volume = True
return has_root_volume
Expand All @@ -468,26 +470,27 @@ def _is_volume_enabled_for_fs_check(self, mountpoint):
return False

def _set_default_volume(self, default_volume):
subvolume_list_call = Command.run(
['btrfs', 'subvolume', 'list', self.mountpoint]
)
for subvolume in subvolume_list_call.output.split('\n'):
id_search = re.search('ID (\d+) .*path (.*)', subvolume)
if id_search:
volume_id = id_search.group(1)
volume_path = id_search.group(2)
if volume_path == default_volume:
Command.run(
[
'btrfs', 'subvolume', 'set-default',
volume_id, self.mountpoint
]
)
return
if self.custom_args['set_default_volume']:
subvolume_list_call = Command.run(
['btrfs', 'subvolume', 'list', self.mountpoint]
)
for subvolume in subvolume_list_call.output.split('\n'):
id_search = re.search('ID (\d+) .*path (.*)', subvolume)
if id_search:
volume_id = id_search.group(1)
volume_path = id_search.group(2)
if volume_path == default_volume:
Command.run(
[
'btrfs', 'subvolume', 'set-default',
volume_id, self.mountpoint
]
)
return

raise KiwiVolumeRootIDError(
'Failed to find btrfs volume: %s' % default_volume
)
raise KiwiVolumeRootIDError(
'Failed to find btrfs volume: %s' % default_volume
)

def _xml_pretty(self, toplevel_element):
xml_data_unformatted = ElementTree.tostring(
Expand Down
Loading

0 comments on commit 8e90ede

Please sign in to comment.