Quantcast
Channel: CodeSection,代码区,Linux操作系统:Ubuntu_Centos_Debian - CodeSec
Viewing all articles
Browse latest Browse all 11063

N21沉舟第十周作业

$
0
0

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


N21沉舟第十周作业

2、为运行于虚拟机上的CentOS 6添加一块新硬件,提供两个主分区;

(1) 为硬盘新建两个主分区;并为其安装grub;

(2) 为硬盘的第一个主分区提供内核和ramdisk文件; 为第二个分区提供rootfs;

(3) 为rootfs提供bash、ls、cat程序及所依赖的库文件;

(4) 为grub提供配置文件;

(5) 将新的硬盘设置为第一启动项并能够正常启动目标主机;

~]# fdisk /dev/sdb
~]# partx -a /dev/sdb
~]# mount /dev/sdb1 /mnt/sd
~]# grub-install --root-directory=/mnt/sd /dev/sdb
~]# cp /boot/vmlinuz-2.6.32-504.el6.x86_64 /mnt/sd/vmlinuz
~]# cp /boot/initramfs-2.6.32-504.el6.x86_64.img /mnt/sd/initramfs.img
~]# cp /boot/grub/grub.conf /mnt/sd/boot/grub/grub.conf
~]# cat /sdb1/boot/grub/grub.conf
default=0
timeout=5
hiddenmenu
title CentOS 6 (test new)
root (hd0,0)
kernel /vmlinuz ro root=/dev/sda2 selinux=0 init=/bin/bash
initrd /initramfs.img
~]# umount /dev/sdb1 #卸载分区1
~]# mount /dev/sdb2 /mnt #挂载分区2
~]# 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 #复制lib文件
~]# sync #同步
~]# init 6 #重启
#进入bios,设置硬盘启动顺序

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

#命令段
firewall --disabled //禁用防火墙
install //执行新安装
cdrom //用光盘安装
rootpw --iscrypted $1$TxkJ7T6B$obLELgEGcn0uzgA3QTAPl/ //管理员加密密码
auth --useshadow --passalgo=sha512 //屏蔽密码算法
graphical //安装图形环境
firstboot --disable //首次引导禁用代理
keyboard us //安装键盘类型
lang en_US //默认语言
selinux --enforcing //激活selinux
logging --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

简单引导镜像光盘制作:


(1)复制系统安装光盘/Packages /repodata外的所有目录下的所有文件到一自制目录中(/tmp/myiso/)
(2)创建引导光盘:把myiso目录创建为光盘镜像boot.iso
~]# mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 --boot-info-table
-V "CentOS 6.6 x86_64 boot" -b isolinux/isolinux.bin
-c isolinux/boot.cat -o /root/boot.iso /tmp/myiso/

4、写一个脚本

(1) 能接受四个参数:start, stop, restart, status

start: 输出“starting 脚本名 finished.”

(2) 其它任意参数,均报错退出;

#!/bin/bash
#
case $1 in
start)
echo "starting $0 finished."
;;
stop)
echo "stoping $0 finished."
;;
restart)
echo "restarting $0 finished."
;;
status)
echo "$0 is running."
;;
*)
echo "wrong input."
exit 1
;;
ssac

5、写一个脚本,判断给定的用户是否登录了当前系统;

(1) 如果登录了,则显示用户登录,脚本终止;

(2) 每3秒钟,查看一次用户是否登录;

#!/bin/bash
#
while [ 0 -eq 0 ];do
if `who | grep $1&>/dev/null`;then
echo "$1 is login."
exit 0
else
sleep 3
fi
done

6、写一个脚本,显示用户选定要查看的信息;

cpu) display cpu info

mem) display memory info

disk) display disk info

quit) quit

非此四项选择,则提示错误,并要求用户重新选择,只到其给出正确的选择为止;

#!/bin/bash
#
while [ 1 -eq 1 ];do
echo "please input a option:"
echo "mem: display memory info."
echo "disk: display disk info."
echo "quit: quit mean."
read -p ":" test
case $test in
cpu)
cat /proc/cpuinfo
;;
mem)
free -m
;;
disk)
fdisk -l
;;
quit)
exit 0
;;
*)
echo "you have wrong choose."
continue
;;
esac
done

7、写一个脚本

(1) 用函数实现返回一个用户的UID和SHELL;用户名通过参数传递而来;

(2) 提示用户输入一个用户名或输入“quit”退出;

当输入的是用户名,则调用函数显示用户信息;

当用户输入quit,则退出脚本;进一步地:显示键入的用户相关信息后,再次提醒输出用户名或quit:

#!/bin/bash
#
function userid {
while [ 1 -eq 1 ];do
read -p "please input a username:" uname
if id $uname&>/dev/null;then
uuid=$(grep "^$uname" /etc/passwd|cut -d: -f3 )
ushell=`grep "^$uname" /etc/passwd|cut -d: -f7`
echo "user $uname UUID is $uuid."
echo "user $uname shell is $ushell"
else
if [ $uname == "quit" ];then
exit 1
else
echo "please input a right username."
continue
fi
fi
done
}
userid

8、写一个脚本,完成如下功能(使用函数)

(1) 提示用户输入一个可执行命令的名字;获取此命令依赖的所有库文件;

(2) 复制命令文件至/mnt/sysroot目录下的对应的rootfs的路径上,例如,如果复制的文件原路径是/usr/bin/useradd,则复制到/mnt/sysroot/usr/bin/目录中;

(3) 复制此命令依赖的各库文件至/mnt/sysroot目录下的对应的rootfs的路径上;规则同上面命令相关的要求;

#!/bin/bash
#
function comdso {
read -p "input a command:" comd
dirname=`dirname $(which $comd)`
if [ -d /mnt/sysroot`which $comd` ];then
cp -r `which $comd` /mnt/sysroot`which $comd`
else
mkdir -p /mnt/sysroot$dirname
cp -r `which $comd` /mnt/sysroot`which $comd`
fi
for i in `ldd $(which $comd) |grep -o "/lib.*[[:space:]]"`;do
dirname=`dirname $i`
if [ -d /mnt/sysroot$dirname ];then
cp -r $i /mnt/sysroot$i
else
mkdir -p /mnt/sysroot$dirname
cp -r $i /mnt/sysroot/usr$i
fi
done
}
comdso

Viewing all articles
Browse latest Browse all 11063

Trending Articles