Linux01-BASH指令碼編程之系統裁剪51

來源:互聯網
上載者:User

標籤:linux系統   自訂linux   linux   

上接(BASH指令碼編程之拷貝系統庫檔案50)


重新編輯grub為靜默模式:

    1.vim /mnt/boot/grub/grub.conf

default=0

timeout=3

title Nick Linux(2.6.18)

kernel /vmlinuz ro root/dev/hda2 quiet

initrd /initrd.gz


如何?終端提示資訊:

    2.複製宿主機檔案:

        cp /etc/issue /mnt/sysroot/etc/ 

    3.重新編輯issue資訊:

        vim /mnt/sysroot/etc/issue

Nick release 5.9 (Final)

Kernel \r on an \m


http://www.mageedu.com


如何掛載/etc/fstab中定義的其他檔案系統:

  • rc.sysinit:掛載/etc/fstab中定義的其它檔案系統

    a)怎麼判斷裝置是否掛載:

        awk ‘{print $1}‘ /proc/mounts | grep "/dev/hda2"

    b)swap裝置不能使用mount直接掛載:

        grep -v "\<swap\>" /etc/fstab | awk ‘{print $1}‘

        grep -E -v "\<swap|proc|sysfs\>" /etc/fstab | awk ‘{print $1}‘

        grep -E -v "\<swap|proc|sysfs\>" /etc/fstab | awk ‘{print $1}‘ | while read LINE;do awk ‘{print $1}‘ /proc/mounts | grep "^$LINE";done


    4.cd /mnt/sysroot/

    5.vim etc/rc.d/rc.sysinit修改添加:

#!/bin/bash

#

. /etc/rc.d/init.d/functions


echo -e "\tWelcome to\033[34mNick Team\033[0m Linux."


echo "Remount rootfs ..."

mount -n -o remount,rw /

[ $? -eq 0 ] && success "Remount rootfs" || failure "Remount rootfs"


mount -a

[ $? -eq 0 ] && success "Mount others filesystem" || failure "Mount others filesystem"


echo "Set the hostname ..."

[ -f /etc/sysconfig/network ] && . /etc/sysconfig/network

[ -z $HOSTNAME -o "$HOSTNAME" == ‘(none)‘ ] && HOSTNAME=localhost

/bin/hostname $HOSTNAME

[ $? -eq 0 ] && success "Set the hostname" || failure "Set the hostname"


echo "Initialization network device ..."

/sbin/insmod    /lib/modules/mii.ko

/sbin/insmod    /lib/modules/pcnet32.ko

[ $? -eq 0 ] && success "Initialization network device" || failure "Initialization network device"


ifconfig lo 127.0.0.1/8

[ $? -eq 0 ] && success "Activating loopback network device" || failure "Activating loopback network device"


如何設定核心參數/etc/sysctl.conf:

    6.運行binary.sh移植sysctl命令;

    7.建立/etc/sysctl.conf設定檔:

        cd /mnt/sysroot/

        vim /etc/sysctl.conf

net.ipv4.ip_forward = 1

    8.開機自動生效:

        vim /etc/rc.d/rc.sysinit最後行添加:

sysctl -p &> /dev/null

[ &? -eq 0 ] && success "Set kernel parameter" || failure "Set kernel parameter"

    9.啟動新主機,測試:

        cat /proc/sys/net/ipv4/ip_forward


如何?使用者運行:

  • PAM:Pluggable Authentication Module(可插入式設定檔);

  • RHEL5 通過/etc/pam.d/*來實現使用者的登入、認證等等;

  • 繞過PAM,RHEL的登入顯示通過/bin/login列印顯示:

  • login程式如何?使用者登入和認證:

    a)nsswitch(作為login的中介層):Network Service Switch

    b)架構:/etc/passwd,/etc/shadow,/etc/group,/etc/gshadow

        庫:libnss_file.so,libnss_nis.so,libnsss_ldap.so ...

        設定檔:/etc/nsswitch.conf

        庫檔案:/lib/libnss*;/usr/lib/libnss*


    10.複製使用者驗證庫檔案到/lib:

        cp -d /lib/libnss_files* /mnt/sysroot/lib/  --->-d選項,保留檔案連結

        ls -l /mnt/sysroot/lib/

    11.複製使用者驗證庫檔案到/usr/lib:

        cp -d /usr/lib/libnss_files.so /mnt/sysroot/usr/lib/

        cp -d /usr/lib/libnss3.so /usr/lib/libnssckbi.so /usr/lib/libnssutil3.so /mnt/sysroot/usr/lib/

        ls -l /mnt/sysroot/usr/lib/

    12、編輯設定檔:

        cp /etc/nsswitch.conf /mnt/sysroot/etc/

        vim /mnt/sysroot/etc/nsswitch.conf

passwd:files

shadow:files

group:files

hosts:filesdns

    13、建立使用者:

        添加hadoop使用者

        grep -E "^(root|hadoop)\>" /etc/passwd > /mnt/sysroot/etc/passwd

        grep -E "^(root|hadoop)\>" /etc/shadow > /mnt/sysroot/etc/shadow

        grep -E "^(root|hadoop)\>" /etc/group > /mnt/sysroot/etc/group

    14、移植mingetty,passwd,useradd,userdel,usermod,groupadd命令;

    15、修改inittab檔案:

        cd /mnt/sysroot/

        vim etc/inittab修改:

1:2345:respawn:/sbin/mingetty tty1

2:2345:respawn:/sbin/mingetty tty2

    16.下載login到/mnt/sysroot/bin

    17.添加執行許可權:chmod +x /mnt/sysroot/bin/login 

    18.啟動新主機,init 3 看是否提示使用者登入;


建立使用者設定檔:

    19.建立使用者命令提示字元設定檔:

        cd /mnt/sysroot/

        vim root/.bash_profile

PS1=‘[\[email protected]\h \W]\$‘

export PS1


單一使用者模式:

    20.修改root目錄許可權:

        cd /mnt/sysroot/

        chmod -R og=--- root/

    21.定義inittab檔案的1層級:

        vim etc/inittab添加一行:

l1:1:wait:/etc/rc.d/rc 1

    22.建立1層級服務鏈結接:

        cd /mnt/sysroot/etc/rc.d 

        mkdir rc1.d 

        cd rc1.d 

        ln -sv ../init.d/network K90network

        ln -sv ../init.d/tserver K33tserver

    23.建立單使用者singer檔案:

        vim etc/rc.d/init.d/single

#!/bin/bash

#

case $1 in

start)

 ;;

*)

        echo "Usage:Single start"

        ;;

esac


exec /sbin/init S

添加執行許可權:chmod +x etc/rc.d/init.d/single

    24、建立單使用者服務連結:

        cd rc1.d 

        ln -sv ../init.d/single S98single

    25、開始測試新主機的單一使用者模式:

        init 6 

        e

        選擇kernel /vmlinuz ro root/dev/hda2 quiet輸入e

        輸入1--> 斷行符號

        b鍵開始引導.

本文出自 “Nick Liu的博文” 部落格,請務必保留此出處http://zkhylt.blog.51cto.com/3638719/1430050

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.