Redhat 5 Series DIY Mini Linux II

Source: Internet
Author: User

In this article, assuming that mini Linux mounts in the host's/mnt/boot and/mnt/sysroot, some of the script in this paper is simplified, just to achieve our goal, the Linux workflow is more complex than imagined


Now that we have a mini Linux available, let's make some extensions to it

    1. Re-mount the root file system for read-write

      First, provide Minlinux with a fstab configuration file, which reads as follows:

      650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/84/45/wKiom1eLJ8_RsolJAACDw4M-VWo164.png-wh_500x0-wm_3 -wmp_4-s_2946706722.png "title=" 68tvs3p~9g8z) [@ ' r04{_sd.png ' alt= ' wkiom1elj8_rsoljaacdw4m-vwo164.png-wh_50 '/>

Add Mount-o REMOUNT,RW/Rc.sysinit inside

If there is no Mstab file in the ETC directory of mini Linux at this time, use Mount-o-n REMOUNT,RW/command, otherwise error


2. Set host name

<1> porting the hostname command and providing a configuration file for Mini Linux

echo "Hostname=mylinux" >/mnt/sysroot/etc/sysconfig/network

<2> Add the following in Rc.sysinit


Echo-e "Set up HOSTNAME ..."

if [-f/etc/sysconfig/network]; Then

. /etc/sysconfig/network

Fi

If [-Z] $HOSTNAME "-o" $HOSTNAME "=" (none) "]; Then

Hostname=localhost

Fi

Hostname $HOSTNAME


3. Shutdown and restart

First edit the Level service script, (Linux shutdown restart Halt, reboot and other commands will jump to the corresponding boot level to execute the service script) must be at the corresponding level to perform the shutdown restart command, otherwise it will fail to perform successfully. There is also a need to use a built-in command exec,bash execution of a command, fork a child process to execute, after using the EXEC command, directly replace the parent process to execute. Simply put, without the exec time, the halt shutdown of the child process after the end, bash this parent process will not end itself, not completely shut down.

The script reads as follows:

[email protected] sysroot]# cat Etc/rc.d/init.d/halt

#!/bin/bash

Case $ in

*halt)

Command= "Halt-p";;

*reboot)

command= "reboot";;

*)

Esac

EXEC $COMMAND


To create a soft connection:

Ln/mnt/sysroot/etc/rc.d/init.d/halt/mnt/sysroot/etc/rc0.d/k99halt-sv

Ln/mnt/sysroot/etc/rc.d/init.d/halt/mnt/sysroot/etc/rc6.d/k99reboot-sv


Edit the RC and config files under etc/rc.d/inittab

RC content is as follows:

#!/bin/bash

Runlevel=$1

For I in/etc/rc${runlevel}.d/k*

Do

$i stop;

Done


For I in/etc/rc${runlevel}.d/s*

Do

$i start;

Done


Inittab Append the following lines:

L0:0:WAIT:/ETC/RC.D/RC 0

L3:3:WAIT:/ETC/RC.D/RC 3

L6:6:WAIT:/ETC/RC.D/RC 6

Both the service script and RC are granted execute permissions, and here you can restart with the init 0 and init 6 shutdown in mini Linux.


4. Service scripts at all levels

The service script format references the Linux startup process.


5. Start the terminal

Here the system default Mingetty can not only specify bash, it will always call the login program, but also rely on/bin/sh, so this is used agetty substitution.

Transplant the Agetty and append the following two lines to the Inittab:

1:2345:respawn:/sbin/agetty-n-l/bin/bash 38400 tty1

2:2345:respawn:/sbin/agetty-n-l/bin/bash 38400 Tty2

-N to be used with-l,-n means no user name login,-L refers to the use of Shell 38400 refers to the screen display rate can be used

Stty-f/dev/console Speed came to


6. Defining function functions

Only two functions are defined in order to make the boot-up process look more like CentOS, as follows:


Success () {

String=$1

ok= "[\033[32m OK \033[0m]"

All= ' stty-f/dev/console Size|awk ' {print $} '

spa=$[$ALL-${#STRING}-${#OK}]

Echo-n "$STRING"

For i in ' seq 1 $SPA '

Do

Echo-n ""

Done

Echo-e "$OK"

}


Failed () {

String=$1

Failed= "[\033[31m FAILED \033[0m]"

All= ' stty-f/dev/console Size|awk ' {print $} '

spa=$[$ALL-${#STRING}-${#FAILED}]

Echo-n "$STRING"

For i in ' seq 1 $SPA '

Do

Echo-n ""

Done

Echo-e "$FAILED"

}

Err_check () {

If [$?-eq 0];then

Success $

Else

Failed $

Fi

}


Modify the Rc.sysinit as follows:

#!/bin/bash

. /etc/init.d/functions

echo "remount/..."

Mount-o REMOUNT,RW/

Err_check "remount/..."

Echo-e "Set up HOSTNAME ..."

if [-f/etc/sysconfig/network]; Then

. /etc/sysconfig/network

Fi

If [-Z] $HOSTNAME "-o" $HOSTNAME "=" (none) "]; Then

Hostname=localhost

Fi

Hostname $HOSTNAME

Err_check "Set up HOSTNAME ..."

Echo-e "Welcome to \033[31m linzb\033[0m ' s mini linux"


Effects such as:

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/84/50/wKioL1eMp8GT2MFkAAAm3CPokHc369.png-wh_500x0-wm_3 -wmp_4-s_2020855575.png "title=" 6w]dq ' Bi[[ch_33l$py]1ud.png "alt=" Wkiol1emp8gt2mfkaaam3cpokhc369.png-wh_50 "/>


6. Configure network functionality for Mini Linux

First of all to load the network card driver module, because the virtual machine operation, the network card type is pcnet32,pcnet32 and dependent on the Mii module (can be viewed with modinfo pcnet32), so to load two modules

Edit the contents of the/mnt/sysroot/etc/sysconfig/network-scripts/ifcfg-eth0 file as follows:


Device=eth0

Bootproto=static

hwaddr=00:0c:29:5b:58:99

Onboot=yes

ipaddr=192.168.2.224

gateway=192.168.2.1

netmask=255.255.255.0


Edit the startup script/mnt/sysroot/etc/init.d/network, which reads as follows:


#!/bin/bash

#chkconfig: 3 20 79

#description: Network config

#

. /etc/init.d/functions

. /etc/sysconfig/network-scripts/ifcfg-eth0

Lock_file=/var/lock/subsys/network

Start () {

echo "Starting network config ... "

Touch $LOCK _file

Insmod/lib/modules/mii.ko

Insmod/lib/modules/pcnet32.ko

Ifconfig $DEVICE $IPADDR netmask $NETMASK up

Route add default GW $GATEWAY

Err_check "Network starting ..."

}

Stop () {

echo "Stopping network ..."

RM $LOCK _file

Modprobe-r Pcnet32.ko

Modprobe-r Mii.ko

Err_check "Network stopping ..."

}

Status () {

If [-f $LOCK _file]; then

echo "Network working ..."

Else

echo "Network stopped ..."

Fi

}

Case $ in

Start

start;;

Stop

stop;;

Restart

Stop

start;;

Status

status;;

*)

echo "Usage: $ [Start|stop|status|restart]";;

Esac


chmod +x give the network Execute permissions and use Chkconfig to create a start level soft connection (this will be chroot to/mnt/sysroot to execute, you will be wrong manually), the final effect is as follows:

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/84/5B/wKioL1eN8zDwzHpiAABFPiG92dc756.png-wh_500x0-wm_3 -wmp_4-s_3299952251.png "title="]r ' Tqu1]5y0sh{_{xhgkg}t.png "alt=" Wkiol1en8zdwzhpiaabfpig92dc756.png-wh_50 "/>

Note:

If you start the process package device no found to see if there is a Mount network card, the network script is not stop, the module can not uninstall the reportmodprobe:fatal:Could not load /lib/modules/2.6.8.custem/modules. Deb The specific cause to be studied

This article from "Single Season rice" blog, declined reprint!

Redhat 5 Series DIY Mini Linux II

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.