0

I have before me the following problem:

Filesystem                                                     Size  Used Avail Use% Mounted on
/dev/sda1                                                       28G   26G  240M 100% /

So, looking to expand this disk, I do the following:

$ sudo parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print                                                            
Model: ATA QEMU HARDDISK (scsi)
Disk /dev/sda: 50.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number Start End Size Type File system Flags 1 1049kB 30.1GB 30.1GB primary ext4 boot 2 30.1GB 40.0GB 9934MB extended 5 30.1GB 34.4GB 4293MB logical linux-swap(v1)

(parted) resizepart
Partition number? 1
Warning: Partition /dev/sda1 is being used. Are you sure you want to continue? Yes/No? Yes
End? [30.1GB]? 40GB
Error: Can't have overlapping partitions.

I was surprised to find Number 2 and 5, and also that number 2 appears to go to 40GB and number 5 starts at the same point and only goes to 34.4GB.

Someone must have tried this before me but also failed.

Also strange: /dev/sda2 exists but does not show up in the output of df -h.

I don't know what to do here. Do I need to merge sda1 and sda2 somehow? How would I even do that? What about that swap partition? Do I need to change it to start at the end of sda2? How do I do that?

Any help would be appreciated. I just want to get this system to be simple and orderly, easy to manage.

KoenDG
  • 5

2 Answers2

1

/dev/sda2 is an extended partition. What this means is it's one large partition that within it can be placed multiple 'logical' partitions - in this case, /dev/sda2 is an extended partition that fills the rest of your disk after the first partition /dev/sda1, and within /dev/sda2 your swap partition exists as /dev/sda5.

To extend your /dev/sda1 you need to do the following first:

  1. Disable your swap partition. sudo swapoff /dev/sda5
  2. Using gparted, shrink /dev/sda2 so it contains only /dev/sda5 and no free space.
  3. Using gparted, move /dev/sda2 and /dev/sda5 together to the end of the disk.
  4. Resize (grow) your /dev/sda1 after the previous tasks are completed.
  5. Reenable your swap partition. sudo swapon /dev/sda5

Alternatively, you can do the following instead, which gets you more in line with what modern Ubuntu does (which is to use swapfiles instead of swap partitions):

  1. Disable your swap partition. sudo swapoff /dev/sda5

  2. Delete both partition 5 and Partition 2 via parted

  3. Grow your /dev/sda1 and its filesystem.

  4. Use a swapfile instead of a swap partition, from within your single partition.

    sudo fallocate -l 4GiB /swapfile
    sudo mkswap /swapfile
    sudo swapon /swapfile
    
  5. Once the swapfile is created, add this to /etc/fstab on the end of the line so that the swapfile is enabled automatically at boot time:

    /swapfile    swap    swap    sw    0    0
    
Thomas Ward
  • 74,764
  • Oh dear, it's been almost a year since I checked this account.

    The second option worked, but needed on more command for createing the swap file, as step 2: sudo mkswap /swapfile

    – KoenDG Mar 10 '22 at 10:08
-2

You can use these two commands

sudo growpart /dev/sda 
sudo resize2fs /dev/sda
storm
  • 4,973
aZaD
  • 11