Spencer Smith c3fabb9829
chore: update default image sizes to 10GB for all "cloud" images
This PR adds a flag to imager that allows for tweaking the size of the created disk. Additionally, it sets the default value of that created disk to 10GB, as most images are cloud images that fail when uploaded b/c it only picks up a 1GB disk currently. Also adds some processing the makefile to make sure we set the default small value for metal images and SBCs.

Signed-off-by: Spencer Smith <spencer.smith@talos-systems.com>
2023-05-19 13:35:39 -04:00

54 lines
1.5 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package pkg
import (
"fmt"
"log"
"github.com/siderolabs/go-cmd/pkg/cmd"
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime"
)
const (
// MinRAWDiskSize is the minimum size disk we can create. Used for metal images.
MinRAWDiskSize = 1246
// DefaultRAWDiskSize is the value we use for any non-metal images by default.
DefaultRAWDiskSize = 10240
)
// CreateRawDisk creates a raw disk by invoking the `dd` command.
func CreateRawDisk(p runtime.Platform, diskSize int) (img string, err error) {
img = "/tmp/disk.raw"
// In the case that no disk size is specified, determine if we should use the min size (metal images)
// or the default for all other images.
if diskSize == 0 {
if p.Name() == "metal" {
diskSize = MinRAWDiskSize
} else {
diskSize = DefaultRAWDiskSize
}
}
// Protect against users creating a disk that's too small
if diskSize < MinRAWDiskSize {
log.Printf("specified disk size too small, using minimum value of %d MB", MinRAWDiskSize)
diskSize = MinRAWDiskSize
}
log.Printf("creating raw disk of size %d MB", diskSize)
seek := fmt.Sprintf("seek=%d", diskSize)
if _, err = cmd.Run("dd", "if=/dev/zero", "of="+img, "bs=1M", "count=0", seek); err != nil {
return "", fmt.Errorf("failed to create RAW disk: %w", err)
}
return img, nil
}