• Linux系统自动化安装


    centos 系统安装启动流程:

        bootloader --> kernel(initramfs) --> rootfs --> /sbin/init

    anaconda : 系统安装程序

        tui : 基于图形库 curses 的文本窗口

        gui : 图形窗口

    MBR : boot.cat

    stage2 : isolinux/isolinux.cfg

        配置文件 : isolinux/isolinux.cfg

        每个对应的菜单选项 :

            加载内核 : isolinuz/vmlinuz

            向内核传递参数 : append initrd=initrd.img ...

    装载根文件系统,并启动 anaconda

        默认启动 GUI 接口

        若是显示指定使用TUI接口 : 向内核传递 text 参数即可

        (1)按 tab 键,在后面增加 text

        (2)按 ESC 键, boot: linux text

    anaconda 工作过程 

    anaconda安装系统分成三个阶段

    安装前配置阶段:

        安装过程使用的语言

        键盘类型

        安装目标存储设备

            Basic Storage : 本地磁盘

            特殊设备 : ISCSI

        设定主机名

        配置网络接口

        时区

        管理员密码

        设定分区方式及MBR的安装位置

        创建一个普通用户

        选定要安装的程序包

    安装阶段:

        在目标磁盘创建分区,执行格式化操作等

        将选定的程序包安装至目标位置

        安装 bootloader 和 initramfs

    首次启动 :

        iptables

        selinux

        core dump

    系统安装

    启动安装过程一般应位于引导设备;后续的anaconda及其安装用到的程序包等可来自下面几种方式:

    •     本地光盘
    •     本地硬盘
    •     ftp server : yum repository
    •     http server : yum repostory
    •     nfs server

    如果想动手指定安装源:

        boot: linux askmethod

    anaconda 的配置方式

        (1)交互式配置方式

        (2)通过读取事先给定的配置文件自动完成配置

            按照特定的语法给出的配置选项,kickstart 文件

    安装 bott 引导选项 :boot

        text : 文本安装方式

        askmethod : 手动指定使用的安装方法

    与网络相关的引导选项:

    1. ip=IPADDR
    2. netmask=MASK
    3. gateway=GW
    4. dns=DNS_ip
    5. ifname=NAME:MAC_ADDR

    与远程访问功能相关的引导选项:

        vnc

        vncpassword='password'

    指明kickstart文件的位置:  ks=

    1. DVD drive: ks=cdrom:/PATH/TO/KICKSTART_FILE 
    2. Hard drive: ks=hd:device:/directory/KICKSTART_FILE 
    3. HTTP server: ks=http://host:port/path/to/KICKSTART_FILE 
    4. FTP server: ks=ftp://host:port/path/to/KICKSTART_FILE 
    5. HTTPS server: ks=https://host:port/path/to/KICKSTART_FILE 
    6. NFS server:ks=nfs:host:/path/to/KICKSTART_FILE 

    启动紧急救援模式:

        rescue

    kickstart文件的格式

    命令段 : 指明各种安装前配置,比如键盘类型,语言等

        必备命令:

    1. authconfig: 认证方式配置 authconfig --useshadow --passalgo=sha512 
    2. bootloader:bootloader的安装位置及相关配置 bootloader --location=mbr --driveorder=sda – append="crashkernel=auto  rhgb quiet" 
    3. keyboard: 设定键盘类型 
    4. lang: 语言类型 
    5. part: 创建分区 
    6. rootpw: 指明root的密码 
    7. timezone: 时区

        可选命令:

    1. install OR upgrade 
    2. text: 文本安装界面 
    3. network 
    4. firewall 
    5. selinux 
    6. halt 
    7. poweroff 
    8. reboot 
    9. repo 
    10. user:安装完成后为系统创建新用户 
    11. url: 指明安装源 
    12. key –skip 跳过安装号码,适用于rhel版本

            

    程序包段 : 指明要安装的程序包组,或者程序包等

    1. %packages 
    2. @group_name 
    3. package 
    4. -package 
    5. %end

    脚本段 :

        %pre: 安装前脚本 

            运行环境:运行于安装介质上的微型Linux环境 

        %post: 安装后脚本 

            运行环境:安装完成的系统

    kickstart 文件的创建

    (1) 直接根据某模板手动编辑修改

    (2) 可以使用创建工具 : system-config-kickstart

        如果没有该工具,需要安装  

    yum install -y system-config-kickstart

         然后就可以依据某模板修改并完成新的配置

    (3) 完成配置后检查ks文件的语法错误 : ksvalidator

    ksvalidator /PATH/TO/kickstart.cfg

    制作引导光盘和U盘

    创建引导光盘:

    1. cp /media/cdrom/isolinux/  /tmp/myiso/ 
    2. vi  /tmp/myiso/isolinux/isolinux.cfg 
    3. initrd=initrd.img text ks=cdrom:/myks.cfg 
    4. cp /root/myks.cfg /tmp/myiso/ 
    5. cd /tmp 
    6. 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 myiso/

    创建U盘启动盘

    dd if=/dev/sr0 of=/dev/sdb 

    自制自定义引导 boot.iso 文件

    工作环境 centos6.8

    http://10.1.1.41  是我自己搭建的一个yum源服务器的ip

    1,先创建kickstart文件

    2,安装完成后再重新运行一次

     ks.cfg文件内容

    1. [root@centos6 Desktop]# cat ks.cfg 
    2. #platform=x86, AMD64, or Intel EM64T
    3. #version=DEVEL
    4. # Firewall configuration
    5. firewall --enabled
    6. # Install OS instead of upgrade
    7. install
    8. # Use network installation
    9. url --url="http://10.1.1.41/centos6/yum/"
    10. # Root password
    11. rootpw --iscrypted $1$DYysuQkH$3H7KLb/uXt75K5cK6YYrU1
    12. # System authorization information
    13. auth  --useshadow  --passalgo=sha512
    14. # Use text mode install
    15. text
    16. firstboot --disable
    17. # System keyboard
    18. keyboard us
    19. # System language
    20. lang en_US
    21. # SELinux configuration
    22. selinux --enforcing
    23. # Installation logging level
    24. logging --level=info
    25. # Reboot after installation
    26. reboot
    27. # System timezone
    28. timezone  Asia/Shanghai
    29. # Network information
    30. network  --bootproto=dhcp --device=eth0 --onboot=on
    31. # System bootloader configuration
    32. bootloader --location=mbr
    33. # Clear the Master Boot Record
    34. zerombr
    35. # Partition clearing information
    36. clearpart --all --initlabel 
    37. # Disk partitioning information
    38. part /boot --fstype="ext4" --size=1000
    39. part / --fstype="ext4" --size=30000
    40. part swap --fstype="swap" --size=3000
    41. %post
    42. echo welcome to nineven_linux >> /etc/issue
    43. mkdir /share
    44. echo '//10.1.1.41/LinuxShare /sharecifsdefaults,username=nineven,password=nineven 0 0' >> /etc/fstab
    45. useradd cent
    46. echo cent | passwd --stdin cent
    47. mkdir /etc/yum.repos.d/old
    48. mv /etc/yum.repos.d/C* /etc/yum.repos.d/old/
    49. wget http://10.1.1.41/centos6/local.repo -O /etc/yum.repos.d/local.repoa
    50. %end
    51. %packages
    52. @backup-client
    53. @base
    54. @basic-desktop
    55. @compat-libraries
    56. @console-internet
    57. @development
    58. @fonts
    59. @hardware-monitoring
    60. @kde-desktop
    61. @network-file-system-client
    62. @network-tools
    63. @perl-runtime
    64. @storage-client-fcoe
    65. git
    66. xsettings-kde
    67. %end

    2,制作boot.iso 镜像引导文件

    1. [root@centos6 Desktop]# mount /dev/cdrom /media
    2. mount: block device /dev/sr0 is write-protected, mounting read-only
    3. [root@centos6 Desktop]# cd /testdir/
    4. [root@centos6 testdir]# ls
    5. [root@centos6 testdir]# cp -r /media/isolinux/ .
    6. [root@centos6 testdir]# ls
    7. isolinux
    8. [root@centos6 testdir]# cd isolinux/
    9. [root@centos6 isolinux]# ls
    10. boot.cat  grub.conf   isolinux.bin  memtest     TRANS.TBL     vmlinuz
    11. boot.msg  initrd.img  isolinux.cfg  splash.jpg  vesamenu.c32
    12. [root@centos6 isolinux]# vim isolinux.cfg

    centos6:

    centos 7

    1. label linux
    2.   menu label ^Auto install CentOS Linux 7
    3.   kernel vmlinuz
    4.   menu default
    5.   append initrd=initrd.img inst.stage2=http://192.168.56.1/centos7/yum inst.ks=http://192.168.56.1/centos7/centos7-ks.cfg
    6. label linux
    7.   menu label ^Install CentOS Linux 7 by yourself
    8.   kernel vmlinuz
    9.   append initrd=initrd.img inst.stage2=http://192.168.56.1/centos7/yum

    然后执行命令如下:

    [root@centos6 isolinux]# mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 --boot-info-table -V "Centos 6.8 x64 nineven_boot" -b isolinux.bin -c boot.cat -o /share/boot.iso /testdir/isolinux/

    3,已经制作完成,下面新建一个虚拟机,把该boot.iso 文件作为光盘挂载

  • 相关阅读:
    二、系统知识笔记-系统架构概述
    【机器学习】用 EM 算法推导解释 Kmeans?(面试回答)
    MySQL学习问题记录
    景联文科技:打造亿级高质量教育题库,赋能教育大语言模型新未来
    读Mybatis框架 总结(个人理解)
    超级基础篇_疑惑实验
    多种方法论的融合,可以把FMEA做得更好——FMEA软件
    代理模式(CGLIB和JDK)
    1panel + Pbootcms 设置伪静态规则
    大数据知识扫盲
  • 原文地址:https://blog.csdn.net/ly1358152944/article/details/126341355