Skip to content

Commit

Permalink
LVM commands improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
matbme committed Oct 8, 2023
1 parent a59d96d commit 5506eb1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
14 changes: 11 additions & 3 deletions RECIPE.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Create LVM logical volume.
**Accepts**:
- *Name* (`string`): Logical volume name.
- *VG* (`string`): Volume group name.
- *Type* (`string`): Logical volume type. See lvcreate(8) for available types.
- *Type* (`string`): Logical volume type. See lvcreate(8) for available types. If unsure, use `linear`.
- *Size* (`float`): Logical volume size in MiB.

### lvrename
Expand All @@ -169,8 +169,8 @@ Creates a new LVM thin pool from two LVs: one for metadata and another one for t

**Accepts**:
- *Name* (`string`): The created thin pool name.
- *ThinDataLV* (`string`): The LV for storing data.
- *ThinMetaLV* (`string`): The LV for storing pool metadata.
- *ThinDataLV* (`string`): The LV for storing data (in format `vg_name/lv_name`).
- *ThinMetaLV* (`string`): The LV for storing pool metadata (in format `vg_name/lv_name`).

### lvcreate-thin

Expand All @@ -182,6 +182,14 @@ Same as `lvcreate`, but creates a thin LV instead.
- *Size* (`float`): Volume group size in MiB.
- *Thinpool* (`string`): Name of the thin pool to create the LV from.

### lvm-format

Same as `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`\*.

---

## Post-Installation
Expand Down
14 changes: 12 additions & 2 deletions core/lvm/lv.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,19 @@ func parseLvAttrs(attrStr string) ([10]int, error) {
return [10]int{attrVolType, attrPermissions, attrAllocPolicy, attrFixed, attrState, attrDevice, attrTargetType, attrBlocks, attrHealth, attrSkip}, nil
}

func FindLv(vgName, lvName string) (Lv, error) {
// FindLv fetches an LVM logical volume by its name. You can pass the name
// either as a single string (as in `vg_name/lv_name`) or as two separate
// variables, where the first is the VG name and, the second, the LV name.
func FindLv(name string, lvName ...string) (Lv, error) {
var fullName string
if len(lvName) == 0 {
fullName = name
} else {
fullName = name + "/" + lvName[0]
}

lvm := NewLvm()
lvs, err := lvm.Lvs(vgName + "/" + lvName)
lvs, err := lvm.Lvs(fullName)
if err != nil {
return Lv{}, fmt.Errorf("findLv: %v", err)
}
Expand Down
29 changes: 26 additions & 3 deletions core/recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func runSetupOperation(diskLabel, operation string, args []interface{}) error {
* **Accepts**:
* - *Name* (`string`): Logical volume name.
* - *VG* (`string`): Volume group name.
* - *Type* (`string`): Logical volume type. See lvcreate(8) for available types.
* - *Type* (`string`): Logical volume type. See lvcreate(8) for available types. If unsure, use `linear`.
* - *Size* (`float`): Logical volume size in MiB.
*/
case "lvcreate":
Expand Down Expand Up @@ -497,8 +497,8 @@ func runSetupOperation(diskLabel, operation string, args []interface{}) error {
*
* **Accepts**:
* - *Name* (`string`): The created thin pool name.
* - *ThinDataLV* (`string`): The LV for storing data.
* - *ThinMetaLV* (`string`): The LV for storing pool metadata.
* - *ThinDataLV* (`string`): The LV for storing data (in format `vg_name/lv_name`).
* - *ThinMetaLV* (`string`): The LV for storing pool metadata (in format `vg_name/lv_name`).
*/
case "make-thin-pool":
thinDataLV := args[0].(string)
Expand Down Expand Up @@ -526,6 +526,29 @@ func runSetupOperation(diskLabel, operation string, args []interface{}) error {
if err != nil {
return err
}
/* !! ### lvm-format
*
* Same as `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`\*.
*/
case "lvm-format":
name := args[0].(string)
filesystem := args[1].(string)
lv, err := lvm.FindLv(name)
if err != nil {
return err
}
dummyPart := Partition{
Path: "/dev/" + lv.VgName + "/" + lv.Name,
Filesystem: PartitionFs(filesystem),
}
err = MakeFs(&dummyPart)
if err != nil {
return fmt.Errorf("failed to execute operation %s: %s", operation, err)
}
/* !! --- */
default:
return fmt.Errorf("unrecognized operation %s", operation)
Expand Down

0 comments on commit 5506eb1

Please sign in to comment.