Create Bootable USB For CentOS 6.x Installation From DVD ISOs
Creating a bootable USB drive for installing CentOS 6.x using DVD1 and DVD2 ISO files involves partitioning the USB drive, making it bootable, and copying the necessary files. This comprehensive guide will walk you through the entire process, ensuring you have a working USB stick ready to install CentOS 6.x. This method is particularly useful when you don't have access to a DVD drive or prefer a faster installation method. We will discuss the necessary steps in detail, covering everything from partitioning the USB drive to copying the ISO contents.
Prerequisites
Before we begin, make sure you have the following:
- A USB drive with at least 16GB of storage.
- CentOS 6.x DVD1 and DVD2 ISO files.
- A Linux system (or a live Linux environment) to prepare the USB drive. While the steps are primarily designed for Linux, similar tools and commands can be adapted for other operating systems like macOS or Windows with some modifications.
- Root or sudo privileges to execute commands.
Step 1: Identifying the USB Drive
First, you need to identify the correct device name for your USB drive. This is a crucial step because selecting the wrong device can lead to data loss on your system’s hard drives. Use the lsblk
command to list block devices. Before inserting the USB drive, run lsblk
to see the current list of devices. Then, insert the USB drive and run lsblk
again. The new device that appears is your USB drive.
Identifying the correct device is crucial. Pay close attention to the size and labels to ensure you are selecting the USB drive and not an internal hard drive. For example, the output might show something like /dev/sdb
or /dev/sdc
. Once you've identified the correct device, make a note of it, as you'll need it for subsequent commands. Double-check this to avoid any accidental data loss.
Step 2: Partitioning the USB Drive
Next, we'll partition the USB drive into two partitions: one for the bootloader and essential files (1GB), and the other for the rest of the ISO contents. We will use fdisk
, a powerful command-line tool for disk partitioning.
- Open a terminal and run
sudo fdisk /dev/sdX
, replacing/dev/sdX
with the correct device name of your USB drive (e.g.,/dev/sdb
). - Type
o
to create a new empty DOS partition table. This ensures a clean slate for our partitioning. - Type
n
to add a new partition. Selectp
for primary partition. - For the first partition, enter
1
as the partition number. Accept the default first sector by pressing Enter. For the last sector, enter+1G
to create a 1GB partition. This partition will hold the bootloader and necessary boot files. - Type
t
to change the partition's system ID. Enterc
to set the partition type to W95 FAT32 (LBA). This is important for ensuring the partition is recognized as a bootable partition by most systems. - Type
n
again to create the second partition. Selectp
for primary partition. - Enter
2
as the partition number. Accept the default first sector by pressing Enter. For the last sector, accept the default to use the remaining space on the USB drive. - Type
w
to write the changes to the disk. This step is critical, as it applies the partition layout you've just configured. If you're not sure about the changes, double-check before writing.
Partitioning the USB drive is a crucial step in making it bootable. Creating two partitions allows us to isolate the bootloader and essential files from the rest of the ISO content. The first partition, formatted as FAT32, will be used for the bootloader, while the second partition will hold the CentOS installation files. This separation ensures that the bootloader can be easily located and accessed during the boot process. The use of fdisk
provides a robust and reliable method for partitioning the drive, giving you fine-grained control over the layout.
Step 3: Formatting the Partitions
After partitioning, you need to format the partitions with appropriate file systems. We'll format the first partition as FAT32 and the second partition as ISO9660, which is the file system used by ISO images.
- Format the first partition (1GB) as FAT32 using the command:
sudo mkfs.vfat -F 32 /dev/sdX1
. Replace/dev/sdX1
with the actual device name of the first partition (e.g.,/dev/sdb1
). - Format the second partition with an ISO9660 file system. Since we'll be directly copying the ISO files to this partition, we don't need to format it explicitly. We’ll handle this implicitly during the file copy process.
Formatting the partitions correctly ensures that the USB drive can be read by the system during the boot process. The FAT32 file system is widely supported and ideal for the boot partition, while the ISO9660 file system is the standard for ISO images. This step prepares the partitions for the next stage, where we'll copy the necessary files to make the USB drive bootable.
Step 4: Mounting the Partitions
Before copying files, you need to mount both partitions so that you can access them as directories.
- Create mount points for the partitions:
sudo mkdir /mnt/usb1 sudo mkdir /mnt/usb2
- Mount the first partition (FAT32) to
/mnt/usb1
:sudo mount /dev/sdX1 /mnt/usb1
- Mount the second partition (which will hold the ISO contents) to
/mnt/usb2
:sudo mount /dev/sdX2 /mnt/usb2
Mounting the partitions allows us to interact with them as if they were regular directories on our system. This step is essential for copying files to the USB drive. By mounting the partitions, we can easily navigate to them and transfer the required files, including the bootloader and the ISO contents.
Step 5: Making the USB Drive Bootable
To make the USB drive bootable, we need to install a bootloader. Syslinux is a popular bootloader that works well for this purpose.
- Install the
syslinux
package if it’s not already installed:sudo apt-get update # For Debian/Ubuntu systems sudo apt-get install syslinux # OR sudo yum install syslinux # For CentOS/RHEL systems
- Install the MBR (Master Boot Record) bootloader on the USB drive:
(Note: The pathsudo dd bs=440 count=1 conv=notrunc if=/usr/lib/syslinux/mbr.bin of=/dev/sdX
/usr/lib/syslinux/mbr.bin
may vary depending on your distribution. Check the correct path usinglocate mbr.bin
.) - Make the first partition bootable using
syslinux
:sudo syslinux /dev/sdX1
Making the USB drive bootable is a critical step in the process. The bootloader is responsible for loading the operating system kernel and initiating the boot process. Syslinux is a lightweight and versatile bootloader that is well-suited for this task. By installing Syslinux on the first partition and writing the MBR, we ensure that the USB drive can be recognized as a bootable device by the system's BIOS or UEFI firmware.
Step 6: Copying Files to the USB Drive
Now, we'll copy the necessary files to the USB drive. This includes the Syslinux configuration files and the contents of the CentOS 6.x DVD1 and DVD2 ISO images.
- Copy the Syslinux configuration files:
(Note: The pathsudo cp /usr/lib/syslinux/ldlinux.sys /mnt/usb1 sudo cp /usr/lib/syslinux/libutil.c32 /mnt/usb1 sudo cp /usr/lib/syslinux/libcom32.c32 /mnt/usb1 sudo cp /usr/lib/syslinux/menu.c32 /mnt/usb1 sudo cp /usr/lib/syslinux/libmenu.c32 /mnt/usb1 sudo cp /usr/lib/syslinux/vesamenu.c32 /mnt/usb1
/usr/lib/syslinux/
may vary depending on your distribution. Adjust the path accordingly.) - Create a
syslinux.cfg
file in/mnt/usb1
with the following content:
Save this file asDEFAULT menu.c32 TIMEOUT 300 MENU TITLE CentOS 6.x Installation LABEL install MENU LABEL Install CentOS 6.x KERNEL /vmlinuz APPEND initrd=/initrd.img LABEL vesa MENU LABEL Install CentOS 6.x in VESA Mode KERNEL /vmlinuz APPEND initrd=/initrd.img vga=ask LABEL linux rescue MENU LABEL Rescue Mode KERNEL /vmlinuz APPEND initrd=/initrd.img rescue
/mnt/usb1/syslinux.cfg
. - Mount the CentOS 6.x DVD1 ISO image:
Replacesudo mkdir /mnt/iso1 sudo mount -o loop /path/to/CentOS-6.x-DVD1.iso /mnt/iso1
/path/to/CentOS-6.x-DVD1.iso
with the actual path to your DVD1 ISO file. - Copy the contents of the DVD1 ISO image to the second partition of the USB drive:
sudo cp -r /mnt/iso1/* /mnt/usb2 sudo cp -r /mnt/iso1/.discinfo /mnt/usb2
- Unmount the DVD1 ISO image:
sudo umount /mnt/iso1 sudo rmdir /mnt/iso1
- Mount the CentOS 6.x DVD2 ISO image:
Replacesudo mkdir /mnt/iso2 sudo mount -o loop /path/to/CentOS-6.x-DVD2.iso /mnt/iso2
/path/to/CentOS-6.x-DVD2.iso
with the actual path to your DVD2 ISO file. - Copy the
Packages
directory from the DVD2 ISO image to the second partition of the USB drive. This is crucial because the installer will look for additional packages in this directory:sudo cp -r /mnt/iso2/Packages /mnt/usb2
- Additionally, copy the
.discinfo
file from DVD2 to the second partition. This file is necessary for the installer to correctly identify the installation media:sudo cp -r /mnt/iso2/.discinfo /mnt/usb2
- Unmount the DVD2 ISO image:
sudo umount /mnt/iso2 sudo rmdir /mnt/iso2
Copying the files to the USB drive involves several key steps. First, we copy the Syslinux configuration files to the boot partition, which tells the bootloader how to load the CentOS installer. The syslinux.cfg
file defines the boot menu entries and kernel parameters. Next, we mount the DVD1 ISO image and copy its entire contents to the second partition of the USB drive. This includes the kernel, initrd image, and other essential installation files. The same process is repeated for DVD2, but this time, we only copy the Packages
directory and the .discinfo
file, as these contain additional software packages and media identification information required by the installer. This ensures that all necessary files are present on the USB drive for a successful installation.
Step 7: Unmounting the Partitions
After copying all the files, it’s important to unmount the partitions to prevent data corruption.
- Unmount the second partition:
sudo umount /mnt/usb2
- Unmount the first partition:
sudo umount /mnt/usb1
- Remove the mount point directories:
sudo rmdir /mnt/usb1 sudo rmdir /mnt/usb2
Unmounting the partitions is a crucial step to ensure data integrity. By unmounting the partitions before removing the USB drive, you prevent potential data corruption that could occur if the system is still writing to the drive. This final step prepares the USB drive for safe removal and use as a bootable installation medium.
Conclusion
By following these steps, you should now have a bootable USB drive ready to install CentOS 6.x using both DVD1 and DVD2 ISO files. This method is a reliable way to install CentOS on systems without DVD drives or for faster installations. Remember to adjust the device names and paths according to your system configuration. You can now use this USB drive to boot your system and proceed with the CentOS 6.x installation. This comprehensive guide ensures that you have a bootable USB stick, which can be a lifesaver in various scenarios, such as installing CentOS on multiple machines or systems without optical drives.
This detailed guide provides a step-by-step approach to creating a bootable USB drive for CentOS 6.x. By following these instructions carefully, you can ensure a smooth and successful installation process.