CentOS 8 Essentials
上QQ阅读APP看书,第一时间看更新

5.2 Deleting the Windows Partitions from the Disk

The first step in freeing up the Windows partition for use by CentOS 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 CentOS 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/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: 0xe3673009

 

Device Boot Start End Sectors Size Id Type

/dev/sda1 * 2048 1126399 1124352 549M 7 HPFS/NTFS/exFAT

/dev/sda2 1126400 53655551 52529152 25G 7 HPFS/NTFS/exFAT

/dev/sda3 53655552 55752703 2097152 1G 83 Linux

/dev/sda4 55752704 104857599 49104896 23.4G 5 Extended

/dev/sda5 55754752 104857599 49102848 23.4G 8e Linux LVM

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.

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.32.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: 0xe3673009

 

Device Boot Start End Sectors Size Id Type

/dev/sda1 * 2048 1126399 1124352 549M 7 HPFS/NTFS/exFAT

/dev/sda2 1126400 53655551 52529152 25G 7 HPFS/NTFS/exFAT

/dev/sda3 53655552 55752703 2097152 1G 83 Linux

/dev/sda4 55752704 104857599 49104896 23.4G 5 Extended

/dev/sda5 55754752 104857599 49102848 23.4G 8e Linux LVM

 

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 end of /dev/sda2).

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): d

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 CentOS 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:

Command (m for help): n

Partition type

   p primary (1 primary, 1 extended, 2 free)

   l logical (numbered from 5)

Select (default p): p

Partition number (1,2, default 1): 1

First sector (2048-104857599, default 2048):

Last sector, +sectors or +size{K,M,G,T,P} (2048-53655551, default 53655551):

 

Created a new partition 1 of type 'Linux' and of size 25.6 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: 0xe3673009

 

Device Boot Start End Sectors Size Id Type

/dev/sda1 2048 53655551 53653504 25.6G 83 Linux

/dev/sda3 * 53655552 55752703 2097152 1G 83 Linux

/dev/sda4 55752704 104857599 49104896 23.4G 5 Extended

/dev/sda5 55754752 104857599 49102848 23.4G 8e Linux LVM

 

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.