1

My Debian vmware image has run out of space. I've expanded the disk image but now need to increase my root partition to see the additional space. My volume is setup as follows

Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x37ce2932

Device     Boot    Start      End  Sectors Size Id Type
/dev/sda1  *        2048 48236543 48234496  23G 83 Linux
/dev/sda2       48238590 52426751  4188162   2G  5 Extended
/dev/sda5       48238592 52426751  4188160   2G 82 Linux swap / Solaris

I understand that in order to expand sda1, any new space has to be directly after it. All the examples I've read either a) use LVM or b) dont have an Extended sda2 partition directly after sda1. Can anyone point me to a reference that will show me how to expand sda1 in this scenario? I know I will have to switch off/remove swap on sda5, but what do I do about sda2?

1
  • 1
    Hi. No, first time user here. I've only recently started to mess around with Linux and am still finding the file system a mystery. This problem stems from the fact I only created a small vdk and rather than 'cheat' (by starting again!), I thought I'd use it as a learning exercise :-) Commented Dec 8, 2021 at 20:39

1 Answer 1

1

UPDATE - I found this answer, and the others, to be quite helpful. You may want to compare those too.

You need to do like this:

  • swapoff, thus "freeing" the swap partition
  • fdisk, and delete both the extended partition and the physical partition.

You are now left with just /dev/sda1.

You can now enlarge the image using fdisk again, up to the maximum "physical" size offered by VMware less the new swap size. You can either use a partition-resizing tool, or you can delete /dev/sda1 and recreate it with the same starting point (and type and boot flag). If you can't do so, do not save changes and exit immediately fdisk, then find a tool such as partition-resize or growpart, or a different fdisk (e.g. cfdisk) which can.

Exiting fdisk, run kpartx /dev/sda to inform the kernel of the size change. I'm sure I must have forgotten more often than not, and never did anything bad happen to me, but it might just have been luck on my part.

Once the partition has been enlarged, you can add a new physical partition /dev/sda2. Leave it type 82h; there's no need to create an extended partition and then another swap partition inside. Keep the swap on /dev/sda2.

Then run mkswap on /dev/sda2 and verify/recreate its UUID, because you want it to be correct in /etc/fstab if it's UUID-based (if it's referred as /dev/sda5, just correct to /dev/sda2)

Finally you can run resize2fs to make the FS grow to fill the new /dev/sda1.

1
  • fantastic. Thank you for this. The main question I had was what to do with sda2 which you've now answered perfectly (basically just delete it!). I was worried in case it was used for something else. Learning every day :-) Commented Dec 8, 2021 at 20:41

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.