Allocating a Windows Disk Partition to CentOS 6

From Techotopia
Revision as of 19:56, 27 October 2016 by Neil (Talk | contribs) (Text replacement - "<table border="0" cellspacing="0">" to "<table border="0" cellspacing="0" width="100%">")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
PreviousTable of ContentsNext
Installing CentOS 6 with Windows in a Dual Boot EnvironmentLogging into the CentOS 6 GNOME Desktop


You are reading a sample chapter from the CentOS 6 Essentials Essentials book.

Purchase a copy of the fully updated CentOS 8 edition in eBook ($24.99) or Print ($36.99) format

CentOS 8 Essentials Print and eBook (ePub/PDF/Kindle) editions contain 31 chapters and over 260 pages. Learn more...

Buy Print Preview Book


In the previous chapter we looked at how to install CentOS 6 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. Performing this type of installation was covered in Installing CentOS 6 with Windows in a Dual Boot Environment.

This chapter is intended for users who have decided they like CentOS 6 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.


Contents


Deleting the Windows Partition from the Disk

The first step in freeing up the Windows partition for use by CentOS 6 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 6 partitions. Having done that, it is safe to proceed with this chapter.

In order to remove the Windows partition we first need to identify it using the fdisk tool:

[root@localhost ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x86008600

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        1276    10249438+   7  HPFS/NTFS
/dev/sda2            1277        1340      512000   83  Linux
/dev/sda3            1340        2611    10209280   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 three partitions accessed via the device names /dev/sda1 through /dev/sda3 respectively. Based on the values in the System column, there is one NTFS partition. This NTFS partition is the one containing the Windows operating system and user data that we plan to remove. Note that a FAT partition also indicates the presence of a Windows installation.

To remove the partition, start the fdisk tool using the device name of the disk containing the partition (/dev/sda in this instance) and follow the instructions to switch out from DOS mode and to display sectors:

# su -
# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): c
DOS Compatibility flag is not set

Command (m for help): u
Changing display/entry units to sectors

Command (m for help):

Next, display the partition table information for the disk drive using the p command:

Command (m for help): p

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 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
Disk identifier: 0x86008600

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *          63    20498939    10249438+   7  HPFS/NTFS
/dev/sda2        20500480    21524479      512000   83  Linux
/dev/sda3        21524480    41943039    10209280   8e  Linux LVM

Make a note of the end sector of the partition we will be deleting (/dev/sda1 in this instance).

At the command prompt, delete the Windows partition (which is partition 1 on our example system):

Command (m for help): d
Partition number (1-5): 1

Command (m for help):

Now that we have deleted the Windows partition we now need to create the new Linux 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. In the case of the start sector accept the default value offered by fdisk. Enter the end sector exactly 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
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20500479, default 20500479):  20498939

Having made these changes the next step is to check that the settings are correct:

Command (m for help): p

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 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
Disk identifier: 0x86008600

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048    20498939    10248446   83  Linux
/dev/sda2        20500480    21524479      512000   83  Linux
/dev/sda3        21524480    41943039    10209280   8e  Linux LVM

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!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

If you see a warning similar to the one indicated in the above output you will need to reboot your CentOS 6 system to be sure the new partition table information is picked up by the system kernel before proceeding.

Formatting the Unallocated Disk Partition

In order to make the new partition suitable for use by CentOS 6, it needs to have a file system created on it. The default file system type for the current release of CentOS 6 is ext4. Creation of the file system is performed using the mkfs command as follows:

[root@localhost ~]# mkfs -t ext4 /dev/sda1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
640848 inodes, 2562111 blocks
128105 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2625634304
79 block groups
32768 blocks per group, 32768 fragments per group
8112 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

Editing the Boot Menu

The next step is to modify the boot menu. Since this was originally a dual boot system, the menu is configured to provide the option of booting either Windows or CentOS 6. Now that the Windows partition is gone, we need to remove this boot option. This is achieved by editing the menu.lst as follows:

su - 
gedit /boot/grub/menu.lst

Towards the bottom of the grub.conf file you will see a section similar to:

 
title Windows
        rootnoverify (hd0,0)
        chainloader +1

Delete this section from the file. Also check the default= value to make sure the default is not set to the partition which was just deleted. Save the file once the changes have been made.

Mounting the New Partition

Finally, 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 CentOS 6 Volume Group and Logical Volume). First we need to create the directory to act as the mount point:

su - 
mkdir /data

Secondly, we need to edit the mount table so that the partition is automatically mounted each time system starts:

gedit /etc/fstab

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

/dev/sda1 /data ext4 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, try running the following command to display the available space:

 
df -h /data

You should see output similar to:

[root@localhost ~]# df -h /data
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             9.7G  150M  9.0G   2% /data


You are reading a sample chapter from the CentOS 6 Essentials Essentials book.

Purchase a copy of the fully updated CentOS 8 edition in eBook ($24.99) or Print ($36.99) format

CentOS 8 Essentials Print and eBook (ePub/PDF/Kindle) editions contain 31 chapters and over 260 pages. Learn more...

Buy Print Preview Book



PreviousTable of ContentsNext
Installing CentOS 6 with Windows in a Dual Boot EnvironmentLogging into the CentOS 6 GNOME Desktop