Bash automatically customizes Linux's own CentOS System

Source: Internet
Author: User

Bash automatically customizes Linux's own CentOS system, directly

1. Create a directory on the host machine,/mnt/boot/mnt/sysroot, and format the disk to mount it.

1. corresponding functions:

Mkdevice (){

Dd if =/dev/zero of = $1 bs = 512 count = 1 &>/dev/null

[$? -Ne 0] & return 67

Echo'

N

P

1

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             

+ 500 M

N

P

2

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             

+ 9G

W' | fdisk $1 &>/dev/null

[$? -Ne 0] & return 68

Sync

Sleep 2

Mkfs. ext4 $ {1} 1 &>/dev/null

PAPT1 = $?

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

PAPT2 = $?

[$ PAPT1-ne 0-o $ PAPT2-ne 0] & return 69

}

 

 


Umountall (){

For PAPT in 'fdisk-l $1 | grep-o "$ {1} [0-9] \ {1, \}" '; do

Fuser-km $ PAPT &>/dev/null

Umount $ PAPT &>/dev/null

Done

}

 


Mountall (){

[-D $ BOOT] | mkdir-p $ BOOT

[-D $ SYSROOT] | mkdir-p $ SYSROOT

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         

Mount $ {1} 1 $ BOOT

Mount $ {1} 2 $ SYSROOT

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         

}


2. Install the grub program. Here we install it to/mnt/boot.

2. corresponding functions:

Instgrub (){

GRUBROOT = 'dirname $ boot'

Grub-install -- root-directory = $ GRUBROOT $1

}


3. Create a directory required by the system

3. corresponding functions

Mkrootfs (){

Mkdir-p $ SYSROOT/{proc, boot, sys, dev, tmp, lib, lib64, bin, sbin, root, home, opt, mnt, media, misc} &>/dev/null

Mkdir-p $ SYSROOT/usr {share/{man, doc}, bin, sbin, local, src, lib, lib64} &>/dev/null

Mkdir-p $ SYSROOT/var/{log, run, lock, spool, tmp} &>/dev/null

Mkdir-p $ SYSROOT/lib/{modules, module} &>/dev/null

Mkdir-p $ SYSROOT/lib64/{modues, module} &>/dev/null

Cp/lib/modules/2.6.32-431. el6.x86 _ 64/kernel/drivers/net/e1000/e1000.ko $ SYSROOT/lib/modules/

Cp/boot/vmlinuz-2.6.32-431.el6.x86_64 $ BOOT/vmlinuz

Cp/boot/initramfs-2.6.32-431.el6.x86_64.img $ BOOT/initramfs. img

Echo-e "default = 0 \ ntimeout = 5 \ ntitle MyCentos root (hd0, 0) \ nkernel/vmlinuz ro root =/dev/sda2 quiet selinux = 0 init =/sbin/init

Initrd/initramfs. img "> $ BOOT/grub. conf

Touch $ SYSROOT/sbin/init & cat/root/init> $ SYSROOT/sbin/init & chmod + x $ SYSROOT/sbin/init

}


4. Copy the kernel to the target host.

4. corresponding functions

Mkrootfs (){

Mkdir-p $ SYSROOT/{proc, boot, sys, dev, tmp, lib, lib64, bin, sbin, root, home, opt, mnt, media, misc} &>/dev/null

Mkdir-p $ SYSROOT/usr {share/{man, doc}, bin, sbin, local, src, lib, lib64} &>/dev/null

Mkdir-p $ SYSROOT/var/{log, run, lock, spool, tmp} &>/dev/null

Mkdir-p $ SYSROOT/lib/{modules, module} &>/dev/null

Mkdir-p $ SYSROOT/lib64/{modues, module} &>/dev/null

Cp/lib/modules/2.6.32-431. el6.x86 _ 64/kernel/drivers/net/e1000/e1000.ko $ SYSROOT/lib/modules/

Cp/boot/vmlinuz-2.6.32-431.el6.x86_64 $ BOOT/vmlinuz

Cp/boot/initramfs-2.6.32-431.el6.x86_64.img $ BOOT/initramfs. img

Echo-e "default = 0 \ ntimeout = 5 \ ntitle MyCentos root (hd0, 0) \ nkernel/vmlinuz ro root =/dev/sda2 quiet selinux = 0 init =/sbin/init

Initrd/initramfs. img "> $ BOOT/grub. conf

Touch $ SYSROOT/sbin/init & cat/root/init> $ SYSROOT/sbin/init & chmod + x $ SYSROOT/sbin/init

}

  • 1
  • 2
  • Next Page

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.