写于 2022/05/13 ,有个老哥的 pve lvm not found,无法开机,然后他瞎搞一番后来找我,我让他 vgchange -a y 激活后挂载 /dev/mapper/pve-root 后进去修复 grub 。他当时用的是 debian 的 iso 进去整的,vgchange 的时候报错无法找到 dm-thin-pool 内核模块,然后还无法激活所有的 vg,我让他用 centos7.x 的 iso 进 rescue 试试后全部激活了。然后报错:
1 2 3 4 5 6
$ mount /dev/mapper/pve-root /mnt/sysimage mount: wrong fs type, bad option, bad superblock on /dev/mapper/pve-root, missing codepage or helper program, or other error
In some cases useful info is found in syslog - try dmesg | tail or so.
看着是损坏了,pve 的 root 分区是 ext4 的,让他修复下:
1 2 3 4
$ fsck.ext4 /dev/mapper/pve-root e2fsck 1.42.9 (28-Dec-2013) /dev/mapper/pve-root has unsupported feature(s): metadata_csum e2fsck: Get a newer version of e2fsck!
看样子 pve 的 mkfs.ext4 用了一些特性,而 centos 的 ISO 里的 e2fsck 实在太老了,后面让他用 pve 或者 debian 的 iso 进去修复了。然后我就有了静态编译 e2fsck 的想法。
e2fsck
静态编译
官方代码仓库
先找源码,github 上没找到,于是 man e2fsck 找到 This version of e2fsck was written by Theodore Ts'o <tytso@mit.edu> ,源码找的几个可下载的地址:
If you wish to turn on ELF shared libraries, add the option --enable-elf-shlibs. If you wish to build profiling libraries, add the option --enable-profile.
FROM docker.mirrors.ustc.edu.cn/library/ubuntu as build ARG branch=1.46.5 ENV DEBIAN_FRONTEND noninteractive RUN sed -ri 's/(ports|deb|security|archive).(debian.org|ubuntu.com)/mirrors.aliyun.com/g' /etc/apt/sources.list \ && apt-get update WORKDIR /opt
FROM scratch AS bin COPY --from=build /install_root /
构建
1 2 3 4 5
docker buildx build . --platform linux/amd64,linux/arm64 --target bin --output .
$ file linux_a*/bin/fsck.ext4 linux_amd64/bin/fsck.ext4: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=a0f4bf08157fdc8132707af16f9fc103a411c05b, for GNU/Linux 3.2.0, with debug_info, not stripped linux_arm64/bin/fsck.ext4: ELF 64-bit LSB executable, ARM aarch64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=8b9c945c4a18bdaf6152b8445498fc5f436f5c3f, for GNU/Linux 3.7.0, with debug_info, not stripped