Linux01-bash script programming System cropping 51

Source: Internet
Author: User

Up (BASH script Programming copy system library file )


To re-edit grub as silent mode:

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


How to implement terminal prompt information:

2. Copy the host file:

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

3. Re-edit issue information:

Vim/mnt/sysroot/etc/issue

Nick release 5.9 (Final)

Kernel \ r on an \m


Http://www.mageedu.com


How to mount additional file systems defined in/etc/fstab:

    • Rc.sysinit: Mount other file systems defined in the/etc/fstab

A) How to determine if the device is mounted:

awk ' {print '} '/proc/mounts | grep "/dev/hda2"

b) Swap devices cannot be mounted directly with mount:

Grep-v "\<swap\>"/etc/fstab | awk ' {print '} '

Grep-e-V "\<swap|proc|sysfs\>"/etc/fstab | awk ' {print '} '

Grep-e-V "\<swap|proc|sysfs\>"/etc/fstab | awk ' {print '} ' | While read Line;do awk ' {print '} '/proc/mounts | grep "^ $LINE";d One


4.cd/mnt/sysroot/

5.vim Etc/rc.d/rc.sysinit Modified add:

#!/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"


How to set the kernel parameter/etc/sysctl.conf:

6. Run the binary.sh transplant sysctl command;

7. Create the/etc/sysctl.conf configuration file:

cd/mnt/sysroot/

Vim/etc/sysctl.conf

Net.ipv4.ip_forward = 1

8. The power-on automatically takes effect:

Vim/etc/rc.d/rc.sysinit last line add:

Sysctl-p &>/dev/null

[&-eq 0] && Success "Set kernel parameter" | | Failure "Set Kernel parameter"

9. Start the new host and test:

Cat/proc/sys/net/ipv4/ip_forward


How to implement a user run:

    • Pam:pluggable Authentication Module (pluggable configuration file);

    • RHEL5 through the/etc/pam.d/* to achieve user login, authentication and so on;

    • The login that bypasses the Pam,rhel display is printed by/bin/login:

    • How the login program implements user login and authentication:

A)Nsswitch (as the middle tier of login): Network Service Switch

b) Frame:/etc/passwd,/etc/shadow,/etc/group,/etc/gshadow

Library: Libnss_file.so,libnss_nis.so,libnsss_ldap.so ...

Configuration file:/etc/nsswitch.conf

Library files:/lib/libnss*;/usr/lib/libnss*


10. Copy the user authentication library file to/lib:

cp-d/lib/libnss_files*/mnt/sysroot/lib/--->-d option, keep file links

Ls-l/mnt/sysroot/lib/

11. Copy the user authentication library file to/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. Edit the configuration file:

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

Vim/mnt/sysroot/etc/nsswitch.conf

passwd:files

Shadow:files

Group:files

Hosts:filesDNS

13. Create User:

Add a Hadoop user

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, Transplant Mingetty,passwd,useradd,userdel,usermod,groupadd command;

15. Modify the Inittab file:

cd/mnt/sysroot/

Vim Etc/inittab Modification:

1:2345:respawn:/sbin/mingetty tty1

2:2345:respawn:/sbin/mingetty Tty2

16. Download Login to/mnt/sysroot/bin

17. Add Execute Permissions: chmod +x/mnt/sysroot/bin/login

18. Start the new host, Init 3 to see if the user is prompted to log in;


To create a user profile:

19. Create a user command prompt configuration file:

cd/mnt/sysroot/

Vim Root/.bash_profile

Ps1= ' [\[email protected]\h \w]\$ '

Export PS1


Single-User mode:

20. Modify the root directory permissions:

cd/mnt/sysroot/

Chmod-r og=---root/

21. Define level 1 of the Inittab file:

Vim Etc/inittab Add a line:

L1:1:WAIT:/ETC/RC.D/RC 1

22. Create a 1-level service link:

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. Create a single-user singer file:

Vim Etc/rc.d/init.d/single

#!/bin/bash

#

Case $ in

Start

;;

*)

echo "Usage:single start"

;;

Esac


Exec/sbin/init S

Add Execute permission: chmod +x Etc/rc.d/init.d/single

24. Create a single-User Service link:

CD RC1.D

Ln-sv. /init.d/single S98single

25. Start testing the single-user mode for the new host:

Init 6

E

Select Kernel/vmlinuz ro root/dev/hda2 quiet input E

Enter 1--> carriage return

The B key starts booting.

This article is from "Nick Liu's blog," Please make sure to keep this source http://zkhylt.blog.51cto.com/3638719/1430050

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.