Http: // 10.1.1.35/ule_exec/exec01_usblinux.txt

Source: Internet
Author: User
Tags hex code
--

Boot The diskboot file in the CD
Dd If = diskboot. IMG of =/dev/SDB

USB Linux

Livecd can be directly installed using the system CD or DVD.

Review the startup process:

Boot --> BIOS (configure the main board program, Basic Input and Output System, power-on self-check, find the Startup Device number) --> Find MBR (Master bootloader record, it is a hard disk with 0 disks and 0 sectors) --> grub --> Use grub to find vmlinuz and initrd (driver hardware) --> kernel startup, generate the INIT process -->/etc/inittab (determine the system startup level) -->/etc/rc. sysinit (obtain the network environment and host type of the host, test and load the device, whether SELinux is started, and load the module, set the system time .................) -->/etc/rc. local

Plan the USB flash drive

For example, two G
It can be divided into two zones: one root partition and one swap partition.
It can also be divided into three zones: one root partition, one swap partition, and the space can be formatted as FAT32 to store data.

The partition instance here is:
1G is the root
512 M is swap
512mfat32, continue to be used when the USB flash drive

1. First, delete the original partition in the USB flash drive.

First, use fdisk/dev/SDB and run the D command to delete the disk.

Type 2: dd If =/dev/Zero of =/dev/sdb bs = 1024 COUNT = 1 -- delete disk partition information

2. Start partitioning by planned Partition

Command (M for help): n
Command action
E extended
P primary partition (1-4)
P
Partition Number (1-4): 1
First cylinder (1-1008, default 1 ):
Using default value 1
Last cylinder or + size or + sizem or + sizek (1-1008, default 1008): + 1000 m -- divide one GB to the Linux Root Partition

Command (M for help): n
Command action
E extended
P primary partition (1-4)
P
Partition Number (1-4): 2
First cylinder (494-1008, default 494 ):
Using default value 494
Last cylinder or + size or + sizem or + sizek (494-1008, default 1008): + 512 m -- shard m to Linux swap Partition

Command (M for help): n
Command action
E extended
P primary partition (1-4)
P
Partition Number (1-4): 3
First cylinder (747-1008, default 747 ):
Using default value 747
Last cylinder or + size or + sizem or + sizek (747-1008, default 1008): -- The final space is left for the USB flash disk to be formatted as a Windows partition.
Using default value 1008

Command (M for help):
Partition Number (1-4): 1 -- set the first partition as the boot Partition

Command (M for help): T
Partition Number (1-4): 2
HEX Code (type L to list codes): 82
Changed system type of partition 2 to 82 (Linux swap/Solaris) -- change the ID of the second partition to the swap partition format

Command (M for help): T
Partition Number (1-4): 3
HEX Code (type L to list codes): B
Changed system type of partition 3 to B (w95 FAT32) -- change the third partition to the partition format of FAT32

Command (M for help): p -- print to view the final result

Disk/dev/SDB: 2048 MB, 2048901120 bytes
64 heads, 62 sectors/track, 1008 Cylinders
Units = cylinders of 3968*512 = 2031616 bytes

Device boot start end blocks ID system
/Dev/sdb1*1 493 978081 83 Linux
/Dev/sdb2 494 746 501952 82 Linux swap/Solaris
/Dev/sdb3 747 1008 519808 B w95 FAT32

Command (M for help): w -- save and exit

3. Format and mount the partition.

[Root @ Li WWW] # After partprobe -- fdisk partition, use this command to refresh
[Root @ Li WWW] # mkfs-T ext3/dev/sdb1
[Root @ Li WWW] # mkswap/dev/sdb2
[Root @ Li WWW] # mkfs-T vfat/dev/sdb3 -- format the three shards

[Root @ Li WWW] # mkdir/USB
[Root @ Li WWW] # Mount/dev/sdb1/USB/-- create a directory and mount/dev/sdb1

4. Install the basic directory structure

Prepare the cd iso file and mount it to a directory.
[Root @ liwww] # Mount/share/ISO/rhel-5.4-server-i386-dvd.iso/Yum/-o loop

[Root @ Li WWW] # cd/Yum/Server/

[Root @ Li server] # rpm-QIP filesystem-2.4.0-2.i386.rpm
Description:
The filesystem software package is a basic tool installed on the Red Hat Linux system.
Software Package. Filesystem contains the basic directory layout of a Linux operating system,
Including the correct permission for each directory.

You must use -- nodeps to remove dependency before installation.
[Root @ Li server] # rpm-IVH -- root =/USB/-- nodeps filesystem-2.4.0-2.i386.rpm

[Root @ Li server] # ls/USB-after installation, you can see the basic directory, but there is no file in the directory
Bin Dev home lost + found MNT proc sbin srv tmp VaR
Boot etc lib media opt root SELinux sys USR

5. Install the corresponding software package, that is, the customization function.

The main step below is to install the software package of the system. First, you must consider the functions required for the USB system, such as the Basic commands LS and CD.

The CD command is an internal command.
There are 50 Internal commands in man type.

[Root @ Li server] # rpm-QL bash

[Root @ Li server] # rpm-qf/bin/ls
Coreutils-5.97-23.el5

[Root @ Li server] # rpm-QF 'which mount'
Util-linux-2.13-0.52.el5

[Root @ Li server] # rpm-qf'which passwd'
Passwd-0.73-1

[Root @ Li server] # rpm-QF 'which ifconfig'
Net-tools-1.60-78.el5

[Root @ Li server] # rpm-qf'which iptables'
Iptables-1.3.5-5.3.el5

[Root @ Li server] # rpm-QF 'which top'
Procps-3.2.7-11.1.el5

[Root @ Li server] # rpm-QF 'which vi'
Vim-minimal-7.0.109-6.el5

[Root @ Li server] # rpm-QF 'which Vim'
Vim-enhanced-7.0.109-6.el5

[Root @ Li server] # rpm-QF 'which SSH'
Openssh-clients-4.3p2-36.el5

[Root @ Li server] # rpm-QF 'which ping'
Iputils-20020927-46.el5

[Root @ Li server] # rpm-QF 'which tar'
Tar-1.15.1-23.0.1.el5

[Root @ Li server] # rpm-qf'which bzip2'
Bzip2-1.0.3-4.el5_2

[Root @ Li server] # rpm-qf'which gzip'
Gzip-1.3.5-10.el5

[Root @ Li server] # rpm-qf'which init'
SysVinit-2.86-15.el5

[Root @ Li ~] # Rpm-QF 'which grep'
Grep-2.5.1-55.el5

[Root @ Li ~] # Rpm-QF 'which awk'
Gawk-3.1.5-14.el5

[Root @ Li ~] # Rpm-QF 'which sed'
Sed-4.1.5-5.fc6

[Root @ Li ~] # Rpm-QF 'which portmap'
Portmap-4.0-65.2.2.1

[Root @ Li ~] # Rpm-QF 'which mount. NFS'
Nfs-utils-1.0.9-42.el5

Configure the yum Program

Install the customized function package. The following package can be increased or decreased as needed.

[Root @ Li server] # Yum install -- installroot =/USB bash coreutils util-Linux passwd net-tools shadow-utils iptables procps vim-Minimal vim-enhanced openssh-clients iputils tar Bzip2 gzip sysvinit sed grep gawk Portmap nfs-utils

6. Install the boot file

[Root @ Li server] # chroot/USB -- Use this command to take the/USB directory as the root directory.

Bash-3.2 # ls/boot/-- we can see that the/boot directory in USB Linux does not have any files.

Bash-3.2 # exit -- exit the chroot mode with exit
Exit

Custom ramdisk (initrd file) that supports USB storage startup)
[Root @ Li server] # mkinitrd -- with usb_storage/USB/boot/initrd. IMG 'uname-R'

Copy vmlinuz from the real machine to the corresponding directory of USB Linux
[Root @ Li server] # cp/boot/vmlinuz-2.6.18-164.el5/USB/boot/vmlinuz

Copy the kernel module from the real machine to the corresponding directory of USB Linux
[Root @ Li server] # cp/lib/modules/2.6.18-164. EL5 // USB/lib/modules/-RF

7. Install and manually write grub

Install the grub package and run -- nodeps to remove dependency.
[Root @ Li server] # rpm-IVH -- nodeps -- root =/USB grub-0.97-13.5.i386.rpm

Install grub-install to/dev/SDB
[Root @ Li server] # grub-install -- root-directory =/USB -- recheck/dev/SDB

Modify device. Map
[Root @ Li server] # Vim/USB/boot/GRUB/device. Map
(Hd0)/dev/SDB

Manually write the grub. conf file
[Root @ Li server] # Vim/USB/boot/GRUB/grub. conf

Default = 2
Timeout =-1

Splashimage = (hd0, 0)/boot/GRUB/splash.xpm.gz

Title usblinux
Root (hd0, 0)
Kernel/boot/vmlinuz Ro root =/dev/sdb1
Initrd/boot/initrd. img

Copy the grub background image from the real machine to the corresponding directory of USB Linux.
[Root @ Li ~] # Cp/boot/GRUB/splash.xpm.gz/USB/boot/GRUB/

---------------------------------------
Extended: diygrub background image

[Root @ Li ~] # Yum install ImageMagick-y

[Root @ Li ~] # Convert-resize 640*480 image.jpg-colors 14 splash. XPM & gzip splash. XPM

[Root @ Li ~] # Cp splash. XPM/boot/GRUB/

Modify grub

--------------------------------------------------

8. Copy the password file and environment variables.

[Root @ Li server] # cp/etc/passwd/USB/etc/passwd

[Root @ Li server] # chroot/USB/
Bash-3.2 # cp/etc/skel/. Bash */root/-- copy the environment variable Template
Bash-3.2 # exit
Exit
[Root @ Li server] # chroot/USB/-- again chroot to the/USB directory, the prompt changes

[Root @ Li/] # pwconv -- synchronize/etc/passwd and/etc/shadow
[Root @ Li/] # passwd root -- modify the root password, which is required for logon.

9. Manually write the fstab file

[Root @ Li/] # Vim/etc/fstab -- note that fstab is in the USB Linux system, because chroot has entered

/Dev/sdb1/ext3 defaults 0 0
/Dev/sdb2 swap defaults 0 0
Devpts/dev/PTS devpts gid = 5, mode = 620 0 0
Sysfs/sys sysfs defaults 0 0
Proc/proc defaults 0 0

10. Enable USB Linux to support the network

Copy the eth0 configuration file from the real machine to the corresponding directory of USB Linux:

[Root @ Li server] # cp/etc/sysconfig/network-scripts/ifcfg-eth0/USB/etc/sysconfig/network-scripts/

Change the network configuration file to a static IP address.
[Root @ Li server] # Vim/USB/etc/sysconfig/network-scripts/ifcfg-eth0
Device = eth0
Bootproto = DHCP
Onboot = Yes

Copy the global network configuration file from the real machine to the corresponding directory of USB Linux.
[Root @ Li server] # cp/etc/sysconfig/Network/USB/etc/sysconfig/

Copy modprobe. conf from the real machine to the corresponding directory of USB Linux
[Root @ Li server] # cp/etc/modprobe. CONF/USB/etc/
Alias eth0 8139too -- note that this sentence may need to be modified in different systems. The NIC module here is 8139too, so it is 8139too.

-----------------------------------------------------------

After completion, reboot system

Change to USB boot in BIOS

Login verification

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.