I have a hard disk with Ubuntu 18.04 installed, but I want to add Debian. My HDD is formatted as ext4 and I have currently a home, root, swap and efi partitions (sda1, sda2, sda3 and sda4), and, although I have free space to install Debian, I can't, because apparently for ext4 partitions the maximum number of logical spaces is 4. Any suggestions on how to solve the problem? Do LVM partitions allow for more than 4 logical partitions?

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:    18.04
Codename:   bionic

enter image description here

  • 1
    GPT allows for more partitions, but to switch from a MBR/legacy/DOS partition table to GPT generally requires starting again. You can have 4 primary partitions on a legacy/DOS partition table, which includes an extended allowing more logical partitions within the space owned by the extended partition they're created in. One fix maybe to remove swap partition and use that partition for Debian instead (and make your existing Ubuntu use swapfile instead of swap partition. You haven't given specs as to your Ubuntu release so this maybe easy, may not be. – guiverc Sep 8 at 2:57
  • It is Ubuntu 18. So the most correct way to do this is to re-format the entire HDD for GPT, and then reinstall Ubuntu and Debian? @guiverc – Carolina Naccarato Sep 8 at 3:10
  • Ubuntu 18? Do you mean Ubuntu Core 18? As all desktop and server releases of Ubuntu use the yy.mm and only specialist snap based releases use yy format. I have less experience with IoT or appliance releases of Ubuntu sorry. It's up to you, you can use swap as I mentioned (I don't know if Ubuntu Core 18 can use swapfiles, but 18.04 can) and use that partition as extended, sub-dividing it into many for debian if you want multiple partitions for your Debian install. Up to you, but note I've little experience with appliance based Ubuntu Core 18 – guiverc Sep 8 at 3:16
  • Generally, older BIOS computers use MBR disk formatting which is limited to 4 partitions. This is usually done as 3 primary partitions, and one extended partition. The extended partition can contain more logical partitions (trickery). Most modern UEFI computers use GPT disk formatting, which can contain an almost unlimited number of partitions. If you'd edit your question with a screenshot of gparted, I can make a better recommendation. Start comments to me with @heynnema or I'll miss them. – heynnema Sep 8 at 4:58
  • Also, is there a special reason to install Debian? Ubuntu is Debian based, so there's not a lot of differences. Please edit your question again with the result of lsb_release -a. Thanks. – heynnema Sep 8 at 5:06

You can do this without too much effort.

We disable partition swap, create a /swapfile, delete the swap partition, and then you'll be able to install Debian into the unallocated space.

Disable partition swap

sudo swapoff -a # disable current swap

sudo -H gedit /etc/fstab # edit fstab

Remove, or comment out, the line that looks similar to this:

UUID=xxxx-xxxx-xxxx-xxxx-xxxx  none  swap       sw       0       0

Add this line:

/swapfile    none    swap    sw      0   0

Save the edits.

Now we create a /swapfile.

Note: Incorrect use of the dd command can cause data loss. Suggest copy/paste.

sudo swapoff -a           # turn off swap
sudo rm -i /swapfile      # remove old /swapfile

sudo dd if=/dev/zero of=/swapfile bs=1M count=4096

sudo chmod 600 /swapfile  # set proper file protections
sudo mkswap /swapfile     # init /swapfile
sudo swapon /swapfile     # turn on swap
free -h                   # confirm nnG RAM and 4G swap

Confirm this line in /etc/fstab... and confirm no other “swap” lines...

/swapfile    none    swap    sw      0   0

Delete old partitions

Then use gparted to delete /dev/sda5, and then delete /dev/sda2.

reboot                    # reboot and verify operation

Install Debian

Then you can install Debian. If Debian can use its own /swapfile (rather than its own swap partition), then use that for swap space.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.