Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions cmd/limactl/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func diskListAction(cmd *cobra.Command, args []string) error {

if jsonFormat {
for _, diskName := range disks {
disk, err := store.InspectDisk(diskName)
disk, err := store.InspectDisk(diskName, nil)
if err != nil {
logrus.WithError(err).Errorf("disk %q does not exist?", diskName)
continue
Expand All @@ -202,7 +202,7 @@ func diskListAction(cmd *cobra.Command, args []string) error {
}

for _, diskName := range disks {
disk, err := store.InspectDisk(diskName)
disk, err := store.InspectDisk(diskName, nil)
if err != nil {
logrus.WithError(err).Errorf("disk %q does not exist?", diskName)
continue
Expand Down Expand Up @@ -254,7 +254,7 @@ func diskDeleteAction(cmd *cobra.Command, args []string) error {
}

for _, diskName := range args {
disk, err := store.InspectDisk(diskName)
disk, err := store.InspectDisk(diskName, nil)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
logrus.Warnf("Ignoring non-existent disk %q", diskName)
Expand Down Expand Up @@ -325,7 +325,7 @@ $ limactl disk unlock DISK1 DISK2 ...
func diskUnlockAction(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
for _, diskName := range args {
disk, err := store.InspectDisk(diskName)
disk, err := store.InspectDisk(diskName, nil)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
logrus.Warnf("Ignoring non-existent disk %q", diskName)
Expand Down Expand Up @@ -387,7 +387,7 @@ func diskResizeAction(cmd *cobra.Command, args []string) error {
}

diskName := args[0]
disk, err := store.InspectDisk(diskName)
disk, err := store.InspectDisk(diskName, nil)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("disk %q does not exists", diskName)
Expand Down
20 changes: 15 additions & 5 deletions pkg/cidata/cidata.TEMPLATE.d/boot/05-lima-disks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,24 @@ for i in $(seq 0 $((LIMA_CIDATA_DISKS - 1))); do
# first time setup
if [[ ! -b "/dev/disk/by-label/lima-${DISK_NAME}" ]]; then
if $FORMAT_DISK; then
echo 'type=linux' | sfdisk --label gpt "/dev/${DEVICE_NAME}"
# shellcheck disable=SC2086
mkfs.$FORMAT_FSTYPE $FORMAT_FSARGS -L "lima-${DISK_NAME}" "/dev/${DEVICE_NAME}1"
if [ "$FORMAT_FSTYPE" == "swap" ]; then
echo 'type=swap' | sfdisk --label gpt "/dev/${DEVICE_NAME}"
# shellcheck disable=SC2086
mkswap $FORMAT_FSARGS -L "lima-${DISK_NAME}" "/dev/${DEVICE_NAME}1"
else
echo 'type=linux' | sfdisk --label gpt "/dev/${DEVICE_NAME}"
# shellcheck disable=SC2086
mkfs.$FORMAT_FSTYPE $FORMAT_FSARGS -L "lima-${DISK_NAME}" "/dev/${DEVICE_NAME}1"
fi
fi
fi

mkdir -p "/mnt/lima-${DISK_NAME}"
mount -t "$FORMAT_FSTYPE" "/dev/${DEVICE_NAME}1" "/mnt/lima-${DISK_NAME}"
if [ "$FORMAT_FSTYPE" == "swap" ]; then
swapon "/dev/${DEVICE_NAME}1"
else
mkdir -p "/mnt/lima-${DISK_NAME}"
mount -t "$FORMAT_FSTYPE" "/dev/${DEVICE_NAME}1" "/mnt/lima-${DISK_NAME}"
fi
if command -v growpart >/dev/null 2>&1 && command -v resize2fs >/dev/null 2>&1; then
growpart "/dev/${DEVICE_NAME}" 1 || true
# Only resize when filesystem is in a healthy state
Expand Down
2 changes: 1 addition & 1 deletion pkg/driver/krunkit/krunkit_darwin_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func Cmdline(inst *limatype.Instance) (*exec.Cmd, error) {
ctx := context.Background()
diskUtil := proxyimgutil.NewDiskUtil(ctx)
for _, d := range inst.Config.AdditionalDisks {
disk, derr := store.InspectDisk(d.Name)
disk, derr := store.InspectDisk(d.Name, d.FSType)
if derr != nil {
return nil, fmt.Errorf("failed to load disk %q: %w", d.Name, derr)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/driver/qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ func Cmdline(ctx context.Context, cfg Config) (exe string, args []string, err er
extraDisks := []string{}
for _, d := range y.AdditionalDisks {
diskName := d.Name
disk, err := store.InspectDisk(diskName)
disk, err := store.InspectDisk(diskName, d.FSType)
if err != nil {
logrus.Errorf("could not load disk %q: %q", diskName, err)
return "", nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/driver/vz/vm_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ func attachDisks(ctx context.Context, inst *limatype.Instance, vmConfig *vz.Virt

for _, d := range inst.Config.AdditionalDisks {
diskName := d.Name
disk, err := store.InspectDisk(diskName)
disk, err := store.InspectDisk(diskName, d.FSType)
if err != nil {
return fmt.Errorf("failed to run load disk %q: %w", diskName, err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/hostagent/hostagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ sudo chown -R "${USER}" /run/host-services`
a.cleanUp(func() error {
var unlockErrs []error
for _, d := range a.instConfig.AdditionalDisks {
disk, inspectErr := store.InspectDisk(d.Name)
disk, inspectErr := store.InspectDisk(d.Name, d.FSType)
if inspectErr != nil {
unlockErrs = append(unlockErrs, inspectErr)
continue
Expand Down
2 changes: 1 addition & 1 deletion pkg/instance/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func StopForcibly(inst *limatype.Instance) {

for _, d := range inst.AdditionalDisks {
diskName := d.Name
disk, err := store.InspectDisk(diskName)
disk, err := store.InspectDisk(diskName, d.FSType)
if err != nil {
logrus.Warnf("Disk %q does not exist", diskName)
continue
Expand Down
14 changes: 11 additions & 3 deletions pkg/store/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ type Disk struct {
Instance string `json:"instance"`
InstanceDir string `json:"instanceDir"`
MountPoint string `json:"mountPoint"`

// if the Disk is in use and the FSType is specified
FSType *string `json:"fsType,omitempty"`
}

func InspectDisk(diskName string) (*Disk, error) {
func InspectDisk(diskName string, fsType *string) (*Disk, error) {
disk := &Disk{
Name: diskName,
Name: diskName,
FSType: fsType,
}

diskDir, err := DiskDir(diskName)
Expand Down Expand Up @@ -56,7 +60,11 @@ func InspectDisk(diskName string) (*Disk, error) {
disk.InstanceDir = instDir
}

disk.MountPoint = fmt.Sprintf("/mnt/lima-%s", diskName)
if disk.FSType != nil && *disk.FSType == "swap" {
disk.MountPoint = "swap" // only used for logging messages
} else {
disk.MountPoint = fmt.Sprintf("/mnt/lima-%s", diskName)
}

return disk, nil
}
Expand Down
Loading