N27—第十周作业

N27_第十周作业

1、请详细描述Centos系统的启动流程(详细到每个过程系统做了哪些事情)
详情请参考http://www.178linux.com/85713
2、为运行于虚拟机上的Centos 6添加一块新的硬盘,提供两个主分区;
(1)为硬盘新建两个主分区;并为其安装grub
(2)为硬盘的第一个主分区提供内核和ramdisk文件;为第二个分区提供rootfs
(3)为rootfs提供bash、ls、cat程序及所依赖的库文件
(4)为grub提供配置文件;
(5)将新的硬盘设置为第一启动项并能够正常启动目标主机

1)增加一块新的硬盘,
[root@localhost ~]# cd /sys/class/scsi_host/
[root@localhost scsi_host]# ls
host0  host1  host2
[root@localhost scsi_host]# echo "- - -" > /sys/class/scsi_host/host0/scan
[root@localhost scsi_host]# echo "- - -" > /sys/class/scsi_host/host1/scan
[root@localhost scsi_host]# echo "- - -" > /sys/class/scsi_host/host2/scan

fdifsk /dev/sdd
………
[root@localhost ~]#mkdir /mnt/{boot,sys}
[root@localhost ~]# mount /dev/sdd1 /mnt/boot/
[root@localhost ~]# mount /dev/sdd2 /mnt/sys/
2) 为硬盘的第一个主分区提供内核和ramdisk文件
[root@localhost ~]# cp /boot/vmlinuz-2.6.32-431.el6.x86_64 /mnt/boot/vmlinuz
[root@localhost ~]# cp /boot/initramfs-2.6.32-431.el6.x86_64.img /mnt/boot/initramfs.img
[root@localhost ~]# grub-install --root-directory=/mnt/boot/ /dev/sdd1
为第二个分区提供rootfs
[root@localhost ~]# cd /mnt/sys/
[root@localhost sys]# mkdir bin dev etc home lib lib64 media mnt opt proc root sbin selinux srv sys tmp usr var
3) 为rootfs提供bash、ls、cat程序及所依赖的库文件
[root@localhost ~]# cp /bin/{bash,ls,cat} /mnt/sys/bin/
[root@localhost ~]# ldd /bin/bash
    linux-vdso.so.1 =>  (0x00007fff095ff000)
    libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00007fe547896000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007fe547692000)
    libc.so.6 => /lib64/libc.so.6 (0x00007fe5472fd000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fe547ac9000)

……
[root@localhost ~]# ldd $(which --skip-alias bash) |grep -o "/.*\.[[:digit:]]"|xargs -I {} cp {} /mnt/sys/lib64
[root@localhost ~]# ldd $(which --skip-alias ls) |grep -o "/.*\.[[:digit:]]"|xargs -I {} cp {} /mnt/sys/lib64
[root@localhost ~]# ldd $(which --skip-alias cat) |grep -o "/.*\.[[:digit:]]"|xargs -I {} cp {} /mnt/sys/lib64
用chroot测试
[root@localhost ~]# chroot /mnt/sys/
bash-4.1# ls
bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  sbin    selinux  srv  sys  tmp    usr  var
bash-4.1# exit
exit
4) 为grub提供配置文件[root@localhost ~]# vim /mnt/boot/boot/grub/grub.conf
default=0
timeout=5
title Centos (my centos)
root (hd0,0)
kernel /vmlinuz ro root=/dev/sdd2 init=/bin/bash
initrd /initramfs.img
3、制作一个kickstart文件以及一个引导镜像。描述其过程
1)通过编辑anaconda-ks.cfg文件
2)运行system-config-kickstart
4、写一个脚本
(1)能接受四个参数:start,stop,restart,status
start:输出”starting脚本名finished”
…
(2)其他任意参数,均报错退出
#!/bin/bash
if [ "$1" = "start" ];then
echo "starting $0 finished"
elif [ "$1" = "stop" ];then
echo "stopping $0 finished"
elif [ "$1" = "restart" ];then
echo "restarting $0 finished"
elif [ "$1" = "status" ];then
echo "statusing $0 finished"
else
echo "请输入start/stop/restart/status"
fi
exit 1
5、写一个脚本,判断给定的用户是否登录了当前系统
(1)如果登录了,则显示用户登录,脚本终止
(2)每3秒钟,查看一次用户是否登录
#!/bin/bash
while true;do
        if `who | grep "$1" &>null `;then
        echo "$1 is alreadly loged in"
        break
        else
        echo "$1 is not loged in"
        fi
        sleep 3
done
6、写一个脚本,显示用户选定要查看的信息
cpu)display cpu info
mem)display memory info
disk)display disk info
quit)quit

#!/bin/bash
cat << EOF
cpu) display cpu info
mem) display memory info
disk) display disk info
quit) quit
EOF
while true;do
read -p "please choose:" choose
case ${choose} in
cpu)
    lscpu
    ;;
mem)
    free -m
    ;;
disk)
    df -HT
    ;;
quit)
    exit
    ;;
*)
    echo “Error!Please choose again!!”
    continue

esac
done
7、写一个脚本
(1)用函数实现返回一个用户的UID和SHELL;用户名通过参数传递而来
(2)提示用户输入一个用户或输入”quit”退出
当输入的是用户名,则调用函数显示用户信息;
当用户输入quit,则退出脚本;进一步地:显示键入的用户相关信息后,再次提醒输出用户名或quit
#!/bin/bash
#!/bin/bash
#查询用户及shell 
#author:dodo 

user_id () {

if id $username &> /dev/null; then
             grep "^$username" /etc/passwd | awk -F: '{print "UID is:"$3, " Shell is:"$7}'
else
         echo "none user" 
fi

}

while true;do
read -p "please enter username or quit:" username
if [ $username == "quit" ];then
       exit 0
    else
       user_id $username
fi
done

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/87981

(1)
N27_flypigN27_flypig
上一篇 2017-10-21 18:50
下一篇 2017-10-21 21:52

相关推荐

  • (总结)RHEL/CentOS 7.x的几点新改变

    PS:RHEL7和CentOS7出来有一段时间了,拿出点时间研究下,有几个地方跟6和5系列相比改变比较大,估计不少童鞋有点不太习惯。下面简要举例说明改变比较大的要点: 一、CentOS的Services使用了systemd来代替sysvinit管理 1、systemd的服务管理程序:systemctl是主要的工具,它融合之前service和chkconfig…

    Linux干货 2015-02-10
  • LVS产生背景、原理及LVS-DR应用实例(二)

    六、LVS-DR应用实例          (一)基本构建思路:           Director: 通过Director实现访问调度到RS1,RS2,实现负载均衡,RS3负责动态分离。…

    Linux干货 2016-10-29
  • 系统管理之系统启动及内核编译

    CentOS 5和6的启动流程服务管理Grub管理自制Linux启动排错编译安装内核 系统启动流程:  POST –> 读取BootSequence (BIOS),决定引导次序 –>读取引导设备的Bootloader(MBR grubstage1–>stage1.5/boot…

    Linux干货 2016-09-13
  • net25-第14周作业

    系统的INPUT和OUTPUT默认策略为DROP; ~]# iptables -P INPUT DROP ~]# iptables -P OUTPUT DROP 1、限制本地主机的web服务器在周一不允许访问;新请求的速率不能超过100个每秒;web服务器包含了admin字符串的页面不允许访问;web服务器仅允许响应报文离开本机; ~]#iptables -…

    Linux干货 2017-05-15
  • shell脚本语言的for循环使用方法和案例

    在shell语言中bash是用的最多的,其语法简单。以指令为核心快速解决常用的问题。所有语言中逻辑控制是必不可少的,它可以帮助我们减少不必要的重复性工作。今天我们就来说说所有语言都会使用的神奇的for循环,学了它以后不仅知道如果规避重复的工作,还能理解程序的运行原理。         for循环是什么?&nb…

    Linux干货 2017-04-16