1
// This Source Code Form is subject to the terms of the Mozilla Public
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
13
"github.com/siderolabs/talos/pkg/provision"
16
// UserDiskName returns disk device path.
17
func (p *Provisioner) UserDiskName(index int) string {
18
// the disk IDs are assigned in the following way:
19
// * ata-QEMU_HARDDISK_QM00001
20
// * ata-QEMU_HARDDISK_QM00003
21
// * ata-QEMU_HARDDISK_QM00005
22
return fmt.Sprintf("/dev/disk/by-id/ata-QEMU_HARDDISK_QM%05d", (index-1)*2+1)
25
// CreateDisks creates empty disk files for each disk.
26
func (p *Provisioner) CreateDisks(state *State, nodeReq provision.NodeRequest) (diskPaths []string, err error) {
27
diskPaths = make([]string, len(nodeReq.Disks))
29
for i, disk := range nodeReq.Disks {
30
diskPath := state.GetRelativePath(fmt.Sprintf("%s-%d.disk", nodeReq.Name, i))
34
diskF, err = os.Create(diskPath)
39
defer diskF.Close() //nolint:errcheck
41
if err = diskF.Truncate(int64(disk.Size)); err != nil {
45
if !disk.SkipPreallocate {
46
if err = syscall.Fallocate(int(diskF.Fd()), 0, 0, int64(disk.Size)); err != nil {
47
fmt.Fprintf(os.Stderr, "WARNING: failed to preallocate disk space for %q (size %d): %s", diskPath, disk.Size, err)
51
diskPaths[i] = diskPath
54
if len(diskPaths) == 0 {
55
return nil, errors.New("node request must have at least one disk defined to be used as primary disk")