Commit graph

49 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Christian Kellner
37e6fa8b95 disk: add entity-based interfaces and types
Add a generic entity data model that can be used to navigate and operate
on any specific disk image layout. Since the latter allows for arbitrary
nesting of different container types, such as LUKS2, LVM2, and with file
systems that can have sub-volumes, the entity model is very generic.

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
22b8b671a8 disk: move Partition and methods to separate file
Split up disk.go into smaller more manageable pieces: finish
by moving `Partition` to its own file.

Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
53795c3dad disk: move Filesystem and methods to separate file
Split up disk.go into smaller more managable pieces: continue
with moving `Filesystem` to its own file.

Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-22 19:23:41 +00:00
Achilleas Koutsou
e7827b4b97 disk: move PartitionTable and methods to separate file
Split up disk.go into smaller more managable pieces: start with
extracting `PartitionTable` and all its methods to a new file.

Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-22 19:23:41 +00:00
Christian Kellner
dec5a3850c disk: use bytes instead of sectors in all code
Use bytes internally everywhere and convert to sectors only when writing
the options for the stages.

Changed the AlignUp() method to not do the alignment if the input is
already aligned.  This changes the behaviour when the size is 0, but
that's not a realistic use case.  Updated unit tests to match.

Manifests are unaffected.

Co-Authored-By: Christian Kellner <christian@kellner.me>
2022-02-22 19:23:41 +00:00
Christian Kellner
abaadf95ed disk: dynamically calculate header & footer
Instead of just reserving a fixed amount of sectors for the
partition header and footer, calculate the size of the
header and footer dynamically when the layout is GPT.
2022-02-22 19:23:41 +00:00
Christian Kellner
b65ef74cb2 disk: honour maximum number of partitions
Return an error if the maximum numbers of partitions has been
reached and thus creating further partitions would result in
errors.
Currently we limit MBR partition types to 4 as we dont support
logical partitions and GPT layouts to 128. According to the
UEFI specificatio (2.8) a minimum of 16384 bytes are reserved
for the partition entries array. Each entry is 128 bytes wide
thus resulting in at least 128 entries; we choose this to be
the maximum as well for now.
2022-02-22 19:23:41 +00:00
Christian Kellner
1dbd2bc364 disk: use new alignment helper to align partitions
Align partitions during their re-layout. Specifically, we align the
first partition which removes the need for the hard coded magic
number of 2048, which represents the proper alignment for a grain
size of 1MB given a sector size of 512 (our setup).

NB: Since all our partitions should sizes that are themselves
aligned, i.e. evenly dividable by the default grain (1MB) this
will not actually change any manifest.
2022-02-22 19:23:41 +00:00
Christian Kellner
930633c249 disk: add alignment helper
Add a utility method that can be used to align data to the next "grain"
which is currently defined as 1 MiB -- the default used by sfdisk.

Add corresponding tests.
2022-02-22 19:23:41 +00:00
Christian Kellner
b7abef54e8 disk: calculate padding for secondary GPT header
Instead of hard coding a padding of 100 sectors for all layouts, i.e.
MBR and GTP, adjust the needed space depending on the layout: for MBR 
we don't need to reserve any space at all since it does not have a 
secondary header. For GTP we reserve 33 sectors, as indicated in the
UEFI specific, which allows for the header itself and up to 128 entries.
To not modify the layout of already released distributions, like RHEL
8.4 and 8.5, a new member called `ExtraPadding` is added to `Partition
Table` and then used in the corresponding layouts to preserve the
existing padding of 100.
2022-02-22 19:23:41 +00:00
Christian Kellner
b3c769ae02 disk: grow root partition while re-layouting
Instead of growing the root partition in `CreatePartitionTable` do it
as part of `updatePartitionStartPointOffsets`.
2022-02-22 19:23:41 +00:00
Christian Kellner
16ad1211c3 disk: ensure there is enough space for all parts
The old calculation was wrong since it compared sectors and bytes.
2022-02-22 19:23:41 +00:00
Christian Kellner
97754a2c99 disk: add EnsureSize helper
Ensure the partition has at least the given size. Will do nothing
if the partition is already larger. Returns if the size changed.
2022-02-22 19:23:41 +00:00
Christian Kellner
e7dbe60622 disk: add find partition for mountpoint helper 2022-02-22 19:23:41 +00:00
Christian Kellner
9746a87609 disk: move createFilesystem to disk.go
Move the `createFilesystem` method over the `disk.go` and make it
a public method of `PartitionTable`.
2022-02-22 19:23:41 +00:00
Christian Kellner
7e4097fb6f disk: sector size can now be per partition table
Allow the sector size to be specified on the partition table level by
introducing a new `SectorSize` field. Modify the conversion helpers
to use that new field with a fallback to default sector size in case
the field is `0`.
2022-02-22 19:23:41 +00:00
Christian Kellner
f5592bd14a disk: add bytes ↔ sectors conversion helper
Add simple helper methods that convert between bytes and sectors. This
is a method of `PartitionTable`, since the sector size can in theory
be per partition table and this prepares for that case.
2022-02-22 19:23:41 +00:00
Christian Kellner
115c864f93 disk: define the default sector size constant
Move the `sectorSize` constant, defined in `customizations.go`
to `disk.go` as `DefaultSectorSize`. Rename current usages of
the former to the latter.
2022-02-22 19:23:41 +00:00
Christian Kellner
4086bf8dbc disk: add more docs for fields
Complete the docs for fields of `PartitionTable` and `Partition`.
2022-02-22 19:23:41 +00:00
Christian Kellner
58112e7152 disk: add GenerateUUIDs helper
Add a new helper to `PartitionTable` that generates all necessary
uuids for uuid fields that are empty but should not. These are
the file system uuids and, in case of a GPT layout, partition ids.
2022-02-22 19:23:41 +00:00
Christian Kellner
4f474f1661 disk: introduce ContainsMountpoint helper
Simple wrapper around FindFilesystemForMountpoint that will
return a boolean if a filesystem with the given mountpoint
is defined in the partition table.
2022-02-22 19:23:41 +00:00
Christian Kellner
37d912529c disk: add ForEachFilesystem helper
Add helper that iterates over all filesystems in the partition
table and calls the callback on each one.
Add simple checks for it as well.
2022-02-22 19:23:41 +00:00
Christian Kellner
74f6c59c93 disk: remove RootPartitionIndex
This method was only used by `updateRootPartition` which got
removed as well so this method is unused now.
2022-02-22 19:23:41 +00:00
Christian Kellner
d7df6b3d5c disk: add Clone helpers
Add `Clone` methods to Filesystem and PartitionTable. This can be
used to create a new PartitionTable that should be modified based
on the original.
2022-02-22 19:23:41 +00:00
Christian Kellner
34781214cf disk: methods of Filesystem take it by ref
Convert all methods of `Filesystem` to pass it by reference
not by value.
2022-02-22 19:23:41 +00:00
Christian Kellner
5bf4892077 disk: use pointer receiver for PartitionTable
The `PartitionTable` object contains an array of `Partitions`, which
is shared among all shallow copies of `PartitionTable` instances, as
when it is used via a value receiver in method calls. The individual
objects are thus not fully isolated since modifications of array
elements, or in some cases modifications to the array itself, are
shared and visible between all shallow `PartitionTable` copies. Thus
use a pointer receiver for all methods of `PartitionTable` to make
it explicit that modifications will affect other objects.
2022-02-22 19:23:41 +00:00
Christian Kellner
147e0c966b disk: remove updateRootPartition
The previous commit made sure that `PartitionTable.RootPartition`
is indeed returning the pointer partition object inside the array
of the `PartitionTable`. Thus changes to the returned object will
now directly affect the object and thus there is no need to call
`PartitionTable.updateRootPartition` anymore.
2022-02-22 19:23:41 +00:00
Christian Kellner
6333d54091 disk: return the correct ptr from RootPartition
When we iterate over the partitions to find the root partition,
we are getting the partition by value so even if we return a
pointer to that then, it is actually a pointer duplicated object.
Return the pointer to the actual partition object instead.
2022-02-22 19:23:41 +00:00
Christian Kellner
c8efc7d282 disk: create file system accessors and use those
In various places we are interested in the root and boot file-
systems. Currently those were accessed via by retrieving the
partition that contain them and the accessing the filesystem
member. Add accessors to `PartitionTable` that directly return
the needed filesystem. This will help if the file system is
stored inside a container like LVM or LUKS instead of directly
on a partition.
2022-02-22 19:23:41 +00:00
Gianluca Zuccarelli
613ad0b862 disk: refactor partition table size & start points 2021-08-21 02:54:38 +02:00
Gianluca Zuccarelli
280e1b6e3d distro: rhel85 declarative partition tables 2021-08-21 02:54:38 +02:00
Tomas Hozza
7ac1d68fb6 rhel85/90: allow specifying the boot partition for the grub2 stage
Specifying the boot partition filesystem UUID in grub2 stage is required
in case the `/boot` mountpoint is on a separate partition. This is the
case of RHEL-8.5 and RHEL-9.0 `ami` and `ec2` images.

Extend `disk.PartitionTable` with a new `BootPartition` method, which
returns a pointer to partition with FS mountpoint `/boot` if there is
such partition, or `nil` otherwise.

Extend the RHEL-8.5 and RHEL-9.0 code creating options structure for
grub2 osbuild stage to include the boot partition in case it has been
provided.

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2021-08-13 08:24:37 +02:00
Achilleas Koutsou
5909ca202d disk: boot partition finder as partitiontable method
Moved the function that searches for the boot partition index to the
PartitionTable struct as a method. The method returns -1 if not found
and it's now the responsibility of the caller to handle the case where
it is not found.
2021-07-24 15:54:00 +02:00
Achilleas Koutsou
23de460a66 disk: generate fstab stage options for osbuild v2
Same function as v1 but generates v2 struct for v2 pipelines
2021-07-24 15:54:00 +02:00
Achilleas Koutsou
8090621300 osbuild: rename package to osbuild1
Preparing for version 2 of the manifest schema, which will be
implemented in a separate package (osbuild2) alongside the original.
2021-03-17 18:12:17 +00:00
Ondřej Budai
ae0d1b8663 distro/rhel84: remove hardcoded root partition UUIDs
Let's use the root partition UUID from the partition table instead of
hardcoding the value.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2020-12-15 16:43:39 +01:00
Ondřej Budai
d52c1ea1f8 distro/rhel84: generate fstab stage from partition table
Now that we have an abstract partition table definition, we can use it to
generate org.osbuild.fstab stage options.

This is extremely nice because it removes magic contains.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2020-12-15 16:43:39 +01:00
Ondřej Budai
76926ecd35 distro/rhel84: encode the partition table using abstract data-types
Using osbuild.QEMUAssemblerOptions to encode a partition table was weird.
This commit introduces a disk package that contains data types for defining
partition tables. Also, there's a handy function to convert the abstact
partition table to osbuild.QEMUAssemblerOptions.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
2020-12-15 16:43:39 +01:00