Skip to content

Commit

Permalink
adds encrypted var partition to config
Browse files Browse the repository at this point in the history
  • Loading branch information
taukakao committed Jul 22, 2024
1 parent 4efe354 commit 17353c0
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ The configuration file is a JSON file with the following structure:
"partLabelB": "vos-b",
"partLabelBoot": "vos-boot",
"partLabelEfi": "vos-efi",
"PartCryptVar": "/dev/mapper/vos--var-var",

"thinProvisioning": false,
"thinInitVolume": "",
Expand Down Expand Up @@ -108,6 +109,7 @@ The following table describes each of the configuration options:
| `partLabelB` | The label of the partition dedicated to the system's `B` root. |
| `partLabelBoot` | The label of the partition dedicated to the master boot. |
| `partLabelEfi` | The label of the partition dedicated to the EFI boot. |
| `PartCryptVar` | The encrypted partition to unlock during boot. On a non-lvm setup this would be something like `/dev/nvme1n1p3`. |
| `thinProvisioning` | If set to `true`, ABRoot will use and look for a thin provisioning setup. Check the section about [thin provisioning](#thin-provisioning) for more information. |
| `thinInitVolume` | The init volume of the thin provisioning setup. |
| `libPathStates` | NOT_IMPLEMENTED |
Expand Down
15 changes: 8 additions & 7 deletions cmd/unlock-var.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ import (
"github.com/vanilla-os/orchid/cmdr"
)

type VarConfigError struct{}

func (e *VarConfigError) Error() string {
return "reading the var disk from config is not implemented yet"
}

type VarInvalidError struct {
passedDisk string
}
Expand Down Expand Up @@ -63,6 +57,7 @@ func NewUnlockVarCommand() *cmdr.Command {
),
)

// this is just meant for compatability with old Installations
cmd.WithStringFlag(
cmdr.NewStringFlag(
"var-disk",
Expand Down Expand Up @@ -126,7 +121,13 @@ func unlockVar(cmd *cobra.Command, _ []string) error {
}

if varDisk == "" {
return &VarConfigError{}
if settings.Cnf.PartCryptVar == "" {
cmdr.Error.Println("Encrypted var partition not found in configuration.")
os.Exit(3)
return nil
}

varDisk = settings.Cnf.PartCryptVar
}

dryRun, err := cmd.Flags().GetBool("dry-run")
Expand Down
1 change: 1 addition & 0 deletions config/abroot.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"partLabelB": "vos-b",
"partLabelBoot": "vos-boot",
"partLabelEfi": "vos-efi",
"PartCryptVar": "/dev/mapper/vos--var-var",

"thinProvisioning": false,
"thinInitVolume": "",
Expand Down
2 changes: 1 addition & 1 deletion core/disk-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,5 @@ func (p *Partition) IsDevMapper() bool {

// IsEncrypted returns whether the partition is encrypted
func (p *Partition) IsEncrypted() bool {
return strings.HasPrefix(p.Device, "luks-")
return strings.HasPrefix(p.FsType, "crypto_")
}
12 changes: 12 additions & 0 deletions core/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,18 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
return err
}

varParent := s.RootM.VarPartition.Parent
if varParent != nil && varParent.IsEncrypted() {
device := varParent.Device
if varParent.IsDevMapper() {
device = "/dev/mapper/" + device
} else {
device = "/dev/" + device
}

settings.Cnf.PartCryptVar = device
}

err = settings.WriteConfigToFile(filepath.Join(systemNew, "/usr/share/abroot/abroot.json"))
if err != nil {
PrintVerboseErr("ABSystem.RunOperation", 5.25, err)
Expand Down
2 changes: 2 additions & 0 deletions settings/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Config struct {
PartLabelB string `json:"partLabelB"`
PartLabelBoot string `json:"partLabelBoot"`
PartLabelEfi string `json:"partLabelEfivar"`
PartCryptVar string `json:"PartCryptVar"`

// Structure
ThinProvisioning bool `json:"thinProvisioning"`
Expand Down Expand Up @@ -117,6 +118,7 @@ func init() {
PartLabelB: viper.GetString("partLabelB"),
PartLabelBoot: viper.GetString("partLabelBoot"),
PartLabelEfi: viper.GetString("partLabelEfi"),
PartCryptVar: viper.GetString("PartCryptVar"),

// Structure
ThinProvisioning: viper.GetBool("thinProvisioning"),
Expand Down

0 comments on commit 17353c0

Please sign in to comment.