2

I have a VM on Promox running Debian 11. I need to increase disk space, so I've resized disk in Proxmox GUI. But now, I need to enlarge root partition. This wouldn't be a problem, if root partition was the last on disk, but now, it's a partition in the middle of the disk. There is a swap partition that needs to be moved to the end of the disk, before I can resize the root partition. But there are two conditions to be fulfilled:

  1. The swap partition has to keep the same size
  2. The final swap partition has to be aligned properly to disk layout

As I'm working on a headless, we have to use CLI. This is, what parted give me:

(parted) print
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sda: 68.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system     Name  Flags
 1      1049kB  2097kB  1049kB                        bios_grub
 2      2097kB  33.3GB  33.3GB  ext4
 3      33.3GB  34.4GB  1022MB  linux-swap(v1)        swap

(parted) print free
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sda: 68.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system     Name  Flags
        17.4kB  1049kB  1031kB  Free Space
 1      1049kB  2097kB  1049kB                        bios_grub
 2      2097kB  33.3GB  33.3GB  ext4
 3      33.3GB  34.4GB  1022MB  linux-swap(v1)        swap
        34.4GB  68.7GB  34.4GB  Free Space

I know, that I have to remove the existing swap partition, using swapoff /dev/sda3 and deleting it in parted.

My question is: What do I have to type in for creating a properly aligned swap partition with exactly the same size at the end of this disk?

BTW: I don't want top replace Swap with a file.

1
  • 1
    I know how to go with that solution, but I prefer a Swap partition. Commented Sep 10, 2023 at 19:44

1 Answer 1

3

You can align by using flags like this:

parted /dev/sda --align optimal

and then setting the units as your first step

unit MiB
print

Personally I have a script called pdisk that handles this and I run parted non-interactively:

#!/bin/sh
#
dev="$1"
shift
test 0 -eq $# && set -- print
parted "$dev" --align optimal unit MiB "$@"

And then

pdisk /dev/sda [<command>]

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.