Skip to content

Commit

Permalink
feat: LUKS on LVM
Browse files Browse the repository at this point in the history
* Add lvm-luks-format command

* Wait until we have an UUID

* Use regular MakeFs for lvm-luks-format

* lvm-luks-format fixes

* Bump version
  • Loading branch information
matbme authored Nov 5, 2023
1 parent cc0bc54 commit 8cb6c34
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 5 deletions.
10 changes: 10 additions & 0 deletions RECIPE.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ Same as `format`, but formats an LVM logical volume.
- *FsType* (`string`): The filesystem for the partition. Can be either `btrfs`, `ext[2,3,4]`, `linux-swap`, `ntfs`\*, `reiserfs`\*, `udf`\*, or `xfs`\*.
- *Label* (optional `string`): An optional filesystem label. If not given, no label will be set.

### lvm-luks-format

Same as `luks-format`, but formats an LVM logical volume.

**Accepts**:
- *Name* (`string`): Thin logical volume name (in format `vg_name/lv_name`).
- *FsType* (`string`): The filesystem for the partition. Can be either `btrfs`, `ext[2,3,4]`, `linux-swap`, `ntfs`\*, `reiserfs`\*, `udf`\*, or `xfs`\*.
- *Password* (`string`): The password used to encrypt the volume.
- *Label* (optional `string`): An optional filesystem label. If not given, no label will be set.

---

## Post-Installation
Expand Down
58 changes: 54 additions & 4 deletions core/recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,7 @@ func runSetupOperation(diskLabel, operation string, args []interface{}) error {
// UUID, so we loop until it gives us one
uuid := ""
for uuid == "" {
uuid, err = part.GetUUID()
}
if err != nil {
return fmt.Errorf("failed to execute operation %s: %s", operation, err)
uuid, _ = part.GetUUID()
}
err = LuksOpen(part, fmt.Sprintf("luks-%s", uuid), luksPassword)
if err != nil {
Expand Down Expand Up @@ -271,6 +268,12 @@ func runSetupOperation(diskLabel, operation string, args []interface{}) error {
if err != nil {
return fmt.Errorf("failed to execute operation %s: %s", operation, err)
}
// lsblk seems to take a few milliseconds to update the partition's
// UUID, so we loop until it gives us one
uuid := ""
for uuid == "" {
uuid, _ = part.GetUUID()
}
err = LUKSMakeFs(&part)
if err != nil {
return fmt.Errorf("failed to execute operation %s: %s", operation, err)
Expand Down Expand Up @@ -531,6 +534,53 @@ func runSetupOperation(diskLabel, operation string, args []interface{}) error {
return fmt.Errorf("failed to execute operation %s: %s", operation, err)
}
}
/* !! ### lvm-luks-format
*
* Same as `luks-format`, but formats an LVM logical volume.
*
* **Accepts**:
* - *Name* (`string`): Thin logical volume name (in format `vg_name/lv_name`).
* - *FsType* (`string`): The filesystem for the partition. Can be either `btrfs`, `ext[2,3,4]`, `linux-swap`, `ntfs`\*, `reiserfs`\*, `udf`\*, or `xfs`\*.
* - *Password* (`string`): The password used to encrypt the volume.
* - *Label* (optional `string`): An optional filesystem label. If not given, no label will be set.
*/
case "lvm-luks-format":
name := args[0].(string)
filesystem := args[1].(string)
password := args[2].(string)
lv, err := lvm.FindLv(name)
if err != nil {
return fmt.Errorf("failed to execute operation %s: %s", operation, err)
}
dummyPart := Partition{
Path: "/dev/" + lv.VgName + "/" + lv.Name,
Filesystem: PartitionFs(filesystem),
}
err = LuksFormat(&dummyPart, password)
if err != nil {
return fmt.Errorf("failed to execute operation %s: %s", operation, err)
}
// lsblk seems to take a few milliseconds to update the partition's
// UUID, so we loop until it gives us one
uuid := ""
for uuid == "" {
uuid, _ = dummyPart.GetUUID()
}
err = LuksOpen(&dummyPart, fmt.Sprintf("luks-%s", uuid), password)
if err != nil {
return fmt.Errorf("failed to execute operation %s: %s", operation, err)
}
err = LUKSMakeFs(&dummyPart)
if err != nil {
return fmt.Errorf("failed to execute operation %s: %s", operation, err)
}
if len(args) == 4 {
label := args[3].(string)
err := LUKSSetLabel(&dummyPart, label)
if err != nil {
return fmt.Errorf("failed to execute operation %s: %s", operation, err)
}
}
/* !! --- */
default:
return fmt.Errorf("unrecognized operation %s", operation)
Expand Down
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
albius (0.3.1) unstable; urgency=critical

* LUKS on LVM support

-- Mateus Melchiades <matbme@duck.com> Sat, 05 Nov 2023 11:47:00 -0300

albius (0.3.0) unstable; urgency=critical

* LVM support
Expand Down
2 changes: 1 addition & 1 deletion debian/files
Original file line number Diff line number Diff line change
@@ -1 +1 @@
albius_0.3.0_source.buildinfo devel extra
albius_0.3.1_source.buildinfo devel extra

0 comments on commit 8cb6c34

Please sign in to comment.