Skip to content

Commit

Permalink
osbuild: add support for swap in the bootupd stage
Browse files Browse the repository at this point in the history
Add support for swap in bootupd device generation for both plain
and LVM partitions.
  • Loading branch information
mvo5 authored and ondrejbudai committed Dec 5, 2024
1 parent ea37ffd commit 076c920
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
23 changes: 14 additions & 9 deletions pkg/osbuild/bootupd_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,22 @@ func genMountsForBootupd(source string, pt *disk.PartitionTable) ([]Mount, error
case *disk.LVMVolumeGroup:
for i := range payload.LogicalVolumes {
lv := &payload.LogicalVolumes[i]
mountable, ok := lv.Payload.(disk.Mountable)
if !ok {
return nil, fmt.Errorf("expected LV payload %+[1]v to be mountable, got %[1]T", lv.Payload)
switch payload := lv.Payload.(type) {
case disk.Mountable:
mount, err := genOsbuildMount(lv.Name, payload)
if err != nil {
return nil, err
}
mount.Source = lv.Name
mounts = append(mounts, *mount)
case *disk.Swap:
// nothing to do
default:
return nil, fmt.Errorf("expected LV payload %+[1]v to be mountable or swap, got %[1]T", lv.Payload)
}
mount, err := genOsbuildMount(lv.Name, mountable)
if err != nil {
return nil, err
}
mount.Source = lv.Name
mounts = append(mounts, *mount)
}
case *disk.Swap:
// nothing to do
default:
return nil, fmt.Errorf("type %T not supported by bootupd handling yet", part.Payload)
}
Expand Down
20 changes: 18 additions & 2 deletions pkg/osbuild/bootupd_stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,13 @@ var fakePt = &disk.PartitionTable{
FSTabPassNo: 1,
},
},
{
Size: 2 * datasizes.GibiByte,
Type: disk.SwapPartitionGUID,
Payload: &disk.Swap{
Label: "swap",
},
},
},
}

Expand Down Expand Up @@ -354,7 +361,8 @@ func TestGenBootupdDevicesMountsHappyLVM(t *testing.T) {
UEFIVendor: "test",
}

fakePt := testdisk.MakeFakeLVMPartitionTable("/", "/home", "/boot/efi", "/boot")
fakePt := testdisk.MakeFakeLVMPartitionTable("/", "/home", "/boot/efi", "/boot", "swap")

devices, mounts, err := osbuild.GenBootupdDevicesMounts(filename, fakePt, pf)
require.Nil(t, err)
assert.Equal(t, devices, map[string]osbuild.Device{
Expand All @@ -381,6 +389,14 @@ func TestGenBootupdDevicesMountsHappyLVM(t *testing.T) {
VGPartnum: common.ToPtr(3),
},
},
"lv-for-swap": {
Type: "org.osbuild.lvm2.lv",
Parent: "disk",
Options: &osbuild.LVM2LVDeviceOptions{
Volume: "lv-for-swap",
VGPartnum: common.ToPtr(3),
},
},
})
assert.Equal(t, []osbuild.Mount{
{
Expand Down Expand Up @@ -424,5 +440,5 @@ func TestGenBootupdDevicesMountsLVM_NotMountableLV(t *testing.T) {

_, _, err := osbuild.GenBootupdDevicesMounts(filename, fakePt, pf)
require.Error(t, err)
require.Regexp(t, `expected LV payload .* to be mountable, got \*disk.LUKSContainer`, err.Error())
require.Regexp(t, `expected LV payload .* to be mountable or swap, got \*disk.LUKSContainer`, err.Error())
}

0 comments on commit 076c920

Please sign in to comment.