Production of RHEL5 Tiny Linux

Source: Internet
Author: User

Production of RHEL5 Tiny Linux

############# RHEL5 Tiny Linux ##############
Build with Linux startup process

First step: partition, Mount, the following is the partition script
#!/bin/bash
# difined Variable
#
bootpart=500m
rootpart=2g
Read-p "Input your disk that need to format:" Disk

# partitons
(
/sbin/fdisk $Disk <<eof
N
P
1

+ $BootPart
N
P
2

+ $RootPart
W
Eof
) &>/dev/null

Sleep 3

Mkfs.ext3 ${disk}1 &>/dev/null
Mkfs.ext3 ${disk}2 &>/dev/null

Mkdir/mnt/{boot,sysroot} &>/dev/null

Mount ${disk}1/mnt/boot


Step Two: Install grub and its configuration file, the following is the processing script

#!/bin/bash
#
Grubrd=/mnt
Read-p "Input your disk for installing GRUB:" Gbdisk
Grub-install--root-directory= $GrubRD $Gbdisk
CD $GrubRD/boot/grub
Cat >grub.conf <<eof
Timeout=5
Default=0
Title Welcome to use Tiny Linux (2.6.18)
Root (hd0,0)
Kernel/vmlinuz ro root=/dev/hda2
Initrd/initrd.gz
Eof

#copy kernel and INITRD from the current system
cp/boot/vmlinuz*/$GrubRD/boot/vmlinuz
# Create TMP dir
Cd/tmp
tmpdir=$ (mktemp-d inittemp.xxx)
CD $TmpDir
# uncompress initrd*.img and modify Init
zcat/boot/initrd* | Cpio-id
oldroot=$ (awk '/mkrootdev/{print $NF} ' init)
Sed-i "s#${oldroot}#/dev/hda2#" Init
#compress again
Find. | Cpio-h newc--quiet-o |gzip-9 > $GrubRD/boot/initrd.gz

Step three: Establish the relevant directory under the root file system and initialize the script

#!/bin/bash
#
Read-p "Input real rootfs ' s path for tiny Linux:" Sysroot
CD ${sysroot:-/mnt/sysroot}
mkdir-p proc Sys Dev ETC/RC.D lib/modules lib64 bin Sbin usr/{lib,lib64} Var/{log,run,lock}
Cat >./etc/inittab <<eof
Id:3:initdefault:
Si::sysinit:/etc/rc.d/rc.sysinit
Eof

Cat >./etc/rc.d/rc.sysinit <<eof
#!/bin/bash
#
Echo-e "\twelcome to come \033[5;31mtiny linux\033[0m"
/bin/bash
Eof
chmod +x./etc/rc.d/rc.sysinit

Fourth Step: Copy the program command you want to use to the root directory
#!/bin/bash
#
Dest=/mnt/sysroot
LIBCP () {
libpath=${1%/*}
[!-D $DEST $libpath] && mkdir-p $DEST $libpath
[!-e $DEST ${1}] && cp-a $1* $DEST $libpath && echo "Copy Lib $ finished."
}

BINCP () {
cmdpath=${1%/*}
[!-D $DEST $cmdpath] && mkdir-p $DEST $cmdpath
[!-e $DEST ${1}] && cp $DEST $cmdpath

For LIB in ' LDD $ | Grep-o "/.*lib\ (64\) \{0,1\}/[^. \{1,\} "'; Do
If ["$LIB" = "/lib64/ld-linux-x86-64"];then
Lib= ' echo $LIB | Grep-o "/.*lib\ (64\) \{0,1\}/[^-]\{1,\}" '
Fi
LIBCP $LIB
Done
}

Read-p "Your command:" CMD
until [$CMD = = ' Q ']; Do
! Which $CMD && echo "wrong command" && read-p "Input again:" CMD && continue
Command= ' which $CMD | Grep-v "^alias" | Grep-o "[^[:space:]]\{1,\}" '
BINCP $COMMAND
echo "Copy $COMMAND finished."
Read-p "Continue:" CMD
Done

Fifth step: Add Run Level 0 and 6 to enable the system to shut down properly and restart
1.
#!/bin/bash
#
#addlevel. Sh
#
#used for adding run level
#
tiny_etc_dir=/mnt/sysroot/etc/
Level () {
grep "L$1" ${tiny_etc_dir}/inittab
[$?! = 0] && sed-i "$ A L$1:$1:WAIT:/ETC/RC.D/RC $" ${tiny_etc_dir}/inittab && echo-e "Add runing Lev El $ \033[32mok\033[0m "| | echo" Run level $ has added "
}

Read-p "Input level number, need to add:" Lnum
until [$Lnum = = "Q"];d o
Case $Lnum in
[0-6])
Level $Lnum
Read-p "continue:" Lnum
;;
*)
echo "Input number[0-6]"
Read-p "continue:" Lnum
;;
Esac
Done

2. Create an RC script
#!/bin/bash
#
#create RC Script
#
Tiny_etc_dir=/mnt/sysroot/etc
[-D ${TINY_ETC_DIR}/RC.D] | | Mkdir-p ${TINY_ETC_DIR}/RC.D
Cat &GT;${TINY_ETC_DIR}/RC.D/RC <<eof
#!/bin/bash
#
Runlevel_dir=/etc/rc.d/rc$1
For i in ${runlevel_dir}/k*;d o
If [-X $i];then
$i Stop
Fi
Done

For i in ${runlevel_dir}/s*;d o
If [-X $i];then
$i Start
Fi
Done
Eof
chmod +x ${TINY_ETC_DIR}/RC.D/RC

3. Set up INIT.D directory and RCN.D directory, as well as corresponding action scripts and links.
Mkdir-p/MNT/SYSROOT/ETC/{INIT.D,RC0.D,RC6.D}

4. Write halt to use as shutdown and restart
Vim/mnt/sysroot/etc/init.d/halt
#!/bin/bash
#
Case $ in
*halt)
echo "Halting the system ..."
/sbin/halt-p
;;
*reboot)
echo "Rebooting the system ..."
/sbin/reboot
;;
*)
;;
Esac
chmod +x/mnt/sysroot/etc/init.d/halt
5. Use the fourth script to move the halt, reboot commands, and dependent libraries

6. Link the halt script to the RC0.D and RC6.D directories separately
CD RC0.D
Ln-sv. /init.d/halt S01halt
CD RC6.D
Ln-sv. /init.d/halt S01reboot

Sixth step: Add terminal, user, host name, environment variable PS1, login prompt
1. In Inittab, add terminal configuration
Cat >>/mnt/sysroot/etc <<eof
#1:2345: Respawn:/sbin/agetty-n-l/bin/bash 38400 tty1
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/ Mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin /mingetty tty5
6:2345:respawn:/sbin/mingetty tty6
EOF
2. Use the fourth script to move the Mingetty, the login command, and the dependent library
3. Modify Rc.sysinit as follows:
#!/bin/bash
#
Echo-e "\twelcome to come \033[1;31mtiny linux\033[0m"
#/bin/bash
#/ Sbin/mingetty--loginprog=/bin/bash tty1
./etc/sysconfig/network
[-Z $HOSTNAME-o "$HOSTNAME" = "None"] &&am P Hostname=localhost
HOSTNAME $HOSTNAME
echo "Remount rootfs ..."
Mount-n-o remount,rw/
4. Login Message
Cat >/mnt/sysroot/etc/issue <<eof
Welcome to use tiny Linux!
EOF
5. Add login user and password
Cat >/mnt/sysroot/etc/passwd <<eof
root:x:0:0:fist user:/root:/bin/bash
EOF

grep "Root"/etc/shadow >/mnt/sysroot/etc/shadow

Cat >/mnt/sysroot/etc/nsswitch.conf <<eof
Passwd:files
Shadow:files
Eof

Cp-a/lib64/libnss_files*/mnt/sysroot/lib64

Cp-a/lib64/libnsl*/mnt/sysroot/lib64

(Mkdir/mnt/sysroot/etc/security & cp-a/etc/security/limits*/mnt/sysroot/etc/security)

(MKDIR/MNT/SYSROOT/ETC/PAM.D & Cp/etc/pam.d/{login,system-auth}/mnt/sysroot/etc/security)


This article is from the "Everything Possible" blog, please be sure to keep this source http://noican.blog.51cto.com/4081966/1656580

Production of RHEL5 Tiny Linux

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.