Commit graph

19 commits

Author SHA1 Message Date
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
437dd397cd disk: test for duplicate Entities when cloning PartitionTables
Collect all entities and compare pointers.
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
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
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
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
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
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
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
01d922a4d5 disk: make disk_test package internal to disk package
So that we can test internal functions of the disk package.
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
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
6db5a7d6a8 disk: fix order of expected size in test
The method assert.GreaterOrEqual(t, a, b) asserts that a >= b,
but the arguments were (expected, actual), which is the wrong
way around since we want to assure that the actual size is at
least the expected size, i.e. actual >= expected and thus the
argument should be (actual, expected).

The partition table size (pt.Size) is in sectors while our checks and
customizations are in bytes, so we need to convert when comparing.

Co-Authored-By: Achilleas Koutsou <achilleas@koutsou.net>
2022-02-22 19:23:41 +00:00
Christian Kellner
199463547e disk: CreatePartitionTable can return errors now
Modify the signature of `CreatePartitionTable` so that it is
possible to return errors from the function. This is not yet
used, but will be in the near future. Change all call sites
accordingly: in most cases we can just bubble up the error.
2022-02-22 19:23:41 +00:00
Christian Kellner
3e72e5aa1d disk: pass basePartitionTable as pointer
Pass the `basePartitionTable` argument of `CreatePartitionTable`.
Now that we clone the partition table at the beginning of the
method there is no need to pass a copy of 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
Juan Abia
8136209d17 gosec: G404 - Use of weak rng
math/rand is good enough for uuids. disabling rule locally.
2021-12-13 12:17:30 +02:00
Gianluca Zuccarelli
613ad0b862 disk: refactor partition table size & start points 2021-08-21 02:54:38 +02:00