Allocating Windows Disk Partitions to Ubuntu 20.04

In the previous chapter we looked at how to install Ubuntu on the same disk as Windows. This so called “dual boot” configuration allows the user to have both operating systems installed on a single disk drive with the option to boot one or the other when the system is powered on. This chapter is intended for users who have decided they like Ubuntu enough to delete Windows entirely from the disk, and use the resulting space for Linux. In the following sections we will work through this process step by step.

1.1  Unmounting the Windows Partition

If the steps in the ”Dual Booting Ubuntu with Windows” chapter were followed to mount the Windows partition from within Ubuntu, steps should be taken to unmount the partition before continuing with this chapter. Assuming that the Windows partition was mounted as /mnt/ windows, it can be unmounted as follows:

# umount /mnt/windows

The /etc/fstab file should also be edited to remove the /mnt/windows auto-mount if it was previously added.

1.2  Deleting the Windows Partitions from the Disk

The first step in freeing up the Windows partition for use by Ubuntu is to delete that partition. Before doing so, however, it is imperative that any data you need to keep is backed up from both the Windows and Ubuntu partitions. Having done that, it is safe to proceed with this chapter. In order to remove the Windows partitions we first need to identify the disk on which they reside using the fdisk tool:

# fdisk -l
Disk /dev/loop0: 3.7 MiB, 3862528 bytes, 7544 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes 
.
.
Device     Boot    Start       End  Sectors  Size Id Type
/dev/sda1  *        2048   1187839  1185792  579M  7 HPFS/NTFS/exFAT
/dev/sda2        1187840  59770533 58582694   28G  7 HPFS/NTFS/exFAT
/dev/sda3       59770878 104855551 45084674 21.5G  5 Extended
/dev/sda5       59770880 104855551 45084672 21.5G 83 Linux
. 
.

In the above example output the system contains one physical disk drive referenced by device name /dev/sda. On that disk drive are five partitions accessed via the device names /dev/sda1 through /dev/sda5 respectively. Based on the values in the System column, there are two NTFS partitions. The first is the Windows system partition while the second, much larger, NTFS partition is the Windows boot partition containing the Windows operating system and user data. On some systems, an additional Windows Recovery partition may be listed and may also be deleted to free up space for Ubuntu. If such a partition exists, it will likely be listed as follows:

 

You are reading a sample chapter from Ubuntu 20.04 Essentials. Buy the full book now in eBook ($14.99) or Print ($36.99) format. Includes 37 chapters. Learn more.

Preview  Buy eBook  Buy Print

 

/dev/sda3 967012352 9767710719758720 4.7G 27 Hidden NTFS WinRE

To remove the partitions, start the fdisk tool using the device name of the disk containing the partition (/dev/sda in this instance) and follow the instructions to once again display the partition and sector information:

# fdisk /dev/sda
 Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 sectors
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: 0x7ef44412

Device     Boot    Start       End  Sectors  Size Id Type
/dev/sda1  *        2048   1187839  1185792  579M  7 HPFS/NTFS/exFAT
/dev/sda2        1187840  59770533 58582694   28G  7 HPFS/NTFS/exFAT
/dev/sda3       59770878 104855551 45084674 21.5G  5 Extended /dev/sda5       59770880 104855551 45084672 21.5G 83 Linux
 Command (m for help):

Currently, the Windows system partition is listed as being the bootable partition. Since we will be deleting this partition, the Linux boot partition needs to be marked as bootable. In the above configuration, this is represented by /dev/sda3. Remaining within the fdisk tool, make this the bootable partition as follows:

Command (m for help): a
Partition number (1,3-5, default 5): 3
The bootable flag on partition 3 is enabled now.

Before proceeding, make a note of the start and end addresses of the partitions we will be deleting (in other words the start of /dev/sda1 and the sector before the start of /dev/sda3).

At the command prompt, delete the Windows partitions (these being partitions 1 and 2 on our example system):

Command (m for help): d
Partition number (1-5, default 5): 1
 Partition 1 has been deleted.
Command (m for help): 
Partition number (2-5, default 5): 2
 Partition 2 has been deleted.

Now that we have deleted the Windows partitions we need to create the new partition in the vacated disk space. The partition number must match the number of the partition removed (in this case 1) and is going to be a primary partition. It will also be necessary to enter the Start and End sectors of the partition exactly as reported for the old partition (fdisk will typically offer the correct values by default, though it is wise to double check). If you are prompted to remove the NTFS signature, enter Y:

 

You are reading a sample chapter from Ubuntu 20.04 Essentials. Buy the full book now in eBook ($14.99) or Print ($36.99) format. Includes 37 chapters. Learn more.

Preview  Buy eBook  Buy Print

 

Command (m for help): n Partition type    p   primary (0 primary, 1 extended, 3 free)    l   logical (numbered from 5) Select (default p): p
Partition number (1,2,4, default 1): 1 First sector (2048-104857599, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-59770877, default 59770877):
 Created a new partition 1 of type 'Linux' and of size 28.5 GiB.
Partition #1 contains a ntfs signature.
Do you want to remove the signature? [Y]es/[N]o: Y
 The signature will be removed by a write command.

Having made these changes the next step is to check that the settings are correct (taking this opportunity to double check that the Linux boot partition is bootable):

Command (m for help): p
Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 sectors
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: 0x7ef44412
Device     Boot    Start       End  Sectors  Size Id Type
/dev/sda1           2048  59770877 59768830 28.5G 83 Linux
/dev/sda3  *    59770878 104855551 45084674 21.5G  5 Extended /dev/sda5       59770880 104855551 45084672 21.5G 83 Linux
 Filesystem/RAID signature on partition 1 will be wiped.

To commit the changes we now need to write the new partition information to disk and quit from the fdisk tool:

Command (m for help): w 
The partition table has been altered.
Syncing disks.

1.3  Formatting the Unallocated Disk Partition

In order to make the new partition suitable for use by Ubuntu, it needs to have a file system created on it. The recommended file system type for the current release of Ubuntu is XFS which will be covered in greater detail in the chapter entitled “Adding a New Disk Drive to an Ubuntu System”. Creation of the file system is performed using the mkfs.xfs command as follows (installing the xfsprogs package if necessary):

# apt install xfsprogs
# mkfs.xfs /dev/sda1 

1.4  Mounting the New Partition

Next, we need to mount the new partition. In this example we will mount it in a directory named / data. You are free, however, to mount the new partition using any valid mount point you desire or to use it as part of a logical volume (details of which are covered in the chapter entitled “Adding a New Disk to an Ubuntu Volume Group and Logical Volume”). First we need to create the directory to act as the mount point:

# mkdir /data

Secondly, we need to edit the mount table in /etc/fstab so that the partition is automatically mounted each time the system starts. At the bottom of the /etc/fstab file, add the following line to mount the new partition (modifying the /dev/sda1 device to match your environment):

 

You are reading a sample chapter from Ubuntu 20.04 Essentials. Buy the full book now in eBook ($14.99) or Print ($36.99) format. Includes 37 chapters. Learn more.

Preview  Buy eBook  Buy Print

 

/dev/sda1 /data xfs defaults 0 0

Finally, we can manually mount the new partition (note that on subsequent reboots this will not be necessary as the partition will automount as a result of the setting we added to the /etc/fstab file above).

# mount /data

To check the partition, run the following command to display the available space:

# df -h /data
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        29G   62M   29G   1% /data

1.5  Editing the Boot Menu

The next step is to modify the Ubuntu boot menu. Since this was originally a dual boot system, the menu is configured to provide the option of booting either Windows or Ubuntu. Now that the Windows partition is gone, we need to remove this boot option. On Ubuntu this can be achieved by running the update-grub command as follows:

# update-grub
Sourcing file `/etc/default/grub'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.3.0-42-generic
Found initrd image: /boot/initrd.img-5.3.0-42-generic
Found linux image: /boot/vmlinuz-5.3.0-28-generic
Found initrd image: /boot/initrd.img-5.3.0-28-generic
Found memtest86+ image: /boot/memtest86+.elf
Found memtest86+ image: /boot/memtest86+.bin

Since there is now only one operating system to boot, the system will automatically boot Ubuntu on the next restart without displaying the boot menu. If you need to access this boot menu, for example to use the advanced boot options, simply press the Esc key during the initial stages of the startup process.

1.6  Using the GNOME Disks Utility

The gnome-disks utility provides a user-friendly graphical alternative to reclaiming the Windows partitions from the command-line. Since the example used here will convert the Windows NTFS partitions to XFS format, the first step us to install the xfsprogs package as follows:

 

You are reading a sample chapter from Ubuntu 20.04 Essentials. Buy the full book now in eBook ($14.99) or Print ($36.99) format. Includes 37 chapters. Learn more.

Preview  Buy eBook  Buy Print

 

# apt install xfsprogs

Once the package has been installed, open a terminal window and launch the gnome-disks utility:

# gnome-disks

After a short delay, the gnome-disks tool will appear as shown in Figure 6-1:

Figure 6-1

In the above example, the disk contains two Windows NTFS partitions which will need to be deleted. Any NTFS partitions with a star shown in the disk map (as is the case for the highlighted partition in the above figure) will need to be unmounted before they can be deleted. This can be achieved by selecting the partition and clicking on the unmount button as indicated in Figure 6-2 below:

Figure 6-2

 

You are reading a sample chapter from Ubuntu 20.04 Essentials. Buy the full book now in eBook ($14.99) or Print ($36.99) format. Includes 37 chapters. Learn more.

Preview  Buy eBook  Buy Print

 

With all the NTFS partitions unmounted, the next step is to delete them. Select the left-most partition in the disk map and click on the Delete button as shown in Figure 6-3:

Figure 6-3

Review the information in the confirmation dialog before clicking on the Delete button to commit the change. Once the first partition has been deleted, repeat this step for any remaining NTFS partitions.

Once the NTFS partitions have been removed, the space should now be shown as being free within the disk map.

A new partition now needs to be created to make use of this free space. With the space selected, click on the new partition button (indicated by the arrow in Figure 6-4):

 

You are reading a sample chapter from Ubuntu 20.04 Essentials. Buy the full book now in eBook ($14.99) or Print ($36.99) format. Includes 37 chapters. Learn more.

Preview  Buy eBook  Buy Print

 

Figure 6-4

In the Create Partition dialog, choose whether the partition is to occupy all of the available space, or reduce the size if you plan to use the space for more than one partition:

Figure 6-5

Click next and, on the subsequent screen, enter a name for the new partition and choose whether the partition should be erased during creation. This causes the creation process to take more time but is a recommended option. Finally, choose a filesystem type for the partition. This will typically be either ext4 or XFS. Given the benefits of XFS, select Other before clicking the Next button:

Figure 6-6

 

You are reading a sample chapter from Ubuntu 20.04 Essentials. Buy the full book now in eBook ($14.99) or Print ($36.99) format. Includes 37 chapters. Learn more.

Preview  Buy eBook  Buy Print

 

On the next screen, select the XFS option before clicking on the Create button:

Figure 6-7

If the XFS option is disabled, exit from gnome-disks and install the xfsprogs package before trying again:

# apt install xfsprogs

The gnome-disks utility will begin the formatting process and display the status of the process:

Figure 6-8

 

You are reading a sample chapter from Ubuntu 20.04 Essentials. Buy the full book now in eBook ($14.99) or Print ($36.99) format. Includes 37 chapters. Learn more.

Preview  Buy eBook  Buy Print

 

Once the partition is ready, it can be mounted either from the command-line or using the gnomedisks utility. To configure a mount point, select the partition and click on the settings button as shown in Figure 6-9:

Figure 6-9

From the settings menu, select the Edit Mount Options… item to display the dialog shown in Figure 6-10.

Figure 6-10

Turn off the User Session Defaults switch and configure the mount point to your requirements. In the above figure, the partition is mounted at /data at system startup and is configured to be identified by the label “Data”.

 

You are reading a sample chapter from Ubuntu 20.04 Essentials. Buy the full book now in eBook ($14.99) or Print ($36.99) format. Includes 37 chapters. Learn more.

Preview  Buy eBook  Buy Print

 

Once the settings are complete, click on OK. The volume is now mounted and ready for use:

$ df -h /mnt/Data
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1        29G   62M   29G   1% /data

Finally, update the boot menu to remove the Windows option using the steps outlined in section 1.5 above.

1.7  Summary

The Windows partitions in a dual boot configuration can be removed at any time to free up space for an Ubuntu system by identifying which partitions belong to Windows and then deleting them. Once deleted, the unallocated space can be used to create a new filesystem and mounted to make it available to the Ubuntu system. The final task is to remove the Windows option from the boot menu configuration. These tasks can be performed either from the command-line using fdisk, or from within the desktop environment using gnome-disks.