Production of RHEL6 Tiny Linux

Source: Internet
Author: User

Production of RHEL6 Tiny Linux

################### RHEL6 Tiny Linux #################
Linux start-up process to create, pre-condition: Host, standalone hard disk (also can use image files)
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.EXT4 ${disk}1 &>/dev/null
MKFS.EXT4 ${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.32)
Root (hd0,0)
Kernel/vmlinuz ro root=/dev/sda2 selinux=0
Initrd/initramfs.img
Eof

#copy kernel and INITRD from the current system
cp/boot/vmlinuz*/$GrubRD/boot/vmlinuz
cp/boot/initramfs*/$GrubRD/boot/initramfs.img

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/{INIT,RC.D} lib/modules lib64 bin Sbin usr/{lib,lib64} Var/{log,run,lock}
Cat >./etc/init/rcs.conf <<eof
Start on startup

Stop on RunLevel

Task
Console output
Exec/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. Cp-a/etc/init/rc.conf.
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 >${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

7. Create the/etc/passwd file and include the root user entry in it:
Cat >/mnt/sysroot/etc/passwd <<eof
Root:x:0:0:root:/root:/bin/bash
Eof

8. Copy the/etc/passwd dependency library
Cp-a/lib64/libnss_files*/mnt/sysroot/lib64/

Sixth step: Add landing terminal
1. Copying terminal-related configuration files during Init program processing
Cp-a/etc/init/{tty.conf,start-ttys.conf,prefdm.conf}/mnt/sysroot/etc/init/

2. Create a login-related directory
Mkdir/mnt/sysroot/etc/{pam.d,security,sysconfig}

3. Copy the configuration file associated with the login
Cp/etc/pam.d/{login,system-auth}/MNT/SYSROOT/ETC/PAM.D
CP/ETC/SECURITY/{LIMITS.CONF,NAMESPACE.CONF}/mnt/sysroot/etc/security/
Cp/etc/sysconfig/init/mnt/sysroot/etc/sysconfig

4. Set up a library file directory to store and log in Pam related functions
Mkdir/mnt/sysroot/lib64/security

5. Copy the Pam library files that are dependent on login
For i in ' awk ' grep-o ' pam.*so '/etc/pam.d/login '; Do cp-a/lib64/security/$i/mnt/sysroot/lib64/security/; Done

6. Copy the Pam library files that are dependent on the System-auth
For i in ' awk ' $ $ ~ "so$" {print $} '/etc/pam.d/system-auth '; Do cp-a/lib64/security/$i/mnt/sysroot/lib64/security/; Done

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

8. grep ^root/etc/shadow >>/mnt/sysroot/etc/shadow

9. Egrep ' ^ (passwd|shadow) '/etc/nsswitch.conf >>/mnt/sysroot/etc/nsswitch.conf (note: No nsswitch.conf is possible)

10. Use the fourth step script to copy the login command and its library file.

11. Modify the Rc.sysinit file as follows:
#!/bin/bash
#
# set hostname
. /etc/sysconfig/network

[-Z] $HOSTNAME "-o" $HOSTNAME "= =" (none) "] && Hostname=tiny.linux
/bin/hostname $HOSTNAME

#remount Rootfs
Mount-n-O REMOUNT,RW/
Echo-e "\twelcome to come \033[5;31mtiny linux\033[0m"
#/bin/bash

12. Use the fourth step script to copy the mount and hostname commands and their library files.

Seventh Step: Add Single user mode
1. Create a directory of RunLevel "1"
Mkdir/mnt/sysroot/etc/rc.d/rc1.d
2. Copy the host's/etc/rc.d/init.d/single
Cp/etc/rc.d/init.d/single/mnt/sysroot/etc/rc.d/init.d
Cp/etc/rc.d/rc1.d/s99single/mnt/sysroot/etc/rc.d/rc1.d

3. cd/mnt/sysroot/etc/rc.d/rc1.d && LN-SV. /init.d/tserver K33tserver

4. Copy a single user profile (used by the INIT program)
cp/etc/init/rcs-sulogin.conf/mnt/sysroot/etc/init/

5. Use the fourth step script to copy the commands and their library files that appear in the rcs-sulogin.conf file.


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

Production of RHEL6 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.