N26-博客作业-week10

1、请详细描述CentOS系统的启动流程(详细到每个过程系统做了哪些事情)

N26-博客作业-week10

2、为运行于虚拟机上的CentOS 6添加一块新硬件,提供两个主分区;
  (1) 为硬盘新建两个主分区;并为其安装grub;
  (2) 为硬盘的第一个主分区提供内核和ramdisk文件; 为第二个分区提供rootfs;
  (3) 为rootfs提供bash、ls、cat程序及所依赖的库文件;
  (4) 为grub提供配置文件;
  (5) 将新的硬盘设置为第一启动项并能够正常启动目标主机;

~]# fdisk /dev/sdb                                               
~]# mke2fs -t ext4 /dev/sdb{1,2}                                
~]# mount /dev/sdb1 /mnt                                         
~]# grub-install --root-directory=/mnt /dev/sdb                  
~]# cp /boot/initramfs-2.6.32-504.el6.i686.img /mnt/initramfs    
~]# cp /boot/vmlinuz-2.6.32-504.el6.i686 /mnt/vmlinuz            
~]# vim /mnt/boot/grub/grub.conf                                 
    default=0
    timeout=5
    title CentOS6(test)
    root (hd0,0)
    kernel /vmlinuz ro root=/dev/sda2 selinux=0 init=/bin/bash
    initrd /initramfs
~]# umount /dev/sdb1                                              
~]# mount /dev/sdb2 /mnt                                          
~]# mkdir -p /mnt/{bin,sbin,lib,lib64,etc,home,root,media,mnt,dev,tmp}
~]# mkdir -p /mnt/{usr/{bin,sbin,lib,lib64},var{lib,lib64,log,local,cache},proc,sys,selinux}
~]# cp /bin/{bash,ls,cat} /mnt/bin
~]# cp `ldd /bin/{bash,ls,cat}|grep -eo "/lib.*[[:space:]]"| sort -u` /mnt/lib                                             
~]# sync                                                          
~]# init 6                                                        
重启后进入BIOS设置 调整硬盘启动顺序后保存退出。

3、制作一个kickstart文件以及一个引导镜像。描述其过程。

可以直接手动编辑或使用创建工具在桌面模式下用system-config-kickstart (CentOS 6)来创建ks.cfg#命令段firewall --disabled                                    //禁用防火墙install                                                //执行新安装cdrom                                                  //用光盘安装rootpw --iscrypted $1$TxkJ7T6B$obLELgEGcn0uzgA3QTAPl/  //管理员加密密码auth  --useshadow  --passalgo=sha512                   //屏蔽密码算法graphical                                              //安装图形环境firstboot --disable                                    //首次引导禁用代理keyboard us                                            //安装键盘类型lang en_US                                             //默认语言selinux --enforcing                                    //激活selinuxlogging --level=info                                   //信息等级timezone  Asia/Hong_Kong                               //系统时区bootloader --location=mbr                              //在MBR上安装引导程序clearpart --all                                        //删除所有现存分区  part /boot --fstype="ext4" --size=500                  //分区挂载part / --fstype="ext4" --size=10000#脚本段%pre                                                   //安装前脚本echo "start"%end%post                                                  //安装后脚本echo "end"%end#程序包段%packages@chinese-support                                       //中文支持@development                                           //开发工具@graphical-admin-tools                                 //图形化工具@remote-desktop-clients                                //远程桌面客户端git-ibus-table-cangjie-ibus-table-erbi-ibus-table-wubi%end

4、写一个脚本
  (1) 能接受四个参数:start, stop, restart, status
   start: 输出“starting 脚本名 finished.”
   …
  (2) 其它任意参数,均报错退出;

#!/bin/bash
#
cat << EOF
Please make a choice!
start
stop
restart
status
======================
EOF

read -p "Your choice: " choice

case $choice in
    
    start)
        echo "starting script $choice finished."
    ;;
    
    stop)
        echo "starting script $choice finished."
    ;;
    
    restart)
        echo "starting script $choice finished."
    ;;
    
    status)
        echo "starting script $choice finished."
    ;;
    
    *)
        exit 1
esac

5、写一个脚本,判断给定的用户是否登录了当前系统;
  (1) 如果登录了,则显示用户登录,脚本终止;
  (2) 每3秒钟,查看一次用户是否登录;

#!/bin/bash
#
read -p "Give a username: " username

while true; do
    if who | grep "^$username\>" &> /dev/null; then
        break
    fi
    sleep 3
done

echo "$username logged on"  

6、写一个脚本,显示用户选定要查看的信息;
   cpu) display cpu info
   mem) display memory info
   disk) display disk info
   quit) quit
   非此四项选择,则提示错误,并要求用户重新选择,只到其给出正确的选择为止;

#!/bin/bash
#
cat << EOF
cpu) display cpu information
mem) display memory infomation
disk) display disks information
quit) quit
===============================
EOF

read -p "Enter your option: " option

while [ "$option" != "cpu" -a "$option" != "mem" -a "$option" != "disk" -a "$option" != "quit" ]; do
    echo "cpu, mem, disk, quit"
    read -p "Enter your option again: " option
done

if [ "$option" == "cpu" ]; then
    lscpu
elif [ "$option" == "mem" ]; then
    free -m
elif [ "$option" == "disk" ]; then
    fdisk -l /dev/[hs]d[a-z]
else
    echo "quit"
    exit 0
fi

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

#!/bin/bash
#
userinfo() {
    local user=$1
    awk -F: '/^'"$user"'/{printf "%s:%s:%s\n",$1,$3,$NF}' /etc/passwd
}

while true; do
    read -p "Please enter a username or "quit": " choice
    if [[ "$choice" == "quit" ]]; then
        break   
    else
        userinfo $choice
    fi
done

exit 0

原创文章,作者:浙江-咲,如若转载,请注明出处:http://www.178linux.com/72894

(0)
浙江-咲浙江-咲
上一篇 2017-04-09 11:19
下一篇 2017-04-09 14:08

相关推荐

  • 马哥教育N22期第四周作业

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 root@xuc-virtual-machine:/home/xuc# cp -r /etc/skel/ /home/tuser1 root@xuc-virtual-machine:/…

    Linux干货 2016-09-06
  • 第十四周 N21 总有刁民想害朕

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

    Linux干货 2016-10-17
  • 进程管理的总结

    进程管理的总结 进程相关概念: Process: 运行中的程序的一个副本,是被载入内存的一个指令集合。进程是程序的基本执                      行实体;程序是指令、数据及其组织形式的描述,进程是程序的实体 Process ID:进程的标记号码 task struct:Linux内核存储进程信息的数据结构格式 task list:多个任务的…

    2017-12-23
  • Linux命令语法及其帮助信息

    一、Linux命令语法 1、通用格式:command options argument 2、Command: 3、Options: 4、Argument: 二、Linux命令帮助信息获取途径 1、help命令 && –help选项 2、manual (1)章节 (2)语法 (3)man命令输出详解   &nbs…

    Linux干货 2016-09-19
  • centos启动流程

    加电自检 检测硬件是否存在并且能够正常运行,如cpu、内存、硬盘是否存在并能正常运行,以及外围得输入输出设备是否存在,如键盘、鼠标、显示器。 bios启动次序,按照次序查找个引导设备,启动第一个具有引导程序的设备,即为本次启动需要加载的设备。 加载boot loader bootloader安装在mbr中,linux的bootloader程序为grub和li…

    Linux干货 2017-11-14
  • 流编辑器Sed(Stream Edit)详解

    流编辑器Sed(Stream Edit)详解       Grep 、sed 和awk并称为文本三剑客。使用Grep就可以很好的实现文本查找的功能,而且简单有效。然而其却无法直接对其进行编辑,sed的出现便解决了这一问题。 Sed被称为流编辑器,它是一种新型的非交互式的文本编辑器,它逐行处理文件或输入,并将结…

    Linux干货 2016-08-22

评论列表(1条)

  • 马哥教育
    马哥教育 2017-04-13 09:41

    总结的比较不错~继续加油~