Allocating Windows Disk Partitions to AlmaLinux 9

Posted: 2024-02-17

In the previous chapter, we looked at installing AlmaLinux 9 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 AlmaLinux 9 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 using both the command-line tools and the gnome-disks utility.

Unmounting the Windows Partition

If the steps in the Dual Booting AlmaLinux 9 with Windows chapter were followed to mount the Windows partition from within AlmaLinux 9, 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/windowsCode language: plaintext (plaintext)

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

 

You are reading a sample chapter from AlmaLinux 9 Essentials. Buy the full book now in eBook format.

Full book includes 34 chapters and 290 pages. Learn more.

Preview  Buy eBook 

 

Deleting the Windows Partitions from the Disk

The first step in freeing up the Windows partition for use by AlmaLinux 9 is to delete that partition. Before doing so, however, any data you need to keep must be backed up from both the Windows and AlmaLinux 9 partitions. Having done that, it is safe to proceed with this chapter.

To remove the Windows partitions, we first need to identify the disk on which they reside using the fdisk tool:

# fdisk -l
Disk /dev/nvme0n1: 64 GiB, 68719476736 bytes, 134217728 sectors
Disk model: VMware Virtual NVMe Disk
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: gpt
Disk identifier: 7A38CD86-091E-4781-BFB0-928FD383C935

Device             Start       End  Sectors  Size Type
/dev/nvme0n1p1      2048    206847   204800  100M EFI System
/dev/nvme0n1p2    206848    239615    32768   16M Microsoft reserved
/dev/nvme0n1p3    239616  49362943 49123328 23.4G Microsoft basic data
/dev/nvme0n1p4 132933632 134213631  1280000  625M Windows recovery environment
/dev/nvme0n1p5  49362944  51460095  2097152    1G Linux filesystem
/dev/nvme0n1p6  51460096 132933631 81473536 38.8G Linux LVM
Code language: plaintext (plaintext)

In the above example output, the system contains one physical disk drive referenced by device name /dev/nvme0n1. On that disk drive are six partitions accessed via the device names /dev/ nvme0n1p1 through /dev/nvme0n1p, respectively. Based on the values in the Types column, three Windows-related partitions exist. The first is the Windows system partition, while the second, much larger, partition is the Windows boot partition containing the Windows operating system and user data, followed by the Windows recovery partition.

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

# fdisk /dev/nvme0n1

Welcome to fdisk (util-linux 2.37.4).
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/nvme0n1: 64 GiB, 68719476736 bytes, 134217728 sectors
Disk model: VMware Virtual NVMe Disk
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: gpt
Disk identifier: 7A38CD86-091E-4781-BFB0-928FD383C935
 
Device             Start       End  Sectors  Size Type
/dev/nvme0n1p1      2048    206847   204800  100M EFI System
/dev/nvme0n1p2    206848    239615    32768   16M Microsoft reserved
/dev/nvme0n1p3    239616  49362943 49123328 23.4G Microsoft basic data
/dev/nvme0n1p4 132933632 134213631  1280000  625M Windows recovery environment
/dev/nvme0n1p5  49362944  51460095  2097152    1G Linux filesystem
/dev/nvme0n1p6  51460096 132933631 81473536 38.8G Linux LVM
 
Partition table entries are not in disk order.
 
Command (m for help):
Code language: plaintext (plaintext)

Before proceeding, note the start and end addresses of the partitions we will delete (in other words, the start of /dev/nvme0n1p2 and the sector before the start of /dev/nvme0n1p5).

 

You are reading a sample chapter from AlmaLinux 9 Essentials. Buy the full book now in eBook format.

Full book includes 34 chapters and 290 pages. Learn more.

Preview  Buy eBook 

 

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

Command (m for help): d
Partition number (1-6, default 6): 2
 
Partition 2 has been deleted.
 
Command (m for help): d
Partition number (1,3-6, default 6): 3
 
Partition 3 has been deleted.
 
Command (m for help): d
Partition number (1,4-6, default 6): 4
 
Partition 4 has been deleted.
Code language: plaintext (plaintext)

Now that we have deleted the Windows partitions, we must create the new AlmaLinux 9 partition in the vacated disk space. The partition number must match the number of the first partition removed (in this case, 2). It will also be necessary to enter the Start and End sectors of the partition precisely as reported for the old partition (fdisk will typically offer the correct values by default, though it is wise to double-check):

Command (m for help): n
Partition number (2-4,7-128, default 2): 2
First sector (206848-134217694, default 206848): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (206848-49362943, default 49362943): 
 
Created a new partition 2 of type 'Linux filesystem' and of size 23.4 GiB.

Command (m for help): n
Partition number (2-4,6-128, default 2): 2
First sector (206848-134217694, default 206848):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (206848-80185343, default 80185343):
 
Created a new partition 2 of type 'Linux filesystem' and of size 38.1 GiB.
Code language: plaintext (plaintext)

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.
Code language: plaintext (plaintext)

Formatting the Unallocated Disk Partition

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

# mkfs.xfs -f /dev/nvme0n1p2
meta-data=/dev/nvme0n1p2         isize=512    agcount=4, agsize=1536128 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=1 inobtcount=1
data     =                       bsize=4096   blocks=6144512, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=3000, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
Code language: plaintext (plaintext)

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 a Rocky Linux 9AlmaLinux 9 Volume Group and Logical Volume”). First, we need to create the directory to act as the mount point:

 

You are reading a sample chapter from AlmaLinux 9 Essentials. Buy the full book now in eBook format.

Full book includes 34 chapters and 290 pages. Learn more.

Preview  Buy eBook 

 

# mkdir /dataCode language: plaintext (plaintext)

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/nvme0n1p2 device to match your environment):

/dev/nvme0n1p2 /data xfs defaults 0 0Code language: plaintext (plaintext)

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

# mount /dataCode language: plaintext (plaintext)

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

# df -h /data
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p2   24G  200M   24G   1% /data
Code language: plaintext (plaintext)

Editing the Boot Menu

The next step is to modify the AlmaLinux boot menu. Since this was originally a dual boot system, the menu is configured to allow booting either Windows or AlmaLinux. Now that the Windows partition is gone, we must remove this boot option. On AlmaLinux, this can be achieved using the following steps:

# rm -rf /boot/efi/EFI/Microsoft
# grub2-mkconfig --output=/boot/grub2/grub.cfg
Code language: plaintext (plaintext)

Using 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 is to install the xfsprogs package as follows:

 

You are reading a sample chapter from AlmaLinux 9 Essentials. Buy the full book now in eBook format.

Full book includes 34 chapters and 290 pages. Learn more.

Preview  Buy eBook 

 

# dnf install xfsprogsCode language: plaintext (plaintext)

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

$ gnome-disksCode language: plaintext (plaintext)

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

Figure 5-1

In the above example, the disk contains two Windows NTFS partitions that 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) must 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 5-2 below:

Figure 5-2

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

Figure 5-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 use this free space.

 

You are reading a sample chapter from AlmaLinux 9 Essentials. Buy the full book now in eBook format.

Full book includes 34 chapters and 290 pages. Learn more.

Preview  Buy eBook 

 

With the space selected, click on the new partition button (indicated by the arrow in Figure 5-4):

Figure 5-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 5-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, enter a name for the volume and choose a filesystem type. This will typically be either ext4 or XFS. Given the benefits of XFS, select Other before clicking the Next button.

Figure 5-6

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

Figure 5-7

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

 

You are reading a sample chapter from AlmaLinux 9 Essentials. Buy the full book now in eBook format.

Full book includes 34 chapters and 290 pages. Learn more.

Preview  Buy eBook 

 

Figure 5-8

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

Figure 5-9

Select the Edit Mount Options… item from the settings menu to display the dialog shown Figure 5-10.

Figure 5-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 /mnt/Data at system startup and is configured to be identified by the label “Data”.

Once the settings are complete, click on OK, then click the mount button highlighted in Figure 5-11:

 

You are reading a sample chapter from AlmaLinux 9 Essentials. Buy the full book now in eBook format.

Full book includes 34 chapters and 290 pages. Learn more.

Preview  Buy eBook 

 

Figure 5-11

To check that the partition is now mounted and ready for use, run the following command to display the available space:

$ df -h /mnt/Data
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p3   17G  152M   17G   1% /mnt/Data
Code language: plaintext (plaintext)

Finally, update the boot menu to remove the Windows option using the steps outlined earlier in this chapter.

Summary

The Windows partitions in a dual boot configuration can be removed anytime to free up space for an AlmaLinux 9 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 AlmaLinux 9 system.


Categories