Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename btrfs root is snapshot #2705

Merged
merged 2 commits into from
Jan 13, 2025
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
9 changes: 5 additions & 4 deletions doc/source/image_description/elements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -448,17 +448,18 @@ btrfs_root_is_subvolume="true|false":

By default the creation of a toplevel volume is set to: `true`

btrfs_root_is_snapshot="true|false":
btrfs_root_is_snapper_snapshot="true|false":
Boolean parameter that tells {kiwi} to install
the system into a btrfs snapshot. The snapshot layout is compatible with
snapper. By default snapshots are turned off.
the system into a btrfs snapshot. The snapshot layout is compatible
with the snapper management toolkit and follows a concept by SUSE.
By default snapshots are turned off.

btrfs_root_is_readonly_snapshot="true|false":
Boolean parameter notifying {kiwi} that
the btrfs root filesystem snapshot has to made read-only. if this option
is set to true, the root filesystem snapshot it will be turned into
read-only mode, once all data has been placed to it. The option is only
effective if `btrfs_root_is_snapshot` is also set to true. By default the
effective if `btrfs_root_is_snapper_snapshot` is also set to true. By default the
root filesystem snapshot is writable.

bootstrap_package="package_name":
Expand Down
2 changes: 1 addition & 1 deletion kiwi/boot/image/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def import_system_description_elements(self) -> None:
type_attributes = [
'bootkernel',
'bootprofile',
'btrfs_root_is_snapshot',
'btrfs_root_is_snapper_snapshot',
'gpt_hybrid_mbr',
'devicepersistency',
'filesystem',
Expand Down
2 changes: 1 addition & 1 deletion kiwi/bootloader/config/grub2.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ def _setup_default_grub(self):
)
if os.path.exists(os.sep.join([self.root_dir, theme_background])):
grub_default_entries['GRUB_BACKGROUND'] = theme_background
if self.xml_state.build_type.get_btrfs_root_is_snapshot():
if self.xml_state.build_type.get_btrfs_root_is_snapper_snapshot():
grub_default_entries['SUSE_BTRFS_SNAPSHOT_BOOTING'] = 'true'
if self.custom_args.get('crypto_disk'):
grub_default_entries['GRUB_ENABLE_CRYPTODISK'] = 'y'
Expand Down
16 changes: 8 additions & 8 deletions kiwi/builder/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ def __init__(
self.custom_root_creation_args,
'root_label':
self.disk_setup.get_root_label(),
'root_is_snapshot':
self.xml_state.build_type.get_btrfs_root_is_snapshot(),
'root_is_snapper_snapshot':
self.xml_state.build_type.get_btrfs_root_is_snapper_snapshot(),
'root_is_readonly_snapshot':
self.xml_state.build_type.get_btrfs_root_is_readonly_snapshot(),
'root_is_subvolume':
Expand Down Expand Up @@ -1308,14 +1308,14 @@ def _write_generic_fstab(
self, device_map: Dict, setup: SystemSetup,
system: Optional[Union[FileSystemBase, VolumeManagerBase]]
) -> None:
root_is_snapshot = \
self.xml_state.build_type.get_btrfs_root_is_snapshot()
root_is_snapper_snapshot = \
self.xml_state.build_type.get_btrfs_root_is_snapper_snapshot()
root_is_readonly_snapshot = \
self.xml_state.build_type.get_btrfs_root_is_readonly_snapshot()

fs_check_interval = '0 1'
custom_root_mount_args = list(self.custom_root_mount_args)
if root_is_snapshot and root_is_readonly_snapshot:
if root_is_snapper_snapshot and root_is_readonly_snapshot:
custom_root_mount_args += ['ro']
fs_check_interval = '0 0'

Expand Down Expand Up @@ -1788,11 +1788,11 @@ def _setup_property_root_is_readonly_snapshot(
self, system: Union[FileSystemBase, VolumeManagerBase]
) -> None:
if self.volume_manager_name:
root_is_snapshot = \
self.xml_state.build_type.get_btrfs_root_is_snapshot()
root_is_snapper_snapshot = \
self.xml_state.build_type.get_btrfs_root_is_snapper_snapshot()
root_is_readonly_snapshot = \
self.xml_state.build_type.get_btrfs_root_is_readonly_snapshot()
if root_is_snapshot and root_is_readonly_snapshot:
if root_is_snapper_snapshot and root_is_readonly_snapshot:
log.info(
'Setting root filesystem into read-only mode'
)
Expand Down
17 changes: 9 additions & 8 deletions kiwi/schema/kiwi.rnc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ div {
attribute xsi:schemaLocation { xsd:anyURI }
k.image.schemaversion.attribute =
## The allowed Schema version (fixed value)
attribute schemaversion { "8.2" }
attribute schemaversion { "8.3" }
k.image.id =
## An identification number which is represented in a file
## named /etc/ImageID
Expand Down Expand Up @@ -1524,20 +1524,21 @@ div {
sch:param [ name = "attr" value = "btrfs_root_is_subvolume" ]
sch:param [ name = "types" value = "oem" ]
]
k.type.btrfs_root_is_snapshot.attribute =
k.type.btrfs_root_is_snapper_snapshot.attribute =
## Tell kiwi to install the system into a btrfs snapshot
## The snapshot layout is compatible with the snapper management
## toolkit. By default no snapshots are used
attribute btrfs_root_is_snapshot { xsd:boolean }
>> sch:pattern [ id = "btrfs_root_is_snapshot" is-a = "image_type"
sch:param [ name = "attr" value = "btrfs_root_is_snapshot" ]
## toolkit and follows a concept by SUSE.
## By default no snapshots are used
attribute btrfs_root_is_snapper_snapshot { xsd:boolean }
>> sch:pattern [ id = "btrfs_root_is_snapper_snapshot" is-a = "image_type"
sch:param [ name = "attr" value = "btrfs_root_is_snapper_snapshot" ]
sch:param [ name = "types" value = "oem" ]
]
k.type.btrfs_root_is_readonly_snapshot.attribute =
## Tell kiwi to set the btrfs root filesystem snapshot read-only
## Once all data has been placed to the root filesystem snapshot
## it will be turned into read-only mode if this option is set to
## true. The option is only effective if btrfs_root_is_snapshot
## true. The option is only effective if btrfs_root_is_snapper_snapshot
## is also set to true. By default the root filesystem snapshot
## is writable
attribute btrfs_root_is_readonly_snapshot { xsd:boolean }
Expand Down Expand Up @@ -2354,7 +2355,7 @@ div {
k.type.dosparttable_extended_layout.attribute? &
k.type.bootprofile.attribute? &
k.type.btrfs_quota_groups.attribute? &
k.type.btrfs_root_is_snapshot.attribute? &
k.type.btrfs_root_is_snapper_snapshot.attribute? &
k.type.btrfs_root_is_subvolume.attribute? &
k.type.btrfs_set_default_volume.attribute? &
k.type.btrfs_root_is_readonly_snapshot.attribute? &
Expand Down
17 changes: 9 additions & 8 deletions kiwi/schema/kiwi.rng
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ second the location of the XSD Schema
<define name="k.image.schemaversion.attribute">
<attribute name="schemaversion">
<a:documentation>The allowed Schema version (fixed value)</a:documentation>
<value>8.2</value>
<value>8.3</value>
</attribute>
</define>
<define name="k.image.id">
Expand Down Expand Up @@ -2255,15 +2255,16 @@ By default the creation of a root subvolume is set to: true</a:documentation>
<sch:param name="types" value="oem"/>
</sch:pattern>
</define>
<define name="k.type.btrfs_root_is_snapshot.attribute">
<attribute name="btrfs_root_is_snapshot">
<define name="k.type.btrfs_root_is_snapper_snapshot.attribute">
<attribute name="btrfs_root_is_snapper_snapshot">
<a:documentation>Tell kiwi to install the system into a btrfs snapshot
The snapshot layout is compatible with the snapper management
toolkit. By default no snapshots are used</a:documentation>
toolkit and follows a concept by SUSE.
By default no snapshots are used</a:documentation>
<data type="boolean"/>
</attribute>
<sch:pattern id="btrfs_root_is_snapshot" is-a="image_type">
<sch:param name="attr" value="btrfs_root_is_snapshot"/>
<sch:pattern id="btrfs_root_is_snapper_snapshot" is-a="image_type">
<sch:param name="attr" value="btrfs_root_is_snapper_snapshot"/>
<sch:param name="types" value="oem"/>
</sch:pattern>
</define>
Expand All @@ -2272,7 +2273,7 @@ toolkit. By default no snapshots are used</a:documentation>
<a:documentation>Tell kiwi to set the btrfs root filesystem snapshot read-only
Once all data has been placed to the root filesystem snapshot
it will be turned into read-only mode if this option is set to
true. The option is only effective if btrfs_root_is_snapshot
true. The option is only effective if btrfs_root_is_snapper_snapshot
is also set to true. By default the root filesystem snapshot
is writable</a:documentation>
<data type="boolean"/>
Expand Down Expand Up @@ -3405,7 +3406,7 @@ kiwi-ng result bundle ...</a:documentation>
<ref name="k.type.btrfs_quota_groups.attribute"/>
</optional>
<optional>
<ref name="k.type.btrfs_root_is_snapshot.attribute"/>
<ref name="k.type.btrfs_root_is_snapper_snapshot.attribute"/>
</optional>
<optional>
<ref name="k.type.btrfs_root_is_subvolume.attribute"/>
Expand Down
6 changes: 3 additions & 3 deletions kiwi/system/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def _type_to_profile(self):
# kiwi_fsmountoptions
# kiwi_bootprofile
# kiwi_vga
# kiwi_btrfs_root_is_snapshot
# kiwi_btrfs_root_is_snapper_snapshot
# kiwi_startsector
type_section = self.xml_state.build_type
self.dot_profile['kiwi_type'] = \
Expand Down Expand Up @@ -322,8 +322,8 @@ def _type_to_profile(self):
self.xml_state.get_build_type_bootloader_console()[0] or 'default',
self.xml_state.get_build_type_bootloader_console()[1] or 'default'
)
self.dot_profile['kiwi_btrfs_root_is_snapshot'] = \
type_section.get_btrfs_root_is_snapshot()
self.dot_profile['kiwi_btrfs_root_is_snapper_snapshot'] = \
type_section.get_btrfs_root_is_snapper_snapshot()
self.dot_profile['kiwi_gpt_hybrid_mbr'] = \
type_section.get_gpt_hybrid_mbr()
self.dot_profile['kiwi_devicepersistency'] = \
Expand Down
33 changes: 17 additions & 16 deletions kiwi/volume_manager/btrfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ def post_init(self, custom_args):
self.custom_args = {}
if 'root_label' not in 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 'root_is_snapper_snapshot' not in self.custom_args:
self.custom_args['root_is_snapper_snapshot'] = False
if 'btrfs_default_volume_requested' not in self.custom_args:
self.custom_args['btrfs_default_volume_requested'] = True
if 'root_is_readonly_snapshot' not in self.custom_args:
Expand All @@ -86,11 +86,11 @@ def post_init(self, custom_args):
self.root_volume_name = volume.name
self.default_volume_name = self.root_volume_name

if self.custom_args['root_is_snapshot'] and \
if self.custom_args['root_is_snapper_snapshot'] and \
self.root_volume_name == '/':
log.warning('root_is_snapshot requires a toplevel sub-volume')
log.warning('root_is_snapshot has been disabled')
self.custom_args['root_is_snapshot'] = False
log.warning('root_is_snapper_snapshot requires a toplevel sub-volume')
log.warning('root_is_snapper_snapshot has been disabled')
self.custom_args['root_is_snapper_snapshot'] = False

self.subvol_mount_list = []
self.toplevel_mount = None
Expand Down Expand Up @@ -134,7 +134,7 @@ def setup(self, name=None):
Command.run(
['btrfs', 'subvolume', 'create', root_volume]
)
if self.custom_args['root_is_snapshot']:
if self.custom_args['root_is_snapper_snapshot']:
snapshot_volume = self.mountpoint + \
f'/{self.root_volume_name}/.snapshots'
Command.run(
Expand Down Expand Up @@ -233,7 +233,8 @@ def create_volumes(self, filesystem_name):
)

volume_mountpoint = toplevel
root_is_snapshot = self.custom_args['root_is_snapshot']
root_is_snapper_snapshot = \
self.custom_args['root_is_snapper_snapshot']

attributes = {
'parent': volume.parent or '',
Expand All @@ -244,7 +245,7 @@ def create_volumes(self, filesystem_name):
).lstrip(os.sep),
'subvol_name': volume.name
}
if root_is_snapshot:
if root_is_snapper_snapshot:
volume_mountpoint = self.mountpoint + \
f'/{self.root_volume_name}/.snapshots/1/snapshot/'
attributes = {
Expand All @@ -263,7 +264,7 @@ def create_volumes(self, filesystem_name):
os.sep.join(
[
volume_mountpoint,
self.root_volume_name if not root_is_snapshot else '',
self.root_volume_name if not root_is_snapper_snapshot else '',
volume.realpath
]
)
Expand Down Expand Up @@ -397,7 +398,7 @@ def get_mountpoint(self) -> str:
sync_target: List[str] = [self.mountpoint]
if self.root_volume_name != '/':
sync_target.append(self.root_volume_name)
if self.custom_args.get('root_is_snapshot'):
if self.custom_args.get('root_is_snapper_snapshot'):
sync_target.extend(['.snapshots', '1', 'snapshot'])
return os.path.join(*sync_target)

Expand All @@ -412,7 +413,7 @@ def sync_data(self, exclude=None):
"""
if self.toplevel_mount:
sync_target = self.get_mountpoint()
if self.custom_args['root_is_snapshot']:
if self.custom_args['root_is_snapper_snapshot']:
self._create_snapshot_info(
''.join(
[
Expand All @@ -426,18 +427,18 @@ def sync_data(self, exclude=None):
options=Defaults.get_sync_options(), exclude=exclude
)
if self.custom_args['quota_groups'] and \
self.custom_args['root_is_snapshot']:
self.custom_args['root_is_snapper_snapshot']:
self._create_snapper_quota_configuration()

def set_property_readonly_root(self):
"""
Sets the root volume to be a readonly filesystem
"""
root_is_snapshot = \
self.custom_args['root_is_snapshot']
root_is_snapper_snapshot = \
self.custom_args['root_is_snapper_snapshot']
root_is_readonly_snapshot = \
self.custom_args['root_is_readonly_snapshot']
if root_is_snapshot and root_is_readonly_snapshot:
if root_is_snapper_snapshot and root_is_readonly_snapshot:
sync_target = self.get_mountpoint()
Command.run(
['btrfs', 'property', 'set', sync_target, 'ro', 'true']
Expand Down
Loading
Loading