Skip to content

Commit

Permalink
storage: update label and uuid after mkfs
Browse files Browse the repository at this point in the history
The UUID is not set until after the file system is created.
We need to update the block device in memory with the new
UUID to properly create a fstab with UUID instead of device.

Signed-off-by: Mark D Horn <[email protected]>
  • Loading branch information
mdhorn committed Sep 13, 2019
1 parent 1a45dd2 commit 5fc0a05
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions storage/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,57 @@ func makeFs(bd *BlockDevice, args []string) error {
return errors.Wrap(err)
}

// Updated the UUID and LABEL now that we made the fs
err = bd.updatePartitionInfo()
if err != nil {
return errors.Wrap(err)
}

return nil
}

func (bd *BlockDevice) updatePartitionInfo() error {
if bd.Type == BlockDeviceTypeDisk {
return errors.Errorf("Trying to run updatePartitionInfo() against a disk, partition required")
}

var err error

blkid := bytes.NewBuffer(nil)
devFile := bd.GetDeviceFile()

// Read the partition blkid info
err = cmd.Run(blkid,
"blkid",
"--probe",
devFile,
"--output",
"export",
)
if err != nil {
log.Warning("updatePartitionInfo() had an error reading blkid %q",
fmt.Sprintf("%s", blkid.String()))
return err
}

for _, line := range strings.Split(blkid.String(), "\n") {
fields := strings.Split(line, "=")
if len(fields) == 2 {
if fields[0] == "LABEL" {
bd.Label = fields[1]
log.Debug("updatePartitionInfo: Updated %d LABEL: %s", devFile, bd.Label)
} else if fields[0] == "UUID" {
bd.UUID = fields[1]
log.Debug("updatePartitionInfo: Updated %d UUID: %s", devFile, bd.UUID)
}
} else {
log.Debug("updatePartitionInfo: Ignoring unknown line: %s", line)
}
}

return err
}

// getGUID determines the partition type guid either based on:
// + mount point
// + file system type (i.e swap)
Expand Down

0 comments on commit 5fc0a05

Please sign in to comment.