Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix partition initialization bug. #10702

Open
wants to merge 1 commit into
base: 3.0-dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions toolkit/tools/imagegen/diskutils/diskutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,13 +682,19 @@ func InitializeSinglePartition(diskDevPath string, partitionNumber int,
partitionNumberStr := strconv.Itoa(partitionNumber)

// There are two primary partition naming conventions:
// /dev/sdN<y> style or /dev/loopNp<x> style
// - /dev/sdN<y>
// - /dev/loopNp<x>
// Detect the exact one we are using.
// Make sure we check for /dev/loopNp<x> FIRST, since /dev/loop1 would generate /dev/loop11 as a partition
// device which may be a valid device. We want to select /dev/loop1p1 first.
testPartDevPaths := []string{
fmt.Sprintf("%sp%s", diskDevPath, partitionNumberStr),
fmt.Sprintf("%s%s", diskDevPath, partitionNumberStr),
}

// If disk path ends in a digit, then the 'p<x>' style must be used.
// So, don't check the other style to avoid ambiguities. For example, /dev/loop1 vs. /dev/loop11.
// The is particularly relevant on Ubuntu, due to snap's use of loopback devices.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// The is particularly relevant on Ubuntu, due to snap's use of loopback devices.
// This is particularly relevant on Ubuntu, due to snap's use of loopback devices.

if !isDigit(diskDevPath[len(diskDevPath)-1]) {
devPath := fmt.Sprintf("%s%s", diskDevPath, partitionNumberStr)
testPartDevPaths = append(testPartDevPaths, devPath)
}

err = retry.Run(func() error {
Expand Down Expand Up @@ -759,6 +765,10 @@ func InitializeSinglePartition(diskDevPath string, partitionNumber int,
return
}

func isDigit(c byte) bool {
return c >= '0' && c <= '9'
}

func setGptPartitionType(partition configuration.Partition, timeoutInSeconds, diskDevPath, partitionNumberStr string) (err error) {
if supports, _ := PartedSupportsTypeCommand(); !supports {
logger.Log.Warn("parted version <3.6 does not support the 'type' session command - skipping this operation")
Expand Down
Loading