System clipping centos6.8 with network function

Source: Internet
Author: User
Tags network function

Installation Environment: centos6.8,kernel:2.6.32-642.4.2.el6.x86_64

Target host: Minimized home-made Linux hosts

Host: A self-made, minimized Linux host made in that Linux host, and the following is done in the host

The newly added disk configuration information is as follows:

650) this.width=650; "src=" Http://note.youdao.com/yws/res/2554/7CCC6D22E5A745D4A83980EE2B06E9C6 "alt=" 7ccc6d22e5a745d4a83980ee2b06e9c6 "/>

650) this.width=650; "src=" Http://note.youdao.com/yws/res/2555/9E0D0D6822FA43D59C7916A9BD89576E "alt=" 9e0d0d6822fa43d59c7916a9bd89576e "/>

1, add a new hard disk in the virtual machine, and remember the storage location of the hard disk, in order to be used, divided into two zones, respectively for the boot and/

# echo-n "

N

P

1

+500m

N

P

2

+5g

W "|fdisk/dev/sdb

Mkfs.ext4/dev/sdb1

Mkfs.ext4/dev/sdb2

2, mount the partition, mount location should not be created first

# Mount/dev/sdb1/mnt/boot

# Mount/dev/sdb2/mnt/sysroot

3. Copy the Linux kernel, and initramfs.img to/mnt/boot/

# cp/boot/vmlinuz-' Uname-r '/mnt/boot/vmlinuz

# cp/boot/initramfs-' Uname-r '. img/mnt/boot/initramfs.img

4. Install Grub to/dev/sdb

# Grub-install--root-directory=/mnt/dev/sdb

Note: Because this is mounted to the/MNT directory, the MNT is treated as the root of grub

5, copy some commands to the cropping system, through the bincp.sh script

# bash/root/scripts/bincp.sh

Bash

Mount

Insmod

Cat

Vim

Ls

Cd

Ifconfig

Mkdir

Touch

Umount

Ping

Tree

Quit

6. Copy the NIC driver to the past

View all drivers, e1000 is the NIC driver

# Lsmod

View the details of the e1000 driver to see the location of the driver file

# Modinfo e1000

# mkdir/mnt/sysroot/lib/modules/-PV

# cp/lib/modules/' Uname-r '/kernel/drivers/net/e1000/e1000.ko/mnt/sysroot/lib/modules/

Note: Lib/modules folder should not be created beforehand

7. Create the corresponding directory under the target host root

# Mkdir-pv/mnt/sysroot/{etc,etc/rc.d,boot,dev,bin,lib,sbin,home,root,var,usr,tmp,mnt,media,proc,sys}

8. Establish a grub profile for the target host to enable the system to boot

# vim/mnt/boot/grub/grub.conf

Default=0

Timeout=3

Title Siyu

Root (hd0,0)

Kernel/vmlinuz ro root=/dev/sda2 selinux=0 init=/sbin/init

INITRD initramfs.img

Note: Here the INITRD instruction and kernel value should be the same as the 4th step, because the init value here is/sbin/init, so you need to create the/sbin/init file and add the appropriate system initialization command, if you do not want to use the init file, then init=/ Bin/bash, but unable to implement network functions

9. Initialize the system file init and give execute permission

# Vim/mnt/sysroot/sbin/init

#!/bin/bash

Echo-e "\ t \033[34m linux \033[3m"

Mount-n-T proc Proc/proc

Mount-n-T Sysfs Sysfs/sys

Insmod/lib/modules/e1000.ko

Ifconfig eth0 192.168.1.4/24

Ifconfig Lo 127.0.0.0/8

Mount-n-T remount,rw/dev/sda2/

/bin/bash

# chmod +x/mnt/sysroot/sbin/init

10. Test the SDB drive into another virtual machine

Create a new virtual machine with the following result, the disk file will be the same as the newly added disk for host

650) this.width=650; "src=" Http://note.youdao.com/yws/res/2557/95DB749BEE49428FAA4B3CBCABAF6EEE "alt=" 95db749bee49428faa4b3cbcabaf6eee "/>

11. Use init config file and network configuration is successful

650) this.width=650; "src=" http://note.youdao.com/yws/res/2556/23A2BD93EAA047D68A56A5F66C56B556 "alt=" 23a2bd93eaa047d68a56a5f66c56b556 "/>

Using the script one-click execution

The host root directory used here is sysroot, mounted under MNT, boot partition boot, mount to/mnt/boot

# Vim Createsys.sh

#!/bin/bash

Disk () {

Echo-n '

N

P

1

+500m

N

P

2

+5g

Wq ' | Fdisk "$"

Sleep 3

Kpartx-l "$"

Kpartx-af "$"

Partx-a "$"

Dmsetup Remove_all

Mke2fs-t Ext4 "$ 1"

Mke2fs-t Ext4 "$ 2"

}

Mounts () {

[-d/mnt/boot/] | | Mkdir/mnt/boot

[-d/mnt/sysroot/] | | Mkdir/mnt/sysroot

Mount "$disk" 1/mnt/boot

Mount "$disk" 2/mnt/sysroot

}

Cpkernel () {

cp/boot/vmlinuz-' Uname-r '/mnt/boot/vmlinuz

cp/boot/initramfs-' Uname-r '. img/mnt/boot/initramfs.img

Grub-install--root-directory=/mnt/dev/sdb

}

Cpcmd () {

bash/root/scripts/bincp.sh #bincp. Sh in The/root/scripts/next

}

Cpnetwork () {

[-d/mnt/sysroot/lib/modules/] | | Mkdir/mnt/sysroot/lib/modules/-PV

cp/lib/modules/' Uname-r '/kernel/drivers/net/e1000/e1000.ko/mnt/sysroot/lib/modules/e1000.ko

}

Mkdirs () {

Mkdir-pv/mnt/sysroot/{etc,etc/rc.d,boot,dev,bin,lib,sbin,home,root,var,usr,tmp,mnt,media,proc,sys}

}

Creategrub () {

echo "

Default=0

Timeout=3

Title Siyu

Root (hd0,0)

Kernel/vmlinuz ro root=/dev/sda2 selinux=0 init=/sbin/init

Initrd/initramfs.img ">>/mnt/boot/grub/grub.conf

}

Inits () {

Cat >>/mnt/sysroot/sbin/init << EOF

#!/bin/bash

Echo-e "\ t \033[34m linux \033[0m"

Mount-n-T proc Proc/proc

Mount-n-T Sysfs Sysfs/sys

Insmod/lib/modules/e1000.ko

Ifconfig eth0 $

Ifconfig Lo 127.0.0.0/8

Mount-n-T remount,rw/dev/sda2/

/bin/bash

Eof

chmod +x/mnt/sysroot/sbin/init

}

Read-p "Input a disk:" Disk

Disk "$disk"

Mounts

Cpkernel

Cpcmd

Mkdirs

Cpnetwork

Creategrub

Read-p "Input a Ip/netmask:" Network

Inits "$network"

The BINCP script is as follows:

#!/bin/bash

#copy command and need so--->/mnt/sysroot

Target=/mnt/sysroot

Main () {

If which $ &>/dev/null; Then

echo "Command such"

Else

echo "No such command"

Return 4

Fi

}

Bincommand () {

Cmdpath= ' which--skip-alias '

Dirpath= ' DirName $cmdpath '

[-D $target] | | Mkdir-p $target

[-D ${target}${dirpath}] | | Mkdir-p ${target}${dirpath}

[-F ${target}${cmdpath}] | | CP $cmdpath ${target}${dirpath}

}

Binlib () {

For i in ' ldd $cmdpath | Grep-o "/[^[:space:]]\{1,\}"; Do

Libdir= ' dirname $i '

[-D ${target}${libdir}] | | Mkdir-p ${target}${libdir}

[-F ${target}${i}] | | CP $i ${target}${libdir}

Done

}

While true; Do

Read-p "Input a command:" cmd

if [["$cmd" = = ' quit ']; Then

echo "Quitting"

Exit 0

Fi

If [$?-ne 0]; Then

echo "worng command"

Continue

Fi

Main $cmd

Bincommand $cmd

Binlib

Done


This article is from the "grep and regular Details" blog, so be sure to keep this source http://tingfengsiyu.blog.51cto.com/10042389/1877620

System clipping centos6.8 with network function

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.