Install centos on a USB flash drive

Source: Internet
Author: User

I. preparations:

1: prepare the required software. It includes the centos image (dvd.exe file and the syslinux.exe file in windows.

2: Prepare two operating systems, one for Windows and one for Linux. Windows to perform boot-write MBR and generate ldlinux. sys; the other for Linux to create partitions and copy files.

3: Prepare a 4G or above USB flash drive. I have prepared an 8g USB flash drive for the sake of insurance, because the ISO file of centos requires 3.8 GB.

II. Specific steps: operations on Linux:

1. Create three new directory files under the MNT Directory: usb1, usb2, ISO

# Mkdir usb1 usb2 ISO

Mount the centos ISO file to/mnt/ISO.

# Mount-o loop/tmp/centos_5.4_final.iso/mnt/ISO

Go to/mnt/ISO to check the Directory and the files in it as you browse the DVD.

2: insert the USB flash disk into the Linux host and run fdisk-L to check whether the disk is identified. In my system, it is identified as/dev/sdb. (You can also go to/dev to see if there is any SDB device file ). And divide the USB flash drive into two zones.

# Fdisk-l view disk

# Fdisk/dev/SDB partitioning the USB disk

N create a partition

P select to create a primary Partition

1 partition number is 1

Enter key, the start column of the partition

+ Set the partition size by 500 mb. Here is 500 mb.

P check whether the partition is successful./dev/sdb1 indicates that the partition is successful.

N create a partition

P create primary Partition

2. The primary partition number is 2.

Enter start column of the disk partition

Enter end cylindrical

A. Activate the partition as a bootable partition.

1. Activate partition 1

W. Save partition information

# Partprobe/dev/SDB allows the kernel to re-read the partition table. If you do not run this command, restart the machine.

3: create a file system and mount partitions

# Mkfs. msdos/dev/sdb1 format the first partition of the USB flash disk into a file system in msdos format. If the format cannot be formatted, unmount the partition and format it in

# Mkfs. ext2/dev/sdb2 format the second partition of the USB flash disk into the ext2 format. It is said that syslinux is only friendly to the dos and ext2 file systems. I have not verified the ext3 format. You have the opportunity to verify it.

 

# Mount/dev/sdb1/mnt/usb1 mount the first partition of the USB flash drive to the/mnt/usb1 directory.

# Mount/dev/sdb2/mnt/usb2 mount the second fat U partition to the/mnt/usb2 directory.

4: Copy directories and files. The directory to be copied is/mnt/ISO/isolinux, the file to be copied is/root/anaconda-ks.cfg. file/root/anaconda-ks.cfg is not required, so this file is used to automatically install centos.

# Cp-A/mnt/ISO/isolinux/mnt/usb1/syslinux copy the isolinux directory to/mnt/usb1/. (change the directory name, so that syslinux can work normally)

# Cp/root/anaconda-ks.cfg/mnt/usb1 copy the anaconda-ks.cfg file to/mnt/usb1 (any installed centos system will automatically generate this file in the/root directory)

# Cp/tmp/CentOS-5.3-i386-bin-DVD.iso/mnt/usb2 copy the ISO image file to/mnt/usb2

# Mv/mnt/usb1/syslinux/isolinux. cfg/mnt/usb1/syslinux. cfg

Change/mnt/usb1/syslinux/isolinux. cfg to/mnt/usb1/syslinux. cfg.

4. Modify the file/mnt/usb1/syslinux. cfg and/mnt/usb1/anaconda-ks.cfg

(WQ! These two files do not have the write permission. Note that the exclamation point is forcibly modified)

(1): The content after/mnt/usb1/syslinux. cfg is modified as follows:

# Vi/mnt/usb1/syslinux. cfg

Else ---------------------------------------------------------------------------------------------------------------------------------

Default Linux
Prompt 1
Timeout 600
Display boot. msg
F1 boot. msg
F2 options. msg
F3 General. msg
F4 Param. msg
F5 rescue. msg
Label Linux
Kernel vmlinuz
Append initrd = initrd. img
Label text
Kernel vmlinuz
Append initrd = initrd. IMG text
Label KS
Kernel vmlinuz
Append Ks = HD: sdb1:/anaconda-ks.cfg initrd = initrd. img
Label local
Localboot 1
Label memtest86
Kernel memtest
Append-

Bytes ---------------------------------------------------------------------------------------------------

"Append Ks = HD: sdb1:/anaconda-ks.cfg
Initrd = initrd. the IMG line was modified, and its function was to boot the system in the hard disk mode (the USB flash disk is also considered as a hard disk). The centos image file required by it is located in the second partition of the USB flash disk, and use kickstart automatic installation, specify the Kickstart configuration file path/anaconda-ks.cfg, that is, the U disk first partition of the root directory.

(2): Modify the file/mnt/usb1/anaconda-ks.cfg, the modified content is as follows

Bytes -----------------------------------------------------------------------------------------------------------------------------

# Kickstart file automatically generated
Anaconda.

Install
Harddrive -- partition = sdb2 -- dir =
Lang en_US.UTF-8
Keyboard us

Text
Rootpw 123456
Firewall -- enabled -- Port = 22: TCP
Authconfig -- enableshadow -- enablemd5
SELinux -- Enforcing
Timezone -- UTC America/new_york
Bootloader -- location = partition -- driveorder = SDA
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# Here So unless you clear all partitions first, this is
# Not guaranteed to work
Clearpart -- Linux
Part/-- fstype ext3 -- size = 20000
Part/var -- fstype ext3 -- size = 20000
Part/usr -- fstype ext3 -- size = 20000
Part/data -- fstype ext3 -- size = 1 -- grow
Part swap -- size = 4096

% Packages
@ Development-libs
@ System-Tools
@ Core
@ Base
@ Network-Server
@ Admin-Tools
@ Development-Tools
Audit
Kexec-Tools
Device-mapper-multipath
Imake

Bytes ---------------------------------------------------------------------------------------------------------------------------

This file defines the configuration information for automatic installation: Account name and password, firewall, Nic, partition size, and so on. Depending on your needs.

 

III:

Unmount and remove the USB flash drive from the Linux host, and insert the USB flash drive into the host with a Windows system, enter the Win32 Directory In the downloaded syslinux to the syslinux directory in the first partition of the USB flash drive (Windows can only identify the first partition, as if this file can be copied to the local host of windows, I didn't try it. You can try it .) Open the doscommand window and run
G: \ syslinux \ Win32 \ syslinux.exe-a-m g: (G is your USB drive letter .)

4. Start Installation

Insert the processed USB flash drive into the server where the system is to be installed, start the system, and change the boot device to a USB flash drive. After the installation is correct, the installation page of centos appears. Follow the prompts to go to the next step. When installing grub, click 'change drive order' to adjust the local hard disk to the first place, after confirmation, return to the previous screen. The system automatically adjusts the installation location of grub to/dev/SDA, and then click Next to continue. The subsequent steps are the same as the installation of the CD.

Note:

  1. If the system repeatedly prompts that the image file cannot be found, it may be because your USB flash drive is not clean (for example, unmount it safely) and the drive cannot be read normally, you need to repeat the above steps and then use it to install the system.
  2. Anaconda-Ks and CFG are not required. If you want to manually select a partition during installation, you do not need to use it.
  3. Copy the images package in the image file to the second partition of the USB flash drive.
  4. During this installation, I did not place the centos boot loader in the MBR, but in the/dev/sda7, that is, the mount point of the boot Directory, which cannot be identified when the computer is started, you only need to add the corresponding option to the new entry in easybcd.

The following is the most important one:

You think!

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.