From fb8e2d82b40b73f2e5a2677f279ab389fe643b58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=AE=B6=E5=B2=AD?= Date: Tue, 17 Sep 2019 17:09:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A04.2=20700=E7=89=88=E6=94=AF?= =?UTF-8?q?=E6=8C=81efi=E5=AE=89=E8=A3=85=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新文件: 4.2-700-efi.md 修改: README.md Signed-off-by: 张家岭 --- 4.2-700-efi.md | 459 +++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 2 + 2 files changed, 461 insertions(+) create mode 100644 4.2-700-efi.md diff --git a/4.2-700-efi.md b/4.2-700-efi.md new file mode 100644 index 0000000..e989483 --- /dev/null +++ b/4.2-700-efi.md @@ -0,0 +1,459 @@ +# 4.2 700版uefi支持 + +## 700版镜像下载 + +[rocky6.0.42.41-x86_64-security-20181101-700.iso](http://42.builder.rd.in.linx/stable-iso/4.2-x86_64-builds/20181101-700/rocky6.0.42.41-x86_64-security-20181101-700.iso) + +--------------------- + +### 重新制作initrd.img + +#### 光盘initrd.img + +目前光盘引导中的initrd.img为正常安装的700版本系统中的/boot/initrd.img-2.6.32.700-Rocky4.2-x86_64文件重命名 + +md5=3596a5ee6924547e4c19487039939693 + +#### initrd解压 + +``` +gunzip -S .img initrd.img +cpio -vimd &1 > /dev/null + + if [ $? -eq 0 ] + + then + + if [ -e /.tmpfs/.cdrom/tag ] + + then + + ln -sf $DEV /dev/cdrom + +# REAL_ROOT="${ROOT}" + + check_flag="true" + + umount /.tmpfs/.cdrom + + rm /.tmpfs -rf + + break + + fi + + else + + check_flag="false" + + log_warning_msg "try to mount cdrom: /dev/$DEV failed." + + fi + + done + + fi + + # check usb disk + + if [ "${check_flag}" == "false" ];then + + + + cat /proc/modules | grep usb_storage + + if [ 0 != $? ];then + + modprobe usb-storage 2>&1 > /dev/null + + fi + + ++ USB_DEVICES=$(list-devices usb-partition) + + for DEV in $USB_DEVICES;do + + if mount -r -t iso9660 $DEV /.tmpfs/.cdrom;then + + if [ -e /.tmpfs/.cdrom/tag ]; then + +# REAL_ROOT="${DEV}" + + ROOT="${DEV}" + + check_flag="true" + + umount /.tmpfs/.cdrom + + rm / + + break + + else + + check_flag="false" + + fi + + log_warning_msg "$DEV on usb disk is not rocky 4.2 iso." + + else + + check_flag="false" + + log_warning_msg "try to mount cdrom on usb disk: $DEV failed." + + fi + + done + + fi + + # Get the root filesystem type + + if [ "${check_flag}" == "false" ]; then + + panic "ALERT! root device: ${REAL_ROOT} does not exist. Dropping to a shell!" + + fi + +# We've given up, but we'll let the user fix matters if they can + while [ ! -e "${ROOT}" ]; do + ``` + +#### initrd压缩 + +``` +find . | cpio -o -H newc | gzip -9 > ../initrd.img +``` + +-------------------------- + +## 制作镜像 + +### 解压镜像 + +``` +mount rocky6.0.42.41-x86_64-security-20181101-700.iso /mnt -o loop +mkdir cd2 +cp -Ra /mnt/. ./cd2 +``` +------------------------------------------------------------------------------ + +### 替换initrd + +``` +cp initrd.img ~/cd2/boot/ +``` + +------------------------------------------------------------------------------ + +### 添加分区对vfat的支持 + +##### 1. 修改cd2/usr/lib/new_install/new_partition/interface_partition.py文件 + +``` +--- /root/cd2/usr/lib/new_install/new_partition/interface_partition.py 2018-10-30 05:30:13.000000000 +0000 ++++ new_partition/interface_partition.py 2019-05-07 07:48:57.000000000 +0000 +@@ -326,7 +326,7 @@ def add_partition(ptype='', extended='', + sg21 = Grid(2,1) + typeLbl = Label("File System type: ") + lb_fstype = Listbox(height=3, scroll=1) +- list_fs = ['ext2', 'ext3', 'ext4', 'linux-swap', 'raid', 'reiserfs', 'xfs', 'jfs'] ++ list_fs = ['ext2', 'ext3', 'ext4', 'vfat', 'linux-swap', 'raid', 'reiserfs', 'xfs', 'jfs'] + for fs in list_fs: + lb_fstype.append(fs, fs) + lb_fstype.setCurrent('ext3') +``` + +##### 2. 修改/root/cd2/usr/lib/new_install/text/ri_newt.py + +``` +root@Linx:~/cd/usr/lib/new_install# diff -uparN /root/cd2/usr/lib/new_install/text/ri_newt.py text/ri_newt.py +--- /root/cd2/usr/lib/new_install/text/ri_newt.py 2018-10-30 05:30:13.000000000 +0000 ++++ text/ri_newt.py 2019-05-07 07:48:57.000000000 +0000 +@@ -524,7 +524,7 @@ class MountPoint(Screen): + Screen.label_mp = Label('mountpoint : ') + Screen.label_fs = Label('File System Type : ') + Screen.widget_label('') +- fs_list = ['ext2','ext3', 'ext4', 'linux-swap', 'reiserfs', 'xfs', 'jfs'] ++ fs_list = ['ext2','ext3', 'ext4', 'vfat', 'linux-swap', 'reiserfs', 'xfs', 'jfs'] + Screen.widget_listbox(3, *fs_list) + Screen.widget_checkbox('Format the partition') + Screen.listbox.setCurrent('ext3') +``` + +------------------------------------------------------------------------------ + +### 制作efi 启动文件 + +#### 制作用于光盘启动bootx64.efi + +##### 1. 在4.2系统中grub-2.02-beta2/grub-core目录下制作用于光盘启动bootx64.efi + +编写grub.cfg文件,用于初始化efi中的环境变量和找到根引导/boot/grub/x86_64-efi/grub.cfg文件 + +早期引导的grub.cfg文件如下 + +``` +search --file /tag --set=root +set prefix=($root)/boot/grub/x86_64-efi/ +configfile $prefix/grub.cfg + +``` +制作bootx64.efi文件 + +``` +../grub-mkimage --config=grub.cfg -O x86_64-efi -d . -o bootx64.efi -p /boot/grub/x86_64-efi part_gpt part_msdos disk fat exfat ext2 ntfs xfs appleldr hfs iso9660 normal search_fs_file configfile linux linux16 chain loopback echo efi_gop efi_uga video_bochs video_cirrus file gfxmenu gfxterm gfxterm_background gfxterm_menu halt reboot help jpeg ls png true +``` + +##### 2. 拷贝efi所依赖的模块到x86_64-efi目录 + +``` +mkdir x86_64-efi +cp *.mod *.lst x86_64-efi/ +``` + +##### 3. 在x86_64-efi目录下编写镜像启动的grub.cfg文件 + +``` +set default="0" + +insmod efi_gop +insmod efi_uga +insmod part_gpt +insmod ext2 +insmod gettext +set root=(hd0) +search --file /tag --set=root +set timeout=5 +### END /etc/grub.d/00_header ### + +menuentry 'Manu Install Rocky OS 4.2' --class rocky --class gnu-linux --class gnu --class os { + insmod part_gpt + insmod fat + linux /boot/isolinux/vmlinuzI instmode=Text efimode=y root=/dev/cdrom vga=791 ro + initrd /boot/initrd.img + +} + +menuentry 'Auto Install Rocky OS 4.2' --class rocky --class gnu-linux --class gnu --class os { + insmod part_gpt + insmod fat + linux /boot/isolinux/vmlinuzI instmode=Auto efimode=y root=/dev/cdrom vga=791 ro + initrd /boot/initrd.img + +} + +menuentry 'StateGrid AutoInstall Rocky OS 4.2' --class rocky --class gnu-linux --class gnu --class os { + insmod part_gpt + insmod fat + linux /boot/isolinux/vmlinuzI instmode=StateGrid efimode=y root=/dev/cdrom vga=791 ro + initrd /boot/initrd.img + +} + +menuentry 'Dmraid Install Rocky OS 4.2' --class rocky --class gnu-linux --class gnu --class os { + insmod part_gpt + insmod fat + linux /boot/isolinux/vmlinuzI instmode=Dmraid efimode=y dmraid=true root=/dev/cdrom vga=791 ro + initrd /boot/initrd.img +} + +``` + +##### 4. 在8.0系统下制作bootx64.img + +``` +dd if=/dev/zero of=bootx64.img bs=1M count=20 +mkfs.vfat bootx64.img +mount bootx64.img /mnt -o loop +mkdir -p /mnt/efi/boot/ +cp bootx64.efi /mnt/efi/boot/ +umount /mnt +cp bootx64.img cd2/boot/grub/ +cp -r x86_64-efi cd2/boot/grub/ + +``` + +#### 制作用于系统启动的bootx64.efi + +##### 1. 在4.2系统中grub-2.02-beta2/grub-core目录下制作用于系统启动的bootx64.efi + +制作bootx64.efi文件 + +``` +../grub-mkimage -O x86_64-efi -d . -o bootx64.efi -p /efi/boot/x86_64-efi search_fs_file search_fs_uuid search_label search part_gpt part_msdos disk fat exfat ext2 ntfs xfs appleldr hfs iso9660 normal search_fs_file configfile linux linux16 chain loopback echo efi_gop efi_uga video_bochs video_cirrus file gfxmenu gfxterm gfxterm_background gfxterm_menu halt reboot help jpeg ls png true + +``` + +##### 2. 将bootx64.efi添加到光盘环境 + +``` +mkdir cd2/opt/efi/boot -p +cp bootx64.efi x86_64-efi/ -r cd2/opt/efi/boot/ +``` +------------------------------------------------------------------------------ + +### 添加efi自动安装脚本 + +#### 1.编写efi安装脚本 + +创建cd2/usr/lib/new_install/operation/finish_install/99exec_install_efi.sh + +``` +#!/bin/bash + +efimode=`cat /proc/cmdline | sed 's/.*efimode=\([^ ]*\).*/\1/'` +upgrubcmd="/usr/sbin/update-grub" + +if [ $efimode == "y" ];then + +source ./functions + +efi_dir="/opt/efi/boot" + +mkdir -p $TARGET/boot/efi/efi/boot + +cp ${efi_dir}/bootx64.efi $TARGET/boot/efi/efi/boot/ + +cp -r ${efi_dir}/x86_64-efi $TARGET/boot/efi/efi/boot/ + +cp $TARGET/boot/grub/grub.cfg $TARGET/boot/efi/efi/boot/x86_64-efi/ + +echo 'exec grub-mkconfig -o /boot/efi/efi/boot/x86_64-efi/grub.cfg $@ ' > $TARGET/$upgrubcmd + +echo -e "Install efi successfully !" +else +echo -e "not efi mode !" +fi + +``` + +#### 2.增加对efi分区情况的限制 + +``` +root@Linx:~/cd2/usr/lib/new_install/text# diff -uparN /root/cd/usr/lib/new_install/text/ri_newt.py /root/cd2/usr/lib/new_install/text/ri_newt.py• +--- /root/cd/usr/lib/new_install/text/ri_newt.py 2019-05-07 07:48:57.000000000 +0000 ++++ /root/cd2/usr/lib/new_install/text/ri_newt.py 2019-06-05 06:51:50.000000000 +0000 +@@ -2,6 +2,7 @@ + from snack import * + import sys + import re ++import logging + sys.path.append('../interface/') + sys.path.append('../new_partition/') +• +@@ -9,6 +10,12 @@ import ri_data + import partition_data as p_d + import interface_partition +• ++logger=logging.getLogger('debuglog') ++logger.setLevel(logging.DEBUG) ++fh=logging.FileHandler('/tmp/test.log') ++fh.setLevel(logging.DEBUG) ++logger.addHandler(fh) ++ + config_xml = "../xml/install_cfg.xml" +• + class Screen: +@@ -478,6 +485,7 @@ class MountPoint(Screen): + self.mds.sort() +• + def check_mountpoint(self,flag='one'): ++ eficheck=0 + nonmount_dir = ['/dev','/etc','/lib64','/lib','/bin','/sbin','/proc','/sys'] + if flag == 'one': + mountpoint = Screen.entry.value() +@@ -497,6 +505,20 @@ class MountPoint(Screen): + return False + return True + elif flag == 'all': ++ for f in self.disks: ++ efidict={} ++ efidevs=p_d.Partition.dict[f]['partition'].keys() ++ if (f+'1') in efidevs: ++ logger.info('efi maybe' + f +'1') ++ logger.info('mountpoint is' +str(p_d.Partition.dict[f]['partition'][f+'1']['mount_point'])) ++ logger.info('filesystem is' +str(p_d.Partition.dict[f]['partition'][f+'1']['filesystem'])) ++ efidict['dev']=f+'1' ++ efidict['mountpoint']=str(p_d.Partition.dict[f]['partition'][f+'1']['mount_point']) ++ efidict['filesystem']=str(p_d.Partition.dict[f]['partition'][f+'1']['filesystem']) ++ if (efidict['mountpoint']=='/boot/efi' or efidict['mountpoint']=='/boot/efi/') and (efidict['filesystem'] == 'vfat'): ++ eficheck=1 ++ break ++ + list_mountpoint = [] + for m in ri_data.Raid.dict.keys(): + R = ri_data.Raid.dict[m] +@@ -511,9 +533,10 @@ class MountPoint(Screen): + list_mountpoint.append(p_d.Partition.dict[d]['partition'][p]['mount_point']) + if len(list_mountpoint) != len(list(set(list_mountpoint))) or '/' not in list_mountpoint: + return False ++ elif eficheck != 1: ++ return False + else: + return True +- + def set_mountpoint(self, device): + disk = device.split(':')[0] + dev = device.split(':')[1] +@@ -524,7 +547,7 @@ class MountPoint(Screen): + Screen.label_mp = Label('mountpoint : ') + Screen.label_fs = Label('File System Type : ') + Screen.widget_label('') +- fs_list = ['ext2','ext3', 'ext4', 'vfat', 'linux-swap', 'reiserfs', 'xfs', 'jfs'] ++ fs_list = ['ext2','ext3', 'ext4', 'linux-swap', 'reiserfs', 'xfs', 'jfs','vfat'] + Screen.widget_listbox(3, fs_list) + Screen.widget_checkbox('Format the partition') + Screen.listbox.setCurrent('ext3') +@@ -551,7 +574,7 @@ class MountPoint(Screen): + s = Screen.yesno(self.title, 1, 8, 'TextboxReflowed', 'eLabel', 'Grid_Complex', 'eLabel', 'Checkbox','eLabel','ButtonBar') + if s == 0: + if not self.check_mountpoint(flag='one'): +- Screen.pop_window('Invalid mount point','The mount point you entered is invalid.\nMount point must start with "/".They cannot contain spaces.\nMount point cannot be "/dev","/etc","/lib","lib# ++ Screen.pop_window('Invalid mount point','The mount point you entered is invalid.\nMount point must start with "/boot/efi".They cannot contain spaces.\nMount point cannot be "/dev","/etc","/l# + continue + if MD: + if Screen.entry.value() != '' or Screen.checkbox.value() == 1: +@@ -561,7 +584,6 @@ class MountPoint(Screen): + ri_data.Raid.dict[disk].filesystem = Screen.listbox.current() + ri_data.Raid.dict[disk].mp = Screen.entry.value() + break +- #p_d.Partition.dict[disk]['partition'][dev]['format'] = 'yes' + else: + if Screen.entry.value() != '' or Screen.checkbox.value() == 1: + p_d.Partition.dict[disk]['partition'][dev]['format'] = 'yes' +@@ -629,7 +651,7 @@ class MountPoint(Screen): + break + else: + if not self.check_mountpoint(flag='all'): +- Screen.pop_window('Invalid mount point','Two file systems must not be assigned the same mount point.\nA root file system is needed.\nPlease correct this by changing mount points.', 50) ++ Screen.pop_window('Invalid mount point','Two file systems must not be assigned the same mount point.\nA root file system is needed.\nIn efi install mod the first partition mountpoint must be# + continue + break + return (s == 'help' and '0' or s) +``` + +------------------------------------------------------------------------------ + +### 制作镜像 + +#### 安装isolinux + +``` +apt-get install isolinux + +``` +#### mk_iso_4.2.sh脚本 + +``` +#!/bin/bash +# shiftwidth=4 tabstop=4 + +isopath="$1" +output="$2" + +xorriso -as mkisofs -r -checksum_algorithm_iso md5,sha1 -V `cat ${isopath}/tag| cut -b1-32` -o ${output} -J -isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin -partition_offset 16 -J -cache-inodes -b boot/isolinux/isolinux.bin -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e boot/grub/bootx64.img -no-emul-boot -isohybrid-gpt-basdat -isohybrid-apm-hfsplus $isopath + +``` +#### 执行脚本制作镜像 + +``` +./mk_iso_4.2.sh cd2 linx4.2-700-uefi.iso + +``` +------------------------------------------------------------------------------ diff --git a/README.md b/README.md index 7ee40f4..3c985a3 100755 --- a/README.md +++ b/README.md @@ -48,3 +48,5 @@ ## [firefox编译过程记录](firefox.md) ## [编译调试版glibc以及gdb调试的简单用法](glibc-debug-gdb.md) + +## [4.2 700版支持efi](4.2-700-efi.md)