always-waiting / Leetcode

Leetcode练习
1 stars 1 forks source link

centos内存镜像打包流程 #1

Open always-waiting opened 3 years ago

always-waiting commented 3 years ago

1.安装febootstrap https://www.dwhd.org/20160630_111307.html

2.构建目录结构

febootstrap -i bash -i wget -i yum -i telnet -i iputils -i iproute -i vim -i gzip -i tar centos76 centos76-extend http://mirrors.aliyun.com/centos/7/os/x86_64/
chroot ~/febootstrap/centos76-extend yum install elrepo-release -y
chroot ~/febootstrap/centos76-extend/ yum --enablerepo=elrepo-kernel install kernel-ml kernel-ml-devel.x86_64
cd centos76-extend/
time tar -cf - . | xz -v --threads=24 > ~/febootstrap/initramfs/rootfs.tar.xz
cd initramfs/
wget -O ~/febootstrap/initramfs/bin/busybox https://busybox.net/downloads/binaries/1.21.1/busybox-x86_64
cat <<EOF > init 
#!/bin/sh

[ -d /dev ] || mkdir -m 0755 /dev
[ -d /root ] || mkdir -m 0700 /root
[ -d /sys ] || mkdir /sys
[ -d /proc ] || mkdir /proc
[ -d /tmp ] || mkdir /tmp
mkdir -p /var/lock
mount -t sysfs -o nodev,noexec,nosuid sysfs /sys
mount -t proc -o nodev,noexec,nosuid proc /proc
# Some things don't work properly without /etc/mtab.
ln -sf /proc/mounts /etc/mtab

grep -q '\<quiet\>' /proc/cmdline || echo "Loading, please wait..."
# Note that this only becomes /dev on the real filesystem if udev's scripts
# are used; which they will be, but it's worth pointing out
if ! mount -t devtmpfs -o mode=0755 udev /dev; then
        echo "W: devtmpfs not available, falling back to tmpfs for /dev"
        mount -t tmpfs -o mode=0755 udev /dev
        [ -e /dev/console ] || mknod -m 0600 /dev/console c 5 1
        [ -e /dev/null ] || mknod /dev/null c 1 3
fi
mkdir /dev/pts
mount -t devpts -o noexec,nosuid,gid=5,mode=0620 devpts /dev/pts || true
mount -t tmpfs -o "noexec,nosuid,size=10%,mode=0755" tmpfs /run
mkdir /run/initramfs
# compatibility symlink for the pre-oneiric locations
ln -s /run/initramfs /dev/.initramfs
# Set modprobe env
export MODPROBE_OPTIONS="-qb"
# mdadm needs hostname to be set. This has to be done before the udev rules are called!
if [ -f "/etc/hostname" ]; then
        /bin/hostname -b -F /etc/hostname 2>&1 1>/dev/null
fi

exec /sbin/init
EOF
find . -print0 | cpio --null -ov --format=newc | gzip -9 > ../build/initramfs.gz

initramfs.gz就是需要的内存镜像,如果需要对内存镜像做定制化处理,可是使用chroot命令。例如:

# 按照包
chroot ~/febootstrap/centos76-extend yum install elrepo-release -y

3.参考链接 https://cloud.tencent.com/developer/article/1454524 https://www.dwhd.org/20160630_111307.html https://cloud.tencent.com/developer/article/1584786 http://linuxcoming.com/blog/2019/06/21/build_ram_os.html

always-waiting commented 3 years ago

ks.cfg

version=DEVEL

System authorization information

auth --enableshadow --passalgo=sha512

Use CDROM installation media

cdrom

Use graphical install

graphical

Run the Setup Agent on first boot

firstboot --enable

Keyboard layouts

keyboard --vckeymap=cn --xlayouts='cn'

System language

lang zh_CN.UTF-8

Network information

network --bootproto=dhcp --device=eth0 --ipv6=auto --activate network --hostname=localhost.localdomain

Root password

rootpw --iscrypted $6$owsYZffHmB.UhDFZ$Y/XNBqU0oLMl8qfDwuSRoHxLDGEefk4RIEXJIzwD91lvm71aTOxsGGY8I1Xe.N8hmKEWaUV50agAMNo/nHJpz.

System services

services --enabled="chronyd"

System timezone

timezone Asia/Shanghai --isUtc

System bootloader configuration

bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda autopart --type=lvm

Partition clearing information

clearpart --none --initlabel

%packages @^minimal @core chrony kexec-tools

%end

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty %end

default

使用欢迎界面

default vesamenu.c32

default menu.c32

prompt 1

倒计时600毫秒

timeout 600

欢迎词

MENU TITLE welcome to centos.

如下三个驱动

启动本地设备

label local menu label Boot from ^local drive localboot 0xffff

启动来自于ks配置文件

MENU SEPARATOR label linux menu label ^Install or upgrade an existing system for ks

系统默认选ks

menu default kernel vmlinuz append initrd=initrd.img ks=http://172.18.41.133/ks_config/CentOS7-ks.cfg

安装基本驱动

MENU SEPARATOR label vesa menu label Install system with ^basic video driver kernel vmlinuz append initrd=initrd.img xdriver=vesa nomodeset

always-waiting commented 3 years ago

1.安装基础软件,如果是最小化安装的话 yum install -y bash-completion vim lrzsz wget expect net-tools nc nmap tree dos2unix htop iftop iotop unzip telnet sl psmisc nethogs glances bc ntpdate

2.配置yum源 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo yum clean all yum makecache

3.关闭防火墙 [root@kickstart yum.repos.d]# systemctl stop firewalld [root@kickstart yum.repos.d]# systemctl disable firewalld Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

[root@client01 ~]# sed -i 's/enforcing/disabled/g' /etc/selinux/config [root@kickstart ~]# getenforce Disabled

4.关闭vmware的dhcp服务,设置linux静态ip [root@kickstart ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE="Ethernet" PROXY_METHOD="none" BROWSER_ONLY="no" BOOTPROTO="static" DEFROUTE="yes" IPV4_FAILURE_FATAL="no" IPV6INIT="yes" IPV6_AUTOCONF="yes" IPV6_DEFROUTE="yes" IPV6_FAILURE_FATAL="no" IPV6_ADDR_GEN_MODE="stable-privacy" NAME="ens33" UUID="b4c06569-fc94-4e94-9c63-0391c7a35432" DEVICE="ens33" ONBOOT="yes" IPADDR=172.18.41.133 NETMASK=255.255.255.0 DNS1=1.2.4.8 GATEWAY=172.18.41.2

5.系统检查 [root@kickstart ~]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core)

[root@kickstart ~]# uname -r 3.10.0-862.el7.x86_64

[root@kickstart ~]# ifconfig ens33 |awk 'NR==2 {print $2}' 172.18.41.133

[root@kickstart ~]# iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination

Chain FORWARD (policy ACCEPT) target prot opt source destination

Chain OUTPUT (policy ACCEPT) target prot opt source destination

6.时间同步更新 [root@kickstart ~]# ntpdate -u ntp.aliyun.com 修改时区 [root@kickstart ~]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime [root@kickstart ~]# date Tue Jul 21 19:05:06 CST 2020

always-waiting commented 3 years ago

PXE准备流程

关防火墙 systemctl stop firewalld

安装dhcp服务 yum install dhcp -y cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example ./dhcpd.conf 根据需求,修改配置文件/etc/dhcp/dhcpd.conf systemctl start dhcpd

安装tftp服务 yum install tftp-server tftp -y systemctl start tftp.socket

安装必要启动文件 yum install syslinux -y cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ 去镜像文件中拷贝vmlinuz 拷贝内存系统

创建pxe启动文件 mkdir pxelinux.cfg vim pxelinux.cfg/default

参考链接 https://blog.51cto.com/1992tao/1870431