Commit graph

109 commits

Author SHA1 Message Date
Achilleas Koutsou
8be2c5c89a disk: test minimum directory size calculations
/ and /usr have minimum sizes defined (1 GiB and 2 GiB respectively).
When /usr is not defined, the minimum size of /usr gets added to the
minimum size for /.
This new test runs through a few scenarios and checks whether the sizes
fit.
2022-04-29 08:55:36 +02:00
Achilleas Koutsou
b8cd4bb839 disk: add an empty blueprint to the tests
Adjusted tests accordingly
2022-04-29 08:55:36 +02:00
Achilleas Koutsou
ae9960b8db disk: test that all mountpoints are the minimum 1 GiB
This tests that the clampFSSize() function ensures all user-defined
mountpoints are at least 1 GiB.
Added a blueprint with < 1 GiB minsizes to test this.
Testing all blueprints in TestCreatePartitionTable() now.
2022-04-29 08:55:36 +02:00
Achilleas Koutsou
61be84d634 disk: define blueprint map for test
Convenient for iterating and to define more cases.
2022-04-29 08:55:36 +02:00
Achilleas Koutsou
9920d798f5 disk: remove special case for /usr in clampFSSize
The `/usr` case is now handled by the `EnsureDirectorySizes()` function.
2022-04-29 08:55:36 +02:00
Achilleas Koutsou
275e60f199 disk: add default minimum directory sizes
Currently, we only specify a minimum size for
- `/` (1 GiB), and
- `/usr` (2 GiB).

This ensures that
- a separate `/usr` partition is at least 2 GiB,
- `/` is always at least 1 GiB,
- if `/usr` it not a separate partition, `/` is at least 3 GiB.

We could (or should), in the future, make it possible for image types to
override this mapping as part of their default config, for example, if
an image type by default requires a larger `/usr`.
2022-04-29 08:55:36 +02:00
Achilleas Koutsou
efa10e56e1 disk: use constants for size units in tests
Makes the test values more readable (without needing comments).
Some values in the default partition table were fixed, e.g., cases where
we had `Size: 1024000, // 500 MB`.
2022-04-29 08:55:36 +02:00
Christian Kellner
b365b18390 disk: fix ensureLVM for partition tables without /boot
When the partition table did not have a boot partition, we created it
but then _unconditionally_ returned, which meant that we did not create
the LVM skeleton and wrap the root partition. Properly handle this case
and also re-initialize the `rootPath` in this case since we change the
underlying `Partition[]` array in `PartitionTable` object. Add an extra
blueprint with only one customization which exposes this bug.

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
2022-04-29 08:55:36 +02:00
Achilleas Koutsou
55a2e8ddac disk: add function for resizing Entities based on dirs
New function that ensures that a partition can hold the total sum of all
the required sizes of specific directories on the partition.  The
function sums the required directory sizes grouped by their mountpoint
and then resizes the entity path of that Mountable.
2022-04-27 13:49:19 +02:00
Achilleas Koutsou
ce5a28c113 disk: add function for finding entity path for a dir
New function that returns the Entity path for the Mountpoint that
contains a given directory path.
2022-04-27 13:49:19 +02:00
Achilleas Koutsou
75a0a74064 disk: add docstring for resizeEntityBranch()
resizeEntityBranch() is a private function, but it's not immediately
clear how it works so a docstring is useful for internal development.
2022-04-27 13:49:19 +02:00
Tomas Hozza
2ec55b4c53 RHEL-90: use XBOOTLDR partition GUID for /boot
Use the Extended Bootloader Partition GUID for `/boot`, instead of the
Linux filesystem data GUID. This is useful for autodetection of a
partition purpose based on its GUID without reading the `/etc/fstab`
first.

Ensure that when creating mountpoints, e.g. when converting the
partitions layout to LVM, the `/boot` partition get the proper GUID
assigned.

Regenerate RHEL-90 and centos-9 image test cases.

Related to https://bugzilla.redhat.com/show_bug.cgi?id=2057231
2022-03-24 15:40:10 +01:00
Tom Gundersen
973b5141b3 ditro/rhel86: set volid like in rhel9.0
This is only required in RHEL9.0, but best practice is to always pin these things
down. Also increases uniformity between distros.

Simplify a bit the volid generator by making it require `rand.Rand` rather than
`io.Reader`, and hence eliminating the need for error handling.
2022-02-28 23:05:45 +00:00
Antonio Murdaca
3be67ad965 Simplified installer: add support for encrypted raw images
Signed-off-by: Antonio Murdaca <runcom@linux.com>
2022-02-28 23:05:45 +00:00
Achilleas Koutsou
437dd397cd disk: test for duplicate Entities when cloning PartitionTables
Collect all entities and compare pointers.
2022-02-28 23:05:45 +00:00
Achilleas Koutsou
10095e382a disk: fix Payload cloning bugs
In LUKSContainer and LVMLogicalVolume we neglected to clone the Payload
which means we would modify the base PartitionTable when manipulating
the clone.
2022-02-28 23:05:45 +00:00
Christian Kellner
ddc0126a36 test: check we always have a boot on lvmification
Check that the `ensureLVM` code creates a boot partition, if it does
not yet exist.
2022-02-28 21:36:25 +01:00
Christian Kellner
63aa1556fc rhel86: automatically convert to LVM on fs customizations
Whenever we create a new mountpoint due to a user customization,
ensure the layout uses LVM, i.e. convert plain layouts to it, if
needed. It uses the existing lvm-ification code but enhances it
so that we also create a `/boot` partition in case it does not
yet exist.
Adjust the existing tests that assumed we can not create more
than 4 partitions on mbr layouts, since that is now not true
anymore.
2022-02-28 21:36:25 +01:00
Christian Kellner
ed4e0a94a4 disk: honour the fact that some containers have metadata
Re-introduce the VolumeContainer interface but with a different
meaning: it is supposed to be implemented by all container that
contain volumes and as a result have themselves a size, like eg
LVM2, LUKS2 and PartitionTable (the latter is not yet included).
The sole method on the interface for now is MetadataSize, which
should return the metadata for the container itself.
Use that new `VolumeContainer.MetadataSize` method when we up-
date the sizes of elements in `resizeEntitybranch`.
2022-02-28 17:09:30 +01:00
Christian Kellner
17fa96b84a disk: rename VolumeContainer → MountpointCreator
Rename the interface after the one method it has and the attribute
it describes for the implementing entities: being able to create
mountpoints.
2022-02-28 17:09:30 +01:00
Christian Kellner
7bfd0bb49f disk: rename Create{Volume → Mountpoint}
The function is indeed creating a mounpoint not a Volume; the
latter is not even well defined in our "ontology".
2022-02-28 17:09:30 +01:00
Christian Kellner
45f898c05c disk: remove unused CreateFilesystem method
The `CreateFilesystem` method on `PartitionTable` is not used
anymore since it got replaced by `CreateVolume`.
2022-02-28 17:09:30 +01:00
Christian Kellner
e57cccc3fe disk: NewPartitionTable can wrap plain partitions in LVM
Add a new parameter `lvmify` to `NewPartitionTable` that, if set to
`true`, will cause the root partition to be wrapped in LVM in case
it is not in a LVM volume group. Set this to `false` for now so no
actual change should happen anywhere. Layouts where the root is
directly on a LUKS container are not yet supported.
Add tests for this.
2022-02-28 17:09:30 +01:00
Christian Kellner
f91d8c6292 distro/rhel86: add support for azure marketplace
Add support for building images for the Azure marketplace: add a
new image type "azure-rhui" that can be used to build images
tailored to the Azure marketplace.
Add two sample manifests for 8.5 and 8.6, but note that even the
8.5 is using the 8.6 distro definitions. Also no image-info is
included since `image-info` cannot (yet) handle LVM setups and
the azure marketplace images use the LVM setup.
2022-02-27 22:03:36 +01:00
Christian Kellner
ca61baf03b disk: add partition type helpers
Add helper methods on `Partition` so that we can easily "detect" if
they are of the type BIOS-BOOT or PReP. Add the PReP GUID for GPT
as well.
2022-02-27 22:03:36 +01:00
Christian Kellner
1060885386 disk: extract GPT header calculation code
Extract the code that calculates the GPT header size into its own
method so that we can use it in other places as well.
2022-02-27 22:03:36 +01:00
Christian Kellner
a9ef16a95e disk/lvm: generate logical volume name
When creating a new logical volume via the `CreateVolume` method,
the logical volume name was left blank. Generate an name based
on the mountpoint.
We will detect collisions for names and will try to correct them
by attaching a suffix. We do give up after 100 attempts though.
Add a simple test for it.
2022-02-27 22:03:36 +01:00
Gianluca Zuccarelli
62c44e86f9 disk: ensure minimum size for filesystems
This commit fixes #2347 by ensuring that a minimum
size of 1GB is set for all file systems. The only
exception to this is the `/usr` which is set to 2GB,
since this was the only mountpoint that was previously
being checked.
2022-02-24 11:00:35 +01:00
Achilleas Koutsou
c347373c90 disk: basic partition table creation tests
Add a few test partition tables with well known configurations, like
LVM, LVM on top of LVM and Btrfs in addition to the plain layout that
is currently used in most partition tables. Add very basic checks,
such as that `NewPartitionTable` works and we have approximately the
correct size.

Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-22 19:23:41 +00:00
Christian Kellner
d1b1e32b6e disk: Partition.Payload is now an Entity
Partition.Payload now supports every type of disk.Entity which enables
creating PartitionTables with LUKS, LVM, and Btrfs. \o/

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
2022-02-22 19:23:41 +00:00
Christian Kellner
206e030f2c disk: guard against nil pointer dereferencing
Add guards protecting against dereferencing the pointer receiver of
method calls.

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
2022-02-22 19:23:41 +00:00
Christian Kellner
beaf411628 disk: remove unused functions
Remove functions that got obsoleted by the more generic, entity based,
ones:
  - `FindPartitionForMountpoint`
  - `BootPartitionIndex`
  - `FindFilesystemForMountpoint`
  - `RootFilesystem`
  - `BootFilesystem`

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
2022-02-22 19:23:41 +00:00
Christian Kellner
908b62ae08 disk: use entityPath in ContainsMountpoint
Implement `PartitionTable.ContainsMountpoint` via `entityPath` instead
of `FindFileSystemForMountpoint`; `entityPath` is the more generic
variant of `FindFileSystemForMountpoint` and will work with anything
that implements `Mountable`.

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
2022-02-22 19:23:41 +00:00
Christian Kellner
b0899c5c59 disk: new interface UniqueEntity for Entities with UUID
This is for all entities that have a uniquely identifiable via a UUID.
Currently the interface only contains a single function, GenUUID(),
that should generate a new UUID via a random source (`rand.Rand`).
NB: Partitions are uniquely identifiable if and only if the layout is
GPT.

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
126c23cb13 disk: move constants to main disk.go file
Code cleanup and reorganisation:
Removed customizations.go file, moved all constants to disk.go, and
updated DefaultGrainBytes to it's actual value.
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
d3b4349c63 disk: remove old unused CreatePartitionTable() function
The new `disk.NewPartitionTable` function is now used in all places
and thus `CreatePartitionTable` can be removed; do so.
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
3312323db1 disk: implement VolumeContainer interface for PartitionTable
Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
2b957a7de6 disk: new constructor for PartitionTable
Uses the new interfaces and supports all the different kinds of
filesystem configurations that we added.
Clones the base PartitionTable before modifying it.

Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
890f380384 distro: replace BootPartition() with FindMountable("/boot")
RootParition() and BootPartition() methods have been removed.
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
3f38602896 disk: new method for finding Mountable entities with a given mountpoint 2022-02-22 19:23:41 +00:00
Achilleas Koutsou
6fc993d03c disk: rename PartitionTable re-layouting method
Small localised change. Nice shorter name.
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
adfed6e0d7 disk: change updatePartitionStartPointOffsets() to use entityPath()
Eventually partition.Payload will be an Entity, so we need to use
more generic functions that work on the interfaces.

Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
491020f9b8 disk: add entityPath() function
Starts from an Entity (typically the PartitionTable) and searches for a
target (Mountpoint), returning a slice of all the entities that lead to
the Mountable with the given Mountpoint (in reverse order).

Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-22 19:23:41 +00:00
Christian Kellner
26c7be5311 disk: add basic check for ForEachEntity
Assure that we visit all the entities.

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
2022-02-22 19:23:41 +00:00
Christian Kellner
cea96c43ac disk: new method on partition table to iterate over all entities
Add a new enumerator method to `PartitioTable` that allows the
caller to visit all entities inside a partition table.

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
3110ae4629 disk: move stage option generation functions to osbuild1,2
Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
05a2f97549 disk: new PartitionTable method ForEachMountable()
Calls a given function on each Mountable in a PartitionTable.

Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
46a0ad77f9 osbuild2: add LUKS2 format stage and device
Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
54fd090a60 disk: rename Partition.Filesystem to Payload
A Partition can contain any type of Entity now.  Before we change the
type, rename the field to a more generic term.
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
221cdedebc disk: Entity types must implement Clone()
All disk.Entitity types now implement Clone() which should return a
deep copy of the same object. Add the Clone() method to the entity
interface. The return type is Entity, but callers can assume it's
safe to convert back to the original type.

Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-22 19:23:41 +00:00