Difference between revisions of "Installing CentOS 6 with Windows in a Dual Boot Environment"

From Techotopia
Jump to: navigation, search
m (Text replacement - "<table border="0" cellspacing="0">" to "<table border="0" cellspacing="0" width="100%">")
 
(7 intermediate revisions by the same user not shown)
Line 8: Line 8:
  
  
<google>BUY_CENTOS6</google>
+
<htmlet>centos6</htmlet>
  
  
Line 25: Line 25:
 
Right click on the partition you wish to reduce and select Shrink Volume. The tool will calculate the maximum amount by which the volume may be reduced without data loss (a process that can take several minutes depending on the overall size of the partition). Once this analysis is complete, a dialog similar to the one in the following figure will appear:
 
Right click on the partition you wish to reduce and select Shrink Volume. The tool will calculate the maximum amount by which the volume may be reduced without data loss (a process that can take several minutes depending on the overall size of the partition). Once this analysis is complete, a dialog similar to the one in the following figure will appear:
  
<google>ADSDAQBOX_FLOW</google>
+
<htmlet>adsdaqbox_flow</htmlet>
 
[[Image:windows_volume_shrink.png|Shrinking a Windows NTFS partition]]
 
[[Image:windows_volume_shrink.png|Shrinking a Windows NTFS partition]]
  
Line 452: Line 452:
  
  
<google>BUY_CENTOS6</google>
+
<htmlet>centos6</htmlet>
  
  
 +
 +
<htmlet>ezoicbottom</htmlet>
 
<hr>
 
<hr>
 
<table border="0" cellspacing="0" width="100%">
 
<table border="0" cellspacing="0" width="100%">

Latest revision as of 20:03, 27 October 2016

PreviousTable of ContentsNext
Performing a CentOS 6 Network InstallationAllocating a Windows Disk Partition to CentOS 6


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


CentOS 6, in common with most Linux distributions, will happily co-exist on a hard disk drive with just about any version of Windows up to and including Windows 7 and Windows Server 2008 R2. This is a concept known as dual-booting. Essentially, when you power up the system, you will be presented with a menu providing the option to boot either your CentOS 6 installation or Windows. Obviously you can only run one operating system at a time in such a configuration, but it is worth noting that the files on the Windows partition of your disk drive will be available to you from CentOS 6 regardless of whether your Windows partition was formatted using Microsoft’s NTFS, FAT16 or FAT32 file system formats.

This installation method involves shrinking the size of the existing Windows partition to accommodate the installation of CentOS 6. How you go about doing this will depend on the version of Windows currently installed on the disk.


Contents


Partition Resizing

In order to accommodate CentOS 6 on a disk drive that already contains a Windows installation the first step involves shrinking the Windows partition to make some room. If you are running Windows Vista, Windows 7, Windows Server 2008 or later, the recommended course of action is to use the Windows Disk Management interface to reduce the size of the partition prior to attempting to install CentOS 6. You can generally access this by right clicking on the Computer icon and selecting Manage from the popup menu. Within the Computer Management interface, select Disk Management to display a graphical representation of the disk drives in your system:


The Windows Disk Management Tool


Right click on the partition you wish to reduce and select Shrink Volume. The tool will calculate the maximum amount by which the volume may be reduced without data loss (a process that can take several minutes depending on the overall size of the partition). Once this analysis is complete, a dialog similar to the one in the following figure will appear:

Shrinking a Windows NTFS partition

Enter into the Total size after shrink in MB field the new target size for the partition and click on Shrink to proceed. Once the resizing operation is complete, reboot using the CentOS 6 installation media (as outlined in Installing CentOS 6 on a Clean Disk Drive) and proceed with the installation. When prompted to decide on where CentOS 6 is to be installed be sure to select the Use Free Space option.

Shrinking the Windows Partition from within Linux

Whilst it is possible to shrink existing Windows partitions using the Windows Disk Management tool on recent versions of Windows, this is not possible from within Windows XP or earlier Windows releases. If you need to shrink a Windows XP partition in order to install CentOS 6, one option is to use one of the commercially available partitioning tools such as PartitionMagic. If you would prefer not to buy a partitioning tool, the repartitioning may also be performed from within the CentOS 6 Live CD distribution using the fdisk and ntfsresize utilities. As outlined in the chapter entitled Installing CentOS 6 on a Clean Disk Drive, a Live CD is a CDROM from which a Linux distribution can be booted and run without the necessity to install the operating system on a disk drive.

Before attempting this resizing technique it is vital that you back up all essential data from your Windows system. In this section we will be performing some low level disk partitioning activities using command line tools. Whilst following these steps is an invaluable method for learning about the structure of disk partitions, it is important that you understand that errors in performing the following steps may result in loss of data. With that warning out of the way we can proceed.

The CentOS Live CD image can be downloaded from the mirror sites listed on the CentOS web site at:

http://mirror.centos.org/centos/6/isos/

Once you have loaded this page into your browser, select either the i386 or x86_64 link depending on whether the target system is a 32-bit or 64-bit platform. Within the next screen, select a mirror from the list and look for a link to download the Live CD image. This will typically be named as follows:

CentOS-<version>-<architecture>-LiveCD.iso

Once you have downloaded the image, burn it to a CD, then make sure your BIOS is configured to boot from the CDROM/DVD drive before the hard disk and then boot from the CD. The system will boot CentOS and you will have a fully functional CentOS environment to use during the repartitioning process.

Once CentOS has loaded, log in and open a terminal window (right click anywhere on the desktop and select Open in Terminal). In the terminal window, gain root privileges by executing the following command:

su –

The fdisk tool is installed by default but the ntfsresize tool is not part of the standard CentOS distribution or installation repositories. Instead, we need to install from a different source. To enable access to the required repository, one of the following commands must be run depending on whether you are running a 32-bit or 64-bit version of CentOS:

For 32-bit systems:

rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm

For 64-bit systems:

rpm -Uhv http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm

Next, we need to install the package that contains the ntfsresize utility:

yum install ntfsprogs

Now that we have installed the tools we need, the next step is to identify the disk drive on which the Windows partition resides. This is achieved by running the fdisk command as follows:

[root@livecd ~]# 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        2609    20956761    7  HPFS/NTFS

As we can see, in the case of the above example, we have a single disk drive (/dev/sda) which contains a single partition (/dev/sda1) that is formatted as NTFS (a sure sign that is a Windows partition). Since the Boot column for /dev/sda1 contains an asterisk we also know this is currently the hard disk’s boot partition. Depending on your system configuration you may see different results (for example if you have multiple disk drives or the disk drive contains more than one partition).

Having identified the disk and partition, we now need to find out how much unused space is available within the partition for us to free up. To obtain this information we use the ntfsresize tool as follows:

[root@livecd ~]# ntfsresize -i /dev/sda1
ntfsresize v1.13.1 (libntfs 9:0:0)
Device name        : /dev/sda1
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 21459722752 bytes (21460 MB)
Current device size: 21459723264 bytes (21460 MB)
Checking filesystem consistency ...
100.00 percent completed
Accounting clusters ...
Space in use       : 2139 MB (10.0%)
Collecting resizing constraints ...
You might resize at 3232075776 bytes or 3233 MB (freeing 18227 MB).
Please make a test run using both the -n and -s options before real resizing!

The output from ntfsresize for our example tells us that we can safely free up 18227MB of disk space by shrinking the specified Windows partition. In practice, however, you will want to leave space on your Windows system for storing future data, so it is recommended that you do not shrink the partition to the full extent available. For the purposes of this example, therefore, we will shrink the partition to 10000MB. Before performing the live resize, it is best to run through a simulation in order to identify any potential problems before permanent changes are made. To do this, run ntfsresize with the –no-action option:

[root@livecd ~]# ntfsresize --no-action -b --size 10000M /dev/sda1
ntfsresize v1.13.1 (libntfs 9:0:0)
Device name        : /dev/sda1
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 21459722752 bytes (21460 MB)
Current device size: 21459723264 bytes (21460 MB)
New volume size    : 9999995392 bytes (10000 MB)
Checking filesystem consistency ...
100.00 percent completed
Accounting clusters ...
Space in use       : 2945 MB (13.7%)
Collecting resizing constraints ...
Needed relocations : 45 (1 MB)
Schedule chkdsk for NTFS consistency check at Windows boot time ...
Resetting $LogFile ... (this might take a while)
Relocating needed data ...
100.00 percent completed
Updating $BadClust file ...
Updating $Bitmap file ...
Updating Boot record ...
The read-only test run ended successfully.

Assuming the read-only test runs successfully, the actual resize can be performed by running the same command, but this time without the –no-action option:

[root@livecd ~]# ntfsresize -b --size 10000M /dev/sda1
ntfsresize v1.13.1 (libntfs 9:0:0)
Device name        : /dev/sda1
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 21459722752 bytes (21460 MB)
Current device size: 21459723264 bytes (21460 MB)
New volume size    : 9999995392 bytes (10000 MB)
Checking filesystem consistency ...
100.00 percent completed
Accounting clusters ...
Space in use       : 2945 MB (13.7%)
Collecting resizing constraints ...
Needed relocations : 45 (1 MB)
WARNING: Every sanity check passed and only the dangerous operations left.
Make sure that important data has been backed up! Power outage or computer
crash may result major data loss!
Are you sure you want to proceed (y/[n])? y
Schedule chkdsk for NTFS consistency check at Windows boot time ...
Resetting $LogFile ... (this might take a while)
Relocating needed data ...
100.00 percent completed
Updating $BadClust file ...
Updating $Bitmap file ...
Updating Boot record ...
Syncing device ...
Successfully resized NTFS on device '/dev/sda1'.
You can go on to shrink the device for example with Linux fdisk.
IMPORTANT: When recreating the partition, make sure that you
  1)  create it at the same disk sector (use sector as the unit!)
  2)  create it with the same partition type (usually 7, HPFS/NTFS)
  3)  do not make it smaller than the new NTFS filesystem size
  4)  set the bootable flag for the partition if it existed before
Otherwise you won't be able to access NTFS or can't boot from the disk!
If you make a mistake and don't have a partition table backup then you
can recover the partition table by TestDisk or Parted's rescue mode.

At this point we have reduced the size of the NTFS partition but the partition does not yet know we have done so. If, for example, we use fdisk to tell us about the partition, the partition table information still indicates the original size:

[root@livecd ~]# 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: 0x8f6a8f6a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        2609    20956761    7  HPFS/NTFS

In order to address this we will have to delete the partition information and then recreate it with the new size information. Before doing so, make a note of the Start and Id values for the partition provided by the above fdisk command (since yours will almost certainly differ from the example and we will need these when we recreate the partition). Begin by starting fdisk with the name of the disk drive on which we are going to modify the partition table information:

[root@livecd ~]# fdisk /dev/sda

At the command prompt, delete the partition (for the example this is partition 1 but may be different on your system):

Command (m for help): d
Selected partition 1

Next, we need to recreate the partition with the new size information (keeping in mind that we reduced the partition to 10000MB):

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1): 1
Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): +10000M

Next, the Id of the partition needs to set to the original value as indicated by the fdisk –l command (in this case 7 to indicate the partition uses the Windows NTFS format):

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 7
Changed system type of partition 1 to 7 (HPFS/NTFS)

Finally, we need to make sure the partition is still bootable:

Command (m for help): p

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

If the Boot column does not contain an asterisk (*) then we need to make the partition bootable before we write the new configuration disk:

Command (m for help): a
Partition number (1-4): 1

Once again, it is prudent to check the settings before proceeding:

Command (m for help): p

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

At this point none of the changes have been written to disk. In the event that the partition settings do not meet your expectations simply exit from fdisk without comitting the changes. If all is well, however, simply write the new partition information to disk as follows:

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

The resize is now complete and you can reboot the system. If you check the disk volumes in the Windows XP disk manager (right click on My Computer, select Manage and choose Disk Management from the Computer Management tool). The newly freed space will be displayed as Unallocated.

Having resized the partition, reboot using the CentOS 6 installation media (as outlined in Installing CentOS 6 on a Clean Disk Drive) and proceed with the installation. When prompted to decide on where CentOS 6 is to be installed be sure to select the Use Free Space option.


Choosing an Operating System at Boot Time

Once the installation completes, the system will display the standard boot countdown screen. Pressing any key on the keyboard at this point will display the boot menu screen as illustrated in the following figure:


Choosing to boot Windows or CentOS 6


This menu provides the option of booting either "CentOS" or "Other". In this instance, selecting "Other" will boot your original Windows installation. In the next section we will cover the steps to modify this menu to change the boot default and rename the "Other" menu option to something more descriptive.

Editing the CentOS 6 Boot Menu

Once you have logged into the system, completed the tasks presented by the setup agent and the desktop is visible the next step is to configure the boot menu so that it lists the alternate operating system as Windows instead of Other. The boot menu configuration settings are stored in the /boot/grub/menu.lst file. This file may be edited in a terminal window as follows:

su -
gedit /boot/grub/menu.lst

When prompted by the su command to enter a password be sure to enter the root password created during the installation process, not the password you created for your user account during the setup agent configuration steps.

The contents of a typical menu.lst file is listed below:

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,1)
#          kernel /vmlinuz-version ro root=/dev/mapper/vg_centos62-lv_root
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,1)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-220.el6.i686)
        root (hd0,1)
        kernel /vmlinuz-2.6.32-220.el6.i686 ro root=/dev/mapper/vg_centos62-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_LVM_LV=vg_centos62/lv_swap rd_LVM_LV=vg_centos62/lv_root rd_NO_MD quiet SYSFONT=latarcyrheb-sun16 rhgb crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM
        initrd /initramfs-2.6.32-220.el6.i686.img
title Other
        rootnoverify (hd0,0)
        chainloader +1

The above menu.lst file contains options to boot for two operating systems. The CentOS section of the configuration typically reads as follows:

title CentOS (2.6.32-220.el6.i686)
        root (hd0,1)
        kernel /vmlinuz-2.6.32-220.el6.i686 ro root=/dev/mapper/vg_centos62-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_LVM_LV=vg_centos62/
lv_swap rd_LVM_LV=vg_centos62/lv_root rd_NO_MD quiet SYSFONT=latarcyrheb-sun16 rhgb 
crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM
        initrd /initramfs-2.6.32-220.el6.i686.img

The Windows section of the configuration is likely to be similar to the following:

title Other
        rootnoverify (hd0,0)
        chainloader +1

The default=0 line indicates that the first entry in the file is to be the default operating system (in other words, the operating system that will boot by default if the user does not intervene during the boot phase). The timeout=5 directive specifies the number of seconds the boot screen is displayed before the default operating system is automatically booted.

To configure the system to boot Windows by default simply change this line so that it reads as follows:

default=1

To increase or decrease the timeout before the default operating system boots, change the timeout value (in this case to 20 seconds):

timeout=20

The final task in our dual boot configuration process is to rename the Windows boot option to something more descriptive than "Other". To achieve this, simply change the "Other" line as follows:

title Windows

Note that the title value can be anything you choose.

The next time the system is rebooted, the boot screen will wait 20 seconds before auto-booting. If no keys are pressed the system will now boot Windows by default, instead of CentOS 6. If the user does intervene and display the boot menu, the Windows option is now titled "Windows" and not "Other".

Accessing the Windows Partition from CentOS 6

When running CentOS 6 in a dual boot configuration it is still possible to access files located on the Windows partition. This can be achieved by manually mounting the partition from the command-line. Before doing so, however, some additional packages need to be installed on the system. To do so, run the following commands inside a terminal window:

su -
yum install fuse

Next, we need to set up access to the Dag RPMForge repositories:

For 32-bit systems:

rpm -Uhv http://apt.sw.be/redhat/el6/en/i386/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.i686.rpm

For 64-bit systems:

rpm –Uhv http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.2-1.el6.rf.x86_64.rpm

Next, install the NTFS driver:

yum install fuse-ntfs-3g

Once the requisite packages are installed, the next step is to create a directory to use as the mount point for our Windows partition. In this example we will create a directory called /windows:

mkdir /windows

When prompted for a password by the su command, enter the root password specified during the CentOS 6 installation process. In order to identify the device name that has been assigned to the Windows partition, use the fdisk command as follows:

[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 output, the main Windows partition containing the files we need access to is /dev/sda1.

Next, we need to run the mount command (still with root privileges and assuming the Windows partition is /dev/sda1 and NTFS format - this may be different on your system):

mount –t ntfs-3g /dev/sda1 /windows

Under some circumstances you may get a message that the Windows partition needs to be checked. If so, either reboot into Windows again and manually run chkdsk (if it does not run automatically during the boot process), or force the mount with the –o option:

mount /dev/sda2 /windows -o force

To automate the mount each time the system is booted, simply add the mount line to the /etc/fstab file:

/dev/sda1 /windows ntfs defaults 0 0

To unmount the Windows file system at any time:

umount /windows


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
Performing a CentOS 6 Network InstallationAllocating a Windows Disk Partition to CentOS 6