Skip to content

Commit 1c5b59e

Browse files
author
Power Cloud Robot
authored
Merge pull request #307 from Shilpi-Das1/getting_partions_dynamically
Get the partition number of the image
2 parents eea0ae8 + 1d8b499 commit 1c5b59e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

cmd/image/qcow2ova/prep/loop.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ func partprobe(device string) error {
4949
return nil
5050
}
5151

52+
// get partition number of the image
53+
func getPartition(device string) (string, error) {
54+
args := fmt.Sprintf("fdisk -l %s | grep ^/dev | wc -l", device)
55+
exitcode, out, err := utils.RunCMD("bash", "-c", args)
56+
if exitcode != 0 {
57+
return "", fmt.Errorf("failed to get partition for device: %s, exitcode: %d, stdout: %s, err: %s", device, exitcode, out, err)
58+
}
59+
return strings.TrimSpace(out), nil
60+
}
61+
5262
// growpart resizes the partition
5363
func growpart(device, partition string) error {
5464
exitcode, out, err := utils.RunCMD("growpart", device, partition)

cmd/image/qcow2ova/prep/prepare.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ func prepare(mnt, volume, dist, rhnuser, rhnpasswd, rootpasswd string) error {
4545
return err
4646
}
4747

48-
// TODO: Get this partition number from the image
49-
partition := "2"
48+
partition, err := getPartition(lo)
49+
if err != nil {
50+
return err
51+
}
52+
5053
partDev := lo + "p" + partition
5154

5255
err = mount("nouuid", partDev, mnt)

0 commit comments

Comments
 (0)