|
| 1 | +#!/bin/sh |
| 2 | +# |
| 3 | +# for Loongnix-Server 23.2 |
| 4 | +# create rootfs.tar from repository |
| 5 | +# |
| 6 | +#set -x |
| 7 | + |
| 8 | +set -e |
| 9 | + |
| 10 | +arch=loongarch64 |
| 11 | +#release=$1 |
| 12 | +releasever=23.2 |
| 13 | +version=23.2 |
| 14 | +if [ -z $version ] |
| 15 | +then |
| 16 | + echo "releasever or version is empty!!!" |
| 17 | + exit 1 |
| 18 | +fi |
| 19 | + |
| 20 | +output="Loongnix-Server-${version}.rootfs.${arch}.tar.gz" |
| 21 | + |
| 22 | +repos_baseos_url="https://pkg.loongnix.cn/loongnix-server/23.2/os/loongarch64/" |
| 23 | + |
| 24 | +trap cleanup TERM EXIT |
| 25 | + |
| 26 | +work_dir=$(mktemp -d $(pwd)/rootfs-image.XXXXXX) |
| 27 | +rootfs=${work_dir}/rootfs |
| 28 | + |
| 29 | +repo_dir="${work_dir}/yum.repo.d" |
| 30 | +repo_conf="${repo_dir}/Loongnix-server.repo" |
| 31 | +setting_scripts=setting.sh |
| 32 | + |
| 33 | +pkg_list=" |
| 34 | + basesystem bash ca-certificates loongnix-gpg-keys loongnix-release |
| 35 | + loongnix-repos chkconfig cracklib crypto-policies dnf passwd |
| 36 | + expat gawk gdbm glib2 glibc gmp gnupg2 gpgme grep ima-evm-utils |
| 37 | + json-c mpfr ncurses-base procps rpm-build git findutils dnf-plugins-core |
| 38 | + npth p11-kit p11-kit-trust pcre pcre2 popt readline rootfiles |
| 39 | + rpm sed setup systemd systemd-libs tzdata util-linux vim-minimal xz yum cracklib-dicts |
| 40 | +" |
| 41 | +#pkg_list=" |
| 42 | +# acl basesystem bash ca-certificates loongnix-gpg-keys loongnix-release |
| 43 | +# loongnix-repos chkconfig cracklib crypto-policies dnf |
| 44 | +# expat gawk gdbm glib2 glibc gmp gnupg2 gpgme grep ima-evm-utils |
| 45 | +# ipcalc iputils json-c kexec-tools kmod langpacks-en less lzo mpfr ncurses-base |
| 46 | +# npth p11-kit p11-kit-trust pam pcre pcre2 popt procps-ng readline rootfiles |
| 47 | +# rpm sed setup systemd-libs tzdata util-linux vim-minimal xz yum |
| 48 | +#" |
| 49 | + |
| 50 | +#################################################################### |
| 51 | +cleanup() |
| 52 | +{ |
| 53 | + rm -rf ${work_dir} |
| 54 | +} |
| 55 | +#################################################################### |
| 56 | + |
| 57 | +mkdir -pv ${rootfs} || : |
| 58 | +mkdir -pv ${repo_dir} || : |
| 59 | + |
| 60 | +#################################################################### |
| 61 | +# gen repos conf |
| 62 | +#################################################################### |
| 63 | +cat > ${repo_conf} << EOF |
| 64 | +[baseos] |
| 65 | +name=Loongnix-Server-$releasever-baseos |
| 66 | +baseurl=${repos_baseos_url} |
| 67 | +gpgcheck=0 |
| 68 | +enabled=1 |
| 69 | +priority=1 |
| 70 | +excludepkgs="${exclude_pkgs}" |
| 71 | +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-LOONGNIX |
| 72 | +EOF |
| 73 | +#################################################################### |
| 74 | + |
| 75 | + |
| 76 | +#################################################################### |
| 77 | +DNF_OPTS="\ |
| 78 | + --setopt=install_weak_deps=False \ |
| 79 | + --setopt=reposdir=${repo_dir} \ |
| 80 | + --releasever=${releasever} \ |
| 81 | + --installroot=${rootfs} \ |
| 82 | + --nodocs" |
| 83 | + |
| 84 | +echo "Install packages : $pkg_list" |
| 85 | + |
| 86 | +rpmdb --root=${rootfs} --initdb |
| 87 | +dnf ${DNF_OPTS} clean packages |
| 88 | +dnf ${DNF_OPTS} makecache --refresh |
| 89 | +dnf ${DNF_OPTS} -y install ${pkg_list} |
| 90 | +#################################################################### |
| 91 | + |
| 92 | +#################################################################### |
| 93 | +cat > ${rootfs}/${setting_scripts} << EOF |
| 94 | +#!/bin/bash |
| 95 | +
|
| 96 | +## config TERM is linux |
| 97 | +echo 'export TERM=linux' >> etc/bash.bashrc |
| 98 | +echo 'container' > /etc/dnf/vars/infra |
| 99 | +
|
| 100 | +#Generate installtime file record |
| 101 | +/bin/date +%Y%m%d_%H%M > /etc/BUILDTIME |
| 102 | +
|
| 103 | +# Limit languages to help reduce size. |
| 104 | +LANG="en_US" |
| 105 | +echo "%_install_langs $LANG" > /etc/rpm/macros.image-language-conf |
| 106 | +echo "LANG=en_US.UTF-8" > /etc/locale.conf |
| 107 | +
|
| 108 | +pushd /usr/share/locale > /dev/null |
| 109 | + ls | egrep -x -v "en|en@arabic|en@boldquot|en@cyrillic|en@greek|en@hebrew|en@piglatin|en@quot|en@shaw|en_CA|en_GB|en_US|locale.alias" | xargs rm -rf |
| 110 | +popd > /dev/null |
| 111 | +
|
| 112 | +# systemd fixes |
| 113 | +:> /etc/machine-id |
| 114 | +systemd-tmpfiles --create --boot |
| 115 | +# mask mounts and login bits |
| 116 | +systemctl mask systemd-logind.service getty.target console-getty.service |
| 117 | +systemctl mask sys-fs-fuse-connections.mount systemd-remount-fs.service dev-hugepages.mount |
| 118 | +
|
| 119 | +# Remove things we don't need |
| 120 | +yum clean all > /dev/null |
| 121 | +rm -rf /etc/udev/hwdb.bin |
| 122 | +rm -rf /usr/lib/udev/hwdb.d/ |
| 123 | +rm -rf /boot |
| 124 | +rm -rf /var/lib/dnf/history.* |
| 125 | +rm -rf /usr/src/ |
| 126 | +rm -rf /home/* |
| 127 | +rm -rf /var/log/* |
| 128 | +rm -rf /var/cache/* |
| 129 | +rm -rf /var/lib/yum/* |
| 130 | +## Introduced by binutils |
| 131 | +rm -rf /usr/bin/gdb |
| 132 | +rm -f \$0 |
| 133 | +########################################################################### |
| 134 | +EOF |
| 135 | +#################################################################### |
| 136 | + |
| 137 | +chmod +x ${rootfs}/${setting_scripts} |
| 138 | +chroot ${rootfs} /${setting_scripts} |
| 139 | + |
| 140 | +##解决在rootfs中su命令没有权限问题 |
| 141 | +#file_list="fingerprint-auth password-auth postlogin smartcard-auth system-auth user-profile" |
| 142 | +#for file in ${file_list} |
| 143 | +#do |
| 144 | +# chroot ${rootfs} authselect create-profile ${file} |
| 145 | +# chroot ${rootfs} ln -s /etc/authselect/custom/${file} /etc/pam.d/${file} |
| 146 | +#done |
| 147 | + |
| 148 | +##解决在chroot中/dev/null没有权限问题 |
| 149 | +chroot ${rootfs} rm -rf /dev/null |
| 150 | +chroot ${rootfs} mknod /dev/null c 1 3 |
| 151 | +chroot ${rootfs} chmod 666 /dev/null |
| 152 | + |
| 153 | +cur_dir=$(pwd) |
| 154 | +pushd ${rootfs} > /dev/null |
| 155 | + if [ -e "${cur_dir}/${output}" ]; then |
| 156 | + echo "Remove old ${output}" |
| 157 | + rm -rf "${cur_dir}/${output}" |
| 158 | + fi |
| 159 | + |
| 160 | + echo "Generating ${output} ...." |
| 161 | +# tar --numeric-owner --exclude='dev/*' -acf "${cur_dir}/${output}" . |
| 162 | + tar --numeric-owner -acf "${cur_dir}/${output}" . |
| 163 | +popd > /dev/null |
| 164 | + |
| 165 | +echo "Generating ${output} md5sum...." |
| 166 | +sync && md5sum ${output} > ${output}.md5 |
| 167 | + |
| 168 | +###################################### |
| 169 | +sync && echo -e "\n^^^^^^ done ^^^^^^^^^^\n" |
| 170 | +###################################### |
0 commit comments