Skip to content

Commit

Permalink
Allow custom root volume name setup
Browse files Browse the repository at this point in the history
In addition to the custom size of the root volume it's now
also possible to setup the name of the root volume as follows:

    <volume name="@root=rootlv"/>

If no name for the root volume is specified the default
name: LVRoot applies as before. This Fixes #1530
  • Loading branch information
schaefi committed Oct 27, 2020
1 parent b63ec54 commit a124d82
Show file tree
Hide file tree
Showing 17 changed files with 216 additions and 80 deletions.
10 changes: 10 additions & 0 deletions doc/source/working_with_images/custom_volumes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ attributes:
<volume name="@root" size="4G"/>
In addition to the custom size of the root volume it's also possible
to setup the name of the root volume as follows:

.. code:: xml
<volume name="@root=rootlv" size="4G"/>
If no name for the root volume is specified the
default name: **LVRoot** applies.

- `freespace`: Optional attribute defining the additional free space added
to the volume. If no suffix (`M` or `G`) is used, the value is considered
to be in megabytes.
Expand Down
7 changes: 0 additions & 7 deletions dracut/modules.d/99kiwi-lib/kiwi-lvm-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -152,26 +152,19 @@ function read_volume_setup_all_free {
local volume
local name
local mpoint
local have_root_volume_setup=false
while read -r volspec;do
if ! [[ "${volspec}" =~ "kiwi_Volume_" ]];then
continue
fi
volume=$(echo "${volspec}" | cut -f2 -d= | tr -d \' | tr -d \")
size=$(echo "${volume}" | cut -f2 -d\| | cut -f2 -d:)
name=$(echo "${volume}" | cut -f1 -d\|)
if [ "${name}" = "LVRoot" ];then
have_root_volume_setup=true
fi
if [ "${size}" = "all" ];then
mpoint=$(echo "${volume}" | cut -f3 -d\|)
echo "${name},${mpoint}"
return
fi
done < "${profile}"
if [ "${have_root_volume_setup}" = "false" ];then
echo LVRoot,
fi
}

function get_all_free_volume {
Expand Down
1 change: 1 addition & 0 deletions kiwi/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
EDIT_BOOT_CONFIG_SCRIPT = 'edit_boot_config.sh'
EDIT_BOOT_INSTALL_SCRIPT = 'edit_boot_install.sh'
IMAGE_METADATA_DIR = 'image'
ROOT_VOLUME_NAME = 'LVRoot'


class Defaults:
Expand Down
3 changes: 1 addition & 2 deletions kiwi/storage/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,13 @@ def create_root_lvm_partition(self, mbsize):
"""
Create root partition for use with LVM
Populates kiwi_RootPart(id) and kiwi_RootPartVol(LVRoot)
Populates kiwi_RootPart(id)
:param int mbsize: partition size
"""
self.partitioner.create('p.lxlvm', mbsize, 't.lvm')
self._add_to_map('root')
self._add_to_public_id_map('kiwi_RootPart')
self._add_to_public_id_map('kiwi_RootPartVol', 'LVRoot')

def create_root_raid_partition(self, mbsize):
"""
Expand Down
4 changes: 2 additions & 2 deletions kiwi/storage/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,15 @@ def _accumulate_volume_size(self, root_mbytes):

def _get_root_volume_configuration(self):
"""
Provide LVRoot volume configuration if present and in
Provide root volume configuration if present and in
use according to the selected volume management. So far
this only affects the LVM volume manager
"""
root_volume_type = namedtuple(
'root_volume_type', ['size_type', 'req_size']
)
for volume in self.volumes:
if volume.name == 'LVRoot':
if volume.is_root_volume:
if volume.size:
[size_type, req_size] = volume.size.split(':')
return root_volume_type(
Expand Down
7 changes: 5 additions & 2 deletions kiwi/system/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,18 @@ def _systemdisk_to_profile(self):

volume_count = 1
for volume in self.xml_state.get_volumes():
volume_id_name = 'kiwi_Volume_{id}'.format(id=volume_count)
if volume.is_root_volume:
volume_id_name = 'kiwi_Volume_Root'
else:
volume_id_name = 'kiwi_Volume_{id}'.format(id=volume_count)
volume_count += 1
self.dot_profile[volume_id_name] = '|'.join(
[
volume.name,
'size:all' if volume.fullsize else volume.size,
volume.mountpoint or ''
]
)
volume_count += 1

def _preferences_to_profile(self):
# kiwi_iversion
Expand Down
2 changes: 1 addition & 1 deletion kiwi/volume_manager/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def get_volume_mbsize(
if lookup_path == volume_path:
continue
if lookup_path == os.sep:
# exclude any sub volume path if lookup_path is / [LVRoot]
# exclude any sub volume path if lookup_path is /
exclude_paths.append(
os.path.normpath(self.root_dir + os.sep + volume_path)
)
Expand Down
2 changes: 1 addition & 1 deletion kiwi/volume_manager/btrfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def create_volumes(self, filesystem_name):
)

for volume in canonical_volume_list.volumes:
if volume.name == 'LVRoot':
if volume.is_root_volume:
# the btrfs root volume named '@' has been created as
# part of the setup procedure
pass
Expand Down
15 changes: 10 additions & 5 deletions kiwi/volume_manager/lvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def get_device(self):
"""
device_map = {}
for volume_name, volume_node in list(self.volume_map.items()):
if volume_name == 'LVRoot':
# LVRoot volume device takes precedence over the
if self._is_root_volume(volume_name):
# root volume device takes precedence over the
# root partition device from the disk. Therefore use
# the same key to put them on the same level
volume_name = 'root'
Expand Down Expand Up @@ -228,7 +228,7 @@ def get_fstab(self, persistency_type, filesystem_name):
"""
fstab_entries = []
for volume_mount in self.mount_list:
if 'LVRoot' not in volume_mount.device:
if not self._is_root_volume(volume_mount.device):
mount_path = '/'.join(volume_mount.mountpoint.split('/')[3:])
if not mount_path.startswith('/'):
mount_path = '/' + mount_path
Expand Down Expand Up @@ -288,7 +288,7 @@ def umount_volumes(self):

def _create_filesystem(self, volume_name, volume_label, filesystem_name):
device_node = self.volume_map[volume_name]
if volume_name == 'LVRoot' and not volume_label:
if self._is_root_volume(volume_name) and not volume_label:
# if there is no @root volume definition for the root volume,
# perform a second lookup of a label specified via the
# rootfs_label from the type setup
Expand All @@ -306,7 +306,7 @@ def _create_filesystem(self, volume_name, volume_label, filesystem_name):

def _add_to_mount_list(self, volume_name, realpath):
device_node = self.volume_map[volume_name]
if volume_name == 'LVRoot':
if self._is_root_volume(volume_name):
# root volume must be first in the list
self.mount_list.insert(
0, MountManager(
Expand Down Expand Up @@ -343,6 +343,11 @@ def _volume_group_in_use_on_host_system(self, volume_group_name):
# group name, it is considered to be not used
return False

def _is_root_volume(self, name):
for volume in self.volumes:
if name in volume.name and volume.is_root_volume:
return True

def __del__(self):
if self.volume_group:
log.info('Cleaning up %s instance', type(self).__name__)
Expand Down
36 changes: 27 additions & 9 deletions kiwi/xml_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from textwrap import dedent

# project
import kiwi.defaults as defaults

from kiwi import xml_parse
from kiwi.system.uri import Uri
from kiwi.defaults import Defaults
Expand Down Expand Up @@ -1223,7 +1225,8 @@ def get_volumes(self): # noqa C901
mountpoint=path,
fullsize=True,
label=volume_label,
attributes=['no-copy-on-write']
attributes=['no-copy-on-write'],
is_root_volume=True|False
)
]
Expand All @@ -1243,7 +1246,8 @@ def get_volumes(self): # noqa C901
'mountpoint',
'fullsize',
'label',
'attributes'
'attributes',
'is_root_volume'
]
)

Expand All @@ -1262,6 +1266,7 @@ def get_volumes(self): # noqa C901
fullsize = False
label = volume.get_label()
attributes = []
is_root_volume = False

if volume.get_copy_on_write() is False:
# by default copy-on-write is switched on for any
Expand All @@ -1270,11 +1275,21 @@ def get_volumes(self): # noqa C901
attributes.append('no-copy-on-write')

if '@root' in name:
# setup root volume, it takes a fixed volume name and
# has no specific mountpoint
# setup root volume, it takes an optional volume
# name if specified as @root=name and has no specific
# mountpoint. The default name is set to
# defaults.ROOT_VOLUME_NAME if no other root volume
# name is provided
mountpoint = None
realpath = '/'
name = 'LVRoot'
is_root_volume = True
root_volume_expression = re.match(
r'@root=(.+)', name
)
if root_volume_expression:
name = root_volume_expression.group(1)
else:
name = defaults.ROOT_VOLUME_NAME
have_root_volume_setup = True
elif not mountpoint:
# setup volume without mountpoint. In this case the name
Expand Down Expand Up @@ -1310,7 +1325,8 @@ def get_volumes(self): # noqa C901
mountpoint=mountpoint,
realpath=realpath,
label=label,
attributes=attributes
attributes=attributes,
is_root_volume=is_root_volume
)
)

Expand All @@ -1327,13 +1343,14 @@ def get_volumes(self): # noqa C901
fullsize = True
volume_type_list.append(
volume_type(
name='LVRoot',
name=defaults.ROOT_VOLUME_NAME,
size=size,
fullsize=fullsize,
mountpoint=None,
realpath='/',
label=None,
attributes=[]
attributes=[],
is_root_volume=True
)
)

Expand All @@ -1346,7 +1363,8 @@ def get_volumes(self): # noqa C901
mountpoint=None,
realpath='swap',
label='SWAP',
attributes=[]
attributes=[],
is_root_volume=False
)
)

Expand Down
41 changes: 41 additions & 0 deletions test/data/example_lvm_custom_rootvol_config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>

<image schemaversion="7.3" name="custom-root-volume-setup">
<description type="system">
<author>Marcus Schäfer</author>
<contact>ms@suse.com</contact>
<specification>
openSUSE 13.2 JeOS, is a small text based image
</specification>
</description>
<preferences>
<version>1.13.2</version>
<packagemanager>zypper</packagemanager>
<locale>en_US</locale>
<keytable>us.map.gz</keytable>
<timezone>Europe/Berlin</timezone>
<rpm-excludedocs>true</rpm-excludedocs>
<rpm-check-signatures>false</rpm-check-signatures>
<bootsplash-theme>openSUSE</bootsplash-theme>
<bootloader-theme>openSUSE</bootloader-theme>
<type image="oem" filesystem="ext3" installiso="true" kernelcmdline="splash" firmware="efi">
<systemdisk>
<volume name="@root=myroot" freespace="500M"/>
</systemdisk>
</type>
</preferences>
<users>
<user groups="root" password="$1$wYJUgpM5$RXMMeASDc035eX.NbYWFl0" home="/root" name="root"/>
</users>
<repository>
<source path="obs://13.2/repo/oss"/>
</repository>
<packages type="image">
<package name="patterns-openSUSE-base"/>
</packages>
<packages type="bootstrap">
<package name="udev"/>
<package name="filesystem"/>
<package name="glibc-locale"/>
</packages>
</image>
1 change: 0 additions & 1 deletion test/unit/storage/disk_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def test_create_root_lvm_partition(self):
'p.lxlvm', 100, 't.lvm'
)
assert self.disk.public_partition_id_map['kiwi_RootPart'] == 1
assert self.disk.public_partition_id_map['kiwi_RootPartVol'] == 'LVRoot'

def test_create_root_raid_partition(self):
self.disk.create_root_raid_partition(100)
Expand Down
10 changes: 5 additions & 5 deletions test/unit/system/profile_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ def test_create(self, mock_which, mock_temp):
os.remove(self.profile_file)
assert self.profile.dot_profile == {
'kiwi_Volume_1': 'usr_lib|size:1024|usr/lib',
'kiwi_Volume_2': 'LVRoot|freespace:500|',
'kiwi_Volume_3': 'etc_volume|freespace:30|etc',
'kiwi_Volume_4': 'bin_volume|size:all|/usr/bin',
'kiwi_Volume_5': 'usr_bin|freespace:30|usr/bin',
'kiwi_Volume_6': 'LVSwap|size:128|',
'kiwi_Volume_2': 'etc_volume|freespace:30|etc',
'kiwi_Volume_3': 'bin_volume|size:all|/usr/bin',
'kiwi_Volume_4': 'usr_bin|freespace:30|usr/bin',
'kiwi_Volume_5': 'LVSwap|size:128|',
'kiwi_Volume_Root': 'LVRoot|freespace:500|',
'kiwi_bootkernel': None,
'kiwi_bootloader': 'grub2',
'kiwi_bootprofile': None,
Expand Down
Loading

0 comments on commit a124d82

Please sign in to comment.