Ubuntu – Creating swap partition, convert primary partitions to logical

dual-bootpartitioningswap

I tried to install Ubuntu 14.04 into my laptop which already has got windows 8 installed in it. I had a 30GB free space and I allocated 29 out of that 30 as primary partition for Ubuntu. I wanted to use the remaining 1GB as my swap area. But once the partition for Ubuntu installation is created, the rest of the free space became unusable.

I searched through the web and realized that I have already got maximum number of primary partitions in my HDD. Now I need to know that,

  1. How to know whether a particular partition is a primary one or a logical one(In this case, I would appreciate if you can provide me a way to know that in Windows environment.).
  2. Can I convert the partition type into logical from primary?
  3. If partitions can be converted into logical from primary, how to do so?
  4. Will it harm my files in the particular partition?
  5. Finally, If I have a big enough RAM, Do I need to create a swap area.?

Best Answer

First, if Windows 8 was pre-installed on the computer, it probably used the GUID Partition Table (GPT), which does not suffer from the 4-partition limit of the older Master Boot Record (MBR) partitioning system. Therefore, I recommend you check your partition table type. You can do this from an Ubuntu live disk (or your installed Ubuntu, if you've gotten that far) by typing sudo parted /dev/sda print | grep Table. (This assumes you've got just one disk; if you've got more than one disk, do the same for each one, such as /dev/sdb, /dev/sdc, and so on.) If the output reads Partition Table: gpt, you're using GPT, and something other than the 4-partition limit is causing you problems; if it reads Partition Table: msdos, then you're using MBR. All this said, your symptom certainly sounds like the MBR 4-partition limit, so I'll assume that's what you're encountering. (Windows 8 may use MBR if you installed it or re-installed yourself, especially on an older computer.)

In Linux, if you type sudo parted /dev/sda print, you'll see your partitions. Primaries are numbered 1-4 and logical partitions are numbered 5 and up. The same is true if you use sudo fdisk -l /dev/sda. In GParted, the same numbering applies, but you'll also see the representation in the GUI shows logical partitions contained in the pale blue extended partition. This is easy to overlook, but it's pretty clear once you know about it. Third-party Windows tools should make this clear, too, although I'm not familiar enough with any of them to give you details. Unfortunately, the stock GUI tools that come with Windows are as clear as mud about this, so I don't recommend you use them for this purpose. Also, do not use the stock Windows tools to create partitions, particularly if that would bring their number over 4; these tools tend to convert from a plain-vanilla MBR setup to a proprietary Windows format atop MBR, and that proprietary format is essentially unusable for Ubuntu.

As to converting partitions from one type to another, it is possible, using the fixparts program that comes with Ubuntu in the gdisk package. See its online documentation for details. (Note: I'm the author of FixParts.) The big caveat is that converting to logical form requires a small gap before each to-be-logical partition. Given your layout, you might need to slightly shrink the partition before your Linux partition to make this work. Some third-party Windows tools can also reportedly do this conversion, but I'm not familiar enough with them to give details. There is a Windows version of FixParts, too. Whenever you muck with partition tables, there's some risk of catastrophic data loss, so you should definitely do this only after backing up important data. That said, the primary-to-logical conversion is simple compared to some (such as partition resizing, especially resizing from the front of the partition).

Swap space is optional for most purposes. Today, it's most useful if you want to perform suspend-to-disk operations, in which case you need at least as much swap space as you have RAM. It's also useful if you've got relatively little RAM, and to help the kernel improve performance by allocating RAM efficiently. (It can swap out programs you haven't used in ages, freeing up the RAM for use by caches.) You can set up a swap file rather than a swap partition, if you so desire.

Related Question