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

相关推荐

  • 挂载

    挂载的相关介绍

    Linux干货 2017-12-10
  • RHCE系列之磁盘加密—-LUKS加密

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://nolinux.blog.51cto.com/4824967/1436460        LUKS (Linux Unified Key Setup)为 Linux 硬盘…

    Linux干货 2016-08-15
  • httpd 基础

      http(1) 开启httpd服务,注意selinux 和防火墙设置。出现错误查看系统日志和http错误日志。 进程间通信:IPC socket:套接字 IP:PORT Client <–> Server     Server: listen  &nb…

    Linux干货 2016-11-01
  • ip ss route nmcli netstart 命令汇总

    route命令 路由管理命令 查看:route -n [root@localhost ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.101.0 0.0.0.0 255.255.255.0 U 1 0 0 e…

    Linux干货 2017-05-07
  • RPM和YUM的使用说明

    一、RPM包管理程序 centos系统上使用rpm命令管理程序包: 安装、卸载、升级、查询、校验、数据库维护 RPM包安装选项:   –test:测试安装,但不真正执行安装   –nodeps:忽略依赖关系   –nosignature:不检查来源合法性   –nodig…

    Linux干货 2016-08-24
  • zabbix报警信息提取

    zabbix报警信息提取     在日常的监控中,我们除了日常的zabbix操作外,我们有的时候还涉及到与其他公司进行数据对接。由于别的公司的数据对接很多时候并不是按照zabbix的数据结构(尤其是大型厂家,或是专业监控厂家,并不会直接使用zabbix,多数是自己开发或是对其他监控软件进行二次开发之类),在这种需求基础…

    Linux干货 2015-12-19