马哥教育网络21期+第十周练习博客

马哥教育网络21期+第十周练习博客

1、请详细描述CentOS系统的启动流程(详细到每个过程系统做了哪些事情)
CentOS启动流程:1,加电自检->Boot Sequence-->加载内核文件
BOOT Sequence中包含了MBR和GRUB
    MBR:记录磁盘扇区,共512字节,前446个字节BootLoader 后4*16的64个字节是存放分区信息
    grub:MBR中的前446个字节,她的左右要选择启动的内核。
加载内核启动文件:
    kernel初始化,探测可识别的所有硬件设备,记载硬件驱动,以只读方式挂载根文件系统,运行用户控件的下的第一个启动程序/sbin/init程序;


2、为运行于虚拟机上的CentOS 6添加一块新硬件,提供两个主分区;
  (1) 为硬盘新建两个主分区;并为其安装grub;
  (2) 为硬盘的第一个主分区提供内核和ramdisk文件; 为第二个分区提供rootfs;
  (3) 为rootfs提供bash、ls、cat程序及所依赖的库文件;
  (4) 为grub提供配置文件;
  (5) 将新的硬盘设置为第一启动项并能够正常启动目标主机;
    1,加载新的磁盘使用fdisk修改新的磁盘分区:
    [root@localhost ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x79c69071

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         262     2104483+  83  Linux
/dev/sdb2             263        2610    18860310   83  Linux
然后将指定磁盘挂载至指定文件系统上
[root@localhost ~]# mkfs.ext4 /dev/sdb1
[root@localhost ~]# mkfs.ext4 /dev/sdb2
[root@localhost mnt]# ls
boot  sysroot
将指定的磁盘挂载至文件系统上:
    [root@localhost mnt]# mount /dev/sdb1 /mnt/boot/
    [root@localhost mnt]# mount /dev/sdb2 /mnt/sysroot/
将原来的grub文件中的内核文件,grub文件以及rootfs文件复制到新的grub文件中!
    [root@localhost ~]# cp -a /boot/vmlinuz-2.6.32-642.4.2.el6.x86_64 /mnt/boot/vmlinuz
    [root@localhost ~]# cp -a /boot/initramfs-2.6.32-642.4.2.el6.x86_64.img /mnt/boot/initramfs.img
安装grub到指定的grub中:
    [root@localhost boot]# grub-install --root-directory=/mnt /dev/sdb
    Probing devices to guess BIOS drives. This may take a long time.
    Installation finished. No error reported.
    This is the contents of the device map /mnt/boot/grub/device.map.
    Check if this is correct or not. If any of the lines is incorrect,
    fix it and re-run the script `grub-install'.

    (fd0)   /dev/fd0
    (hd0)   /dev/sda
    (hd1)   /dev/sdb
    [root@localhost boot]# cd /mnt/sysroot/
    [root@localhost sysroot]# mkdir -pv etc bin sbin lib lib64 dev proc sys tmp var usr home root mnt media
复制bash;ls;cat;所依赖的库文件
[root@localhost sysroot]# cp /bin/bash /bin/ls /bin/cat /mnt/sysroot/bin/
使用ldd查看所需要的软件的依赖的库文件:
[root@localhost sysroot]# cp `ldd /bin/bash | sed '1d'| grep -Eo "/.*[0-9] "` /mnt/sysroot/lib64/
[root@localhost sysroot]# cp `ldd /bin/ls | sed '1d'| grep -Eo "/.*[0-9] "` /mnt/sysroot/lib64/
[root@localhost sysroot]# cp `ldd /bin/cat | sed '1d'| grep -Eo "/.*[0-9] "` /mnt/sysroot/lib64/
在grub中记得修改配置文件:
     timeout=5
     title CentOS (Expres)
     root (hd0,0)
     kernel /vmlinuz ro root=/dev/sda2 selinux=0 init=/bin/bash
     initrd /initramfs.img



3、制作一个kickstart文件以及一个引导镜像。描述其过程。
1、anaconda的配置方式:
(1) 交互式配置方式;
(2) 通过读取事先给定的配置文件自动完成配置;
a)按特定语法给出的配置选项;
   kickstart文件;
  b)安装引导选项:
    text: 文本安装方式
    method: 手动指定使用的安装方法
  c)与网络相关的引导选项:
    ip=IPADDR
    netmask=MASK
    gateway=GW
    dns=DNS_SERVER_IP
    ifname=NAME:MAC_ADDR
          d)与远程访问功能相关的引导选项:
    vnc
    vncpassword='PASSWORD'
          e)指明kickstart文件的位置
    ks=
    DVD drive: ks=cdrom:/PATH/TO/KICKSTART_FILE
    Hard drive: ks=hd:/device/drectory/KICKSTART_FILE
    HTTP server: ks=http://host:port/path/to/KICKSTART_FILE
    FTP server: ks=ftp://host:port/path/to/KICKSTART_FILE
    HTTPS server: ks=https://host:port/path/to/KICKSTART_FILE
  f)启动紧急救援模式:
    rescue

2、 kickstart文件的格式:
  a)命令段:指明各种安装前配置,如键盘类型等;
  b)程序包段:指明要安装的程序包组或程序包,不安装的程序包等;
        %packages
        @group_name
        package
        -package
        %end
  c)脚本段:
        %pre: 安装前脚本
            d)运行环境:运行于安装介质上的微型Linux环境
       %post: 安装后脚本
   运行环境:安装完成的系统;

命令段中的命令: 必备命令 authconfig: 认证方式配置 authconfig –useshadow –passalgo=sha512 bootloader:bootloader的安装位置及相关配置 bootloader –location=mbr –driveorder=sda –append="crashkernel=auto crashkernel=auto rhgb rhgb quiet quiet" keyboard: 设定键盘类型 lang: 语言类型 part: 创建分区 rootpw: 指明root的密码 timezone: 时区 可选命令 install OR upgrade text: 文本安装界面 network firewall selinux halt poweroff reboot repo user:安装完成后为系统创建新用户 url: 指明安装源 3、创建kickstart文件的方式: (1) 直接手动编辑; 依据某模板修改; (2) 可使用创建工具:system-config-kickstart (CentOS 6) 依据某模板修改并生成新配置; 4、检查ks文件的语法错误:ksvalidator # ksvalidator /PATH/TO/KICKSTARTFILE 5、创建引导光盘: # mkisofs -R -J -T -v –no-emul-boot –boot-load-size 4 – boot-info-table -V “CentOS 6.8 x8664 boot” -b isolinux/isolinux.bin -c isolinux/boot.cat -o /root/boot.iso myiso/ [root@localhost ~]# yum install system-config-kickstart [root@localhost ~]# system-config-kickstart # 进入图形界面 4、写一个脚本 4、写一个脚本 (1) 能接受四个参数:start, stop, restart, status start: 输出“starting 脚本名 finished.” … (2) 其它任意参数,均报错退出; [root@localhost bin]# cat 12.sh #!/bin/bash # read -p "Please input parameters such as (start,stop,restart,status) :" option # if [ "$option" = 'start' ];then echo "starting $option finished" elif [ "$option" = 'stop' ];then echo "stop $option finished" elif [ "$option" = 'restart' ];then echo "restart $option finished" elif [ "$option" = 'status' ];then echo "status $option finished" elif [ "$option" != 'start' -a "$option" != 'stop' -a "$option" != 'restart' -a "$option" != 'status' ];then echo "please enter start|stop|restart|status." fi

5、写一个脚本,判断给定的用户是否登录了当前系统;
  (1) 如果登录了,则显示用户登录,脚本终止;
  (2) 每3秒钟,查看一次用户是否登录;
    [root@localhost bin]# cat user1.sh 
    #!/bin/bash
    #
    read -p "Please enter your user name:" username
    while true ;do
       if who | grep "^$username" &> /dev/null ;then
          break
       fi
       sleep 3
    done
    echo "$username logging."

6、写一个脚本,显示用户选定要查看的信息;
   cpu) display cpu info
   mem) display memory info
   disk) display disk info
   quit) quit
   非此四项选择,则提示错误,并要求用户重新选择,只到其给出正确的选择为止;
    [root@localhost bin]# cat canshu2.sh 
    #!/bin/bash
    #
    cat << EOF
    cpu ) show cpu information;
    mem ) show memory information;
    disk) show disk information;
    quit) quit
    ============================
    EOF
    read -p "Please enter the above parameters:" option
    while [ "$option" != 'cpu' -a "$option" != 'mem' -a "$option" != 'disk' -a "$option" != 'quit' ];do
       read -p "Please input parameters again, must give the prompt characters:" option
    done
    case "$option" in
    cpu)
      lscpu
       ;;
    mem)
      cat /proc/meminfo
      ;;
    disk)
      fdisk -l
      ;;
    *)
     echo "Quit..."
     exit 0
      ;;
    esac

7、写一个脚本
  (1) 用函数实现返回一个用户的UID和SHELL;用户名通过参数传递而来;
  (2) 提示用户输入一个用户名或输入“quit”退出;
    当输入的是用户名,则调用函数显示用户信息;
    当用户输入quit,则退出脚本;进一步地:显示键入的用户相关信息后,再次提醒输出用户名或quit:
    [root@localhost bin]# cat user4.sh 
    #!/bin/bash
    info() {
            id $username &> /dev/null
            if [ $? -ne 0 ];then
                    echo "the user is not exist!"
            else
                    grep "^$username" /etc/passwd |awk -F: '{printf "USER ID:%u\nUSER SHELL:%s\n" ,$3,$NF}'
            fi
    }
    read -p "please input a username or quit:" username
    while true;do
            if [ $username == "quit" ];then
                    exit 0
            else
                    info
                    read -p "please input a username or quit:" username
            fi
    done

8、写一个脚本,完成如下功能(使用函数)
   (1) 提示用户输入一个可执行命令的名字;获取此命令依赖的所有库文件;
   (2) 复制命令文件至/mnt/sysroot目录下的对应的rootfs的路径上,例如,如果复制的文件原路径是/usr/bin/useradd,则复制到/mnt/sysroot/usr/bin/目录中;
   (3) 复制此命令依赖的各库文件至/mnt/sysroot目录下的对应的rootfs的路径上;规则同上面命令相关的要求;
    [root@localhost bin]# cat 13.sh 
    #!/bin/bash
    #
    read -p "Please enter a command parameter:" option
    #
    i=`which $option | grep "bin"`
    j () {
       cp $option /mnt/sysroot/$option
       echo "copy $option path to /mnt/sysroot$option over."
    }
    u () {
       lib=`ldd $option | grep -o "\[^[:space:]\{1,\}"`
       for i in $lib ;do
           cp $lib /mnt/sysroot/$option
           echo "copy $option lib to /mnt/sysroot/$option over."
       done
    }
    j
    u

原创文章,作者:wostop,如若转载,请注明出处:http://www.178linux.com/47664

(0)
上一篇 2016-09-19 12:03
下一篇 2016-09-19 13:47

相关推荐

  • 文本处理工具之AWK

    概述:     在之前的文章中,我们介绍过文本处理三剑客的grep、sed,本篇就简要说明下awk的用法。主要是围绕常见的一些用法进行展开,分为以下几个部分:     1、awk的基础语法     2、awk的进阶语法  &nbs…

    Linux干货 2016-09-20
  • ☞实时数据同步方案{ rsync; inotify; }

    实时数据同步方案{ rsync; inotify; } rsync 传输数据 安装 rsyncd 服务 CentOS 6 CentOS 7 配置 rsyncd 服务 配置 rsync 手动同步示例     启动 rsyncd 服务 CentOS 6 CentOS 7 rsync 客户端命令 rsync 数据传输功能 基…

    Linux干货 2016-10-29
  • 密码保护:第二天

    无法提供摘要。这是一篇受保护的文章。

    Linux干货 2017-07-15
  • RPM及YUM工具介绍及使用(下)

    YUM工具 YUM工作原理 YUM工具的出现就是为了解决rpm工具不能够自动解决软件包之间的依赖关系这一难题的。它的工作原理大致如下:YUM透过分析RPM的标头资料,根据各软件的相关性找出软件所依赖的软件列表,然后去下载速度最快的yum仓库中下载所有相关RPM软件包,然后完成相应软件的安装。同时yum工具和rpm工具一样,也可以提供对软件包的查询,安装、升级…

    Linux干货 2016-12-26
  • Linux命令1

    7-13 Linux命令   一、进入终端terminal 1..C1trl+Alt 释放鼠标 2.ifconfig 查询ip地址 3.Ping (IP地址) 查看联网状态 4.ls 查看            -l 列出文件 5.tty、who am i  查看当前的登录终端名…

    Linux干货 2017-07-15
  • centos7 搭建SVN服务器

    运维常见的工作就是日常软件的安装和维护,SVN虽然被Git侵占了市场份额,但是仍然是高效简捷的源码管理工具。从日常软件的安装部署开始,熟悉一些Linux的常用命令。

    Linux干货 2018-03-26

评论列表(1条)

  • 马哥教育
    马哥教育 2016-09-19 17:36

    格式是怎么搞的啊?别的都非常棒