Score:1

Extend primary linux partition to use all available space

ne flag

I am trying to resize my primary/boot partition to use the added 30GB (virtual machine on Proxmox). As you can see my boot partition is full. I am fairly new to all this so, I'm following the answer from here: Ubuntu - unable to extend partition with growpart - partition 1 could only be grown by 2046

As I understand it, I have two partitions "in the way" of my free space, so I can't simply growpart, hence googling the error and coming across the above thread.

porter@porter:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            5.9G     0  5.9G   0% /dev
tmpfs           1.2G  1.6M  1.2G   1% /run
/dev/sda1        19G   18G     0 100% /
tmpfs           5.9G     0  5.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           1.2G     0  1.2G   0% /run/user/0
tmpfs           1.2G     0  1.2G   0% /run/user/1000

Using cfdisk I can see the 30 GB of free space.

                                                   Disk: /dev/sda
                                   Size: 50 GiB, 53687091200 bytes, 104857600 sectors
                                           Label: dos, identifier: 0x0266d922

    Device            Boot               Start            End       Sectors       Size      Id Type
>>  /dev/sda1         *                   2048       39942143      39940096        19G      83 Linux                        
    /dev/sda2                         39944190       41940991       1996802       975M       5 Extended
    └─/dev/sda5                       39944192       41940991       1996800       975M      82 Linux swap / Solaris
    Free space                        41940992      104857599      62916608        30G

So, I delete sda2 and sda5, then write the changes.

                                                   Disk: /dev/sda
                                   Size: 50 GiB, 53687091200 bytes, 104857600 sectors
                                           Label: dos, identifier: 0x0266d922

    Device            Boot                  Start              End         Sectors       Size       Id Type
>>  /dev/sda1         *                      2048         39942143        39940096        19G       83 Linux                
    Free space                           39942144        104857599        64915456        31G

However, when I then go to growpart, I get an error:

porter@porter:~$ sudo growpart -v /dev/sda 1
update-partition set to true
resizing 1 on /dev/sda using resize_sfdisk_dos
104857600 sectors of 512. total size=53687091200 bytes
## sfdisk --unit=S --dump /dev/sda
label: dos
label-id: 0x0266d922
device: /dev/sda
unit: sectors
sector-size: 512

/dev/sda1 : start=        2048, size=    39940096, type=83, bootable
padding 33 sectors for gpt secondary header
max_end=104857567 tot=104857600 pt_end=39942144 pt_start=2048 pt_size=39940096
resize of /dev/sda returned 0.
failed [pt_update:1] pt_update /dev/sda 1
partx: /dev/sda: error updating partition 1
FAILED: pt_resize failed

And the subsequent execution of resize2fs also fails with an error:

porter@porter:~$ sudo resize2fs /dev/sda 1
resize2fs 1.46.2 (28-Feb-2021)
resize2fs: Device or resource busy while trying to open /dev/sda
Couldn't find valid filesystem superblock.

Any guidance would be greatly appreciated.

Jaromanda X avatar
ru flag
`the subsequent execution of resize2fs` why would you even try that on `/dev/sda` - surely you want to resize `/dev/sda1` - though it won't do much good anyway, since the resizing of the partition failed - if `growpart` (whatever that is) fails, then perhaps you should grow the partition "manually" ... i.e. use fdisk to delete partition 1 and then recreate partition 1 starting at the same place using maximum size.
Score:2
za flag

You need to distinguish two kinds of devices:

/dev/sdX (sda in your case) — a "SCSI" disc device (I put it into quotes because many devices are going through emulated SCSI layer than real SCSI).

It's a whole disk. Different things can be placed upon it, but in a vast majority of cases it is a partition table and everything else is going into partitions. This is your case.

/dev/sdXN (sda1 in your case) — a partition N on the device sdX. It's a part of sdX which spans some LBAs.

This is where usually file systems (or other storage system layers) are placed. Unlike growpart which operates on the whole disk level, resize2fs (or any other file system related tool) should be pointed exactly towards the device which contains a file system, and in your case it should be /dev/sda1. Notice there is no space — we refer exactly to the "block device which hosts the file system", not "the disk which has a partition that hosts a file system", because that is very ambiguous (ambiguity is due to those possible additional storage layers — RAID, cache, crypto, LVM).


First, you need to resolve the issue that growpart failed to grow a partition. I believe that's because you forgot to disuse the swap which was placed on /dev/sda5 prior to the removal of that partition. Usually it is done with swapoff /dev/sda5. If you don't have /dev/sda5 device node anymore, I believe the VM reboot can solve this, but it could happen to not be able to boot at all; please, comment the swap-related line fstab to be sure it boots. Then, growpart should succeed.

So, the order is:

  • disable swap line in /etc/fstab and reboot the VM;
  • repeat growpart step as you did;
  • run resize2fs /dev/sda1 (with no space) to grow a file system.
BaconDuctTape avatar
ne flag
Yes!! Thank you!! Your explanation before the line break was so helpful. I'm sure you were also right about swap. Really, truly appreciate that time you took to explain everything.
in flag
No need to reboot to disable swap. just use `swapoff`. Turn it back on with `swapon` afterwards.
Nikita Kipriyanov avatar
za flag
@GeraldSchneider I am not sure that device node still exists after removing partitions. It surely exists in memory, but I don't know and don't want to test if it still exists on disk. Reboot is the safe generic way that should work for sure for inexperienced user, without lengthy explanations and quirky "if this, do that".
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.