美文网首页
[Linux] 定制 Linux Mint 20.2 开发镜像

[Linux] 定制 Linux Mint 20.2 开发镜像

作者: zqq90 | 来源:发表于2021-07-25 23:15 被阅读0次

    !!未完成

    背景

    单纯该更新了

    注意事项

    • 仅供参考学习,部分组件需要额外的授权,除非你能友好的解决,否则,不要分发成品
    • 每个步骤虽经过实际操作,但请根据实际情况 慎重选择 是否执行一些操作,否则可能会对某些 娇贵的 机器造成 永久性的硬件损伤
    • 推荐在 Ext4 文件系统下操作,否则可能丢失文件的权限等信息
    • 有任何意见和建议,请务必联系

    环境 & 工具

    • LinuxMint 20.2 (Kernel: 5.11.0-25-generic)
    • VirtualBox
    • 必备工具:
    sudo apt install squashfs-tools xorriso isolinux
    

    操作记录

    初始化

    sudo su -
    
    export V_KN_OLD=5.4.0-74
    export V_KN_NEW=5.11.0-25
    
    V_WORKSPACE=/home/zhuqq4/some/custom-linuxmint
    V_MNT_ISO=/mnt/iso
    
    V_ISO_ORIGIN=${V_WORKSPACE}/linuxmint-20.2-cinnamon-64bit.iso
    V_CUSTOM_SRC=${V_WORKSPACE}/squashfs-root
    V_ISO_SRC=${V_WORKSPACE}/iso-src
    V_ISO_OUT=${V_WORKSPACE}/linuxmint-20.2-zqq.iso
    V_ISO_TITLE="LINUXMINT_ZQQ"
    

    准备 & 解压

    mkdir -p "${V_WORKSPACE}" "${V_ISO_SRC}" "${V_MNT_ISO}"
    
    mount "${V_ISO_ORIGIN}" "${V_MNT_ISO}"
    rsync -a --exclude=casper/filesystem.squashfs "${V_MNT_ISO}/" "${V_ISO_SRC}/"
    unsquashfs -d "${V_CUSTOM_SRC}" "${V_MNT_ISO}/casper/filesystem.squashfs"
    umount "${V_MNT_ISO}"
    

    挂载 & chroot

    mount --bind /var/cache/apt "${V_CUSTOM_SRC}/var/cache/apt"
    mount --bind /dev "${V_CUSTOM_SRC}/dev/"
    
    chroot "${V_CUSTOM_SRC}/"
    ## 增加辨识
    PS1="(chroot) $PS1"
    LC_ALL=C
    HOME=/root
    export PS1 HOME LC_ALL
    
    mount -t proc none /proc
    mount -t sysfs none /sys
    mount -t devpts none /dev/pts
    mkdir -p /tmp/tools
    
    mv /etc/resolv.conf /etc/resolv.conf.bak
    echo 'nameserver 223.5.5.5' | tee /etc/resolv.conf
    

    基本增删 (chroot)

    ## 替换官方源
    sed -i "s/http:\/\/packages.linuxmint.com/https:\/\/mirrors.tuna.tsinghua.edu.cn\/linuxmint/g" /etc/apt/sources.list.d/official-package-repositories.list
    sed -i "s/http:\/\/archive.ubuntu.com\/ubuntu/https:\/\/mirrors.tuna.tsinghua.edu.cn\/ubuntu/g" /etc/apt/sources.list.d/official-package-repositories.list
    
    apt update
    
    ## Ubuntu Kylin
    apt install ubuntukylin-keyring
    echo "deb http://archive.ubuntukylin.com/ubuntukylin/ focal main" > /etc/apt/sources.list.d/ubuntukylin.list
    
    ## Wine
    dpkg --add-architecture i386
    wget -q -O - https://dl.winehq.org/wine-builds/winehq.key | apt-key add -
    echo "deb https://dl.winehq.org/wine-builds/ubuntu/ focal main" > /etc/apt/sources.list.d/winehq.list
    
    ## Chrome
    wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
    echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list
    
    ## VS Code
    wget -q -O - https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /etc/apt/trusted.gpg.d/microsoft.gpg
    echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list
    
    ## Flatpak
    sudo add-apt-repository ppa:alexlarsson/flatpak
    
    apt update
    
    ## 先移除
    apt purge thunderbird libreoffice-common tomboy hexchat redshift xplayer-common xviewer xed-common
    
    apt install linux-headers-${V_KN_NEW}-generic linux-image-${V_KN_NEW}-generic linux-modules-${V_KN_NEW}-generic linux-modules-extra-${V_KN_NEW}-generic  linux-generic-hwe-20.04
    
    # apt purge linux-headers-${V_KN_OLD}-generic linux-image-${V_KN_OLD}-generic linux-modules-${V_KN_OLD}-generic linux-modules-extra-${V_KN_OLD}-generic
    
    apt dist-upgrade
    apt autoremove
    
    apt install \
      tree \
      vim \
      git \
      openjdk-8-jdk \
      openjdk-11-jdk \
      maven \
      gedit \
      meld \
      code \
      hardinfo \
      autoconf automake libtool \
      firefox-locale-zh-hans \
      google-chrome-stable \
      gimp gimp-help-en \
      mint-meta-codecs \
      vlc \
      flameshot \
      fcitx-ui-classic fcitx-frontend-gtk3 fcitx-frontend-qt5 fcitx-pinyin \
      bcmwl-kernel-source \
      arc-theme \
      fonts-noto-cjk fonts-noto-cjk-extra \
      ttf-mscorefonts-installer \
      openconnect network-manager-openconnect \
      language-pack-zh-hans language-pack-gnome-zh-hans \
      dkms
    
    ## Wine
    apt install --install-recommends winehq-devel
    
    ## 更新 microcode
    apt install intel-microcode amd64-microcode
    
    ## 搜狗输入法 & WPS & 网易云音乐
    wget -O /tmp/sogoupinyin.deb "https://ime.sogoucdn.com/dl/index/1612260778/sogoupinyin_2.4.0.3469_amd64.deb"
    
    wget -O /tmp/wps-office.deb "https://wdl1.cache.wps.cn/wps/download/ep/Linux2019/10161/wps-office_11.1.0.10161_amd64.deb"
    
    wget -O /tmp/netease-cloud-music.deb "http://d1.music.126.net/dmusic/netease-cloud-music_1.2.1_amd64_ubuntu_20190428.deb"
    
    dpkg -i /tmp/sogoupinyin.deb  /tmp/wps-office.deb /tmp/netease-cloud-music.deb
    
    apt install -f
    

    一些增加 (chroot)

    npm & NodeJs

    
    apt install npm 
    npm install npm@latest n -g
    n stable
    

    WPS 缺失的 symbol-fonts, 此处注意授权问题

    cd /tmp
    FONTS_DIR_WPS=/usr/share/fonts/wps-office-symbols
    git clone --depth 1 https://gitee.com/zqq90/wps_linux_fonts.git
    mkdir -p "${FONTS_DIR_WPS}"
    rsync -av --exclude .git --exclude README.md "wps_linux_fonts/" "${FONTS_DIR_WPS}/"
    
    fc-cache -f -v "$FONTS_DIR_WPS"
    

    安装字体: Adobe Source Code Pro

    cd /tmp
    
    V_FONT_HOME=/usr/share/fonts/opentype/adobe-source-code-pro
    mkdir -p $V_FONT_HOME
    wget -P $V_FONT_HOME https://github.com/adobe-fonts/source-code-pro/releases/download/variable-fonts/SourceCodeVariable-Italic.otf
    wget -P $V_FONT_HOME https://github.com/adobe-fonts/source-code-pro/releases/download/variable-fonts/SourceCodeVariable-Roman.otf
    
    fc-cache -f -v "$V_FONT_HOME"
    

    Arc Icons

    cd /tmp/tools
    git clone --depth 1 https://github.com/horst3180/arc-icon-theme.git && cd arc-icon-theme
    ./autogen.sh --prefix=/usr
    make install
    

    For Macbook Touchbar & WiFi

    未经测试,请参考老版:定制 Linux Mint 19.1 镜像

    Deepin Wine

    老方法似乎失效了

    修正首选应用程序

    只是简单替换一下顺序,并不严谨 :-(

    sed -i 's/gimp.desktop;pix.desktop;/pix.desktop;gimp.desktop;/g' /usr/share/applications/mimeinfo.cache
    sed -i 's/gimp.desktop;xreader.desktop;/xreader.desktop;gimp.desktop;/g' /usr/share/applications/mimeinfo.cache
    sed -i 's/vlc.desktop;netease-cloud-music.desktop;/netease-cloud-music.desktop;vlc.desktop;/g' /usr/share/applications/mimeinfo.cache
    sed -i 's/gimp.desktop;pix.desktop;/pix.desktop;gimp.desktop;/g' /usr/share/applications/mimeinfo.cache
    sed -i 's/google-chrome.desktop;firefox.desktop;/firefox.desktop;google-chrome.desktop;/g' /usr/share/applications/mimeinfo.cache
    

    修正网易云音乐启动问题

    参考:https://www.zhihu.com/question/277330447/answer/478510195

    sed -i "s/Exec=netease-cloud-music %U/Exec=sh -c \"unset SESSION_MANAGER \&\& netease-cloud-music %U\"/g" /usr/share/applications/netease-cloud-music.desktop
    

    更新配置

    • 通用配置
    • 可以使用 dconf dump / dump 本机配置作为参考
    mkdir -p /etc/dconf/profile/ /etc/dconf/db/local.d/
    
    # 设置 dconf 配置
    echo "
    # custom dconf, by zqq
    export DCONF_PROFILE=local
    " > /etc/profile.d/50_dconf-local-custom.sh
    
    echo "
    user-db:user
    system-db:local
    " > /etc/dconf/profile/local
    
    echo "
    [org/cinnamon]
    favorite-apps=['firefox.desktop', 'netease-cloud-music.desktop', 'deepin.com.thunderspeed.desktop', 'vlc.desktop', 'deepin.com.weixin.work.desktop', 'gedit.desktop', 'code.desktop', 'meld.desktop', 'gnome-terminal.desktop', 'nemo.desktop', 'gimp.desktop', 'pix.desktop']
    
    [org/cinnamon/desktop/interface]
    font-name='Noto Sans CJK SC 10'
    gtk-theme='Arc'
    icon-theme='Arc'
    
    [org/cinnamon/desktop/keybindings/media-keys]
    terminal=['<Super>t']
    
    [org/cinnamon/desktop/wm/preferences]
    theme='Arc'
    titlebar-font='Noto Sans CJK SC 8'
    
    [org/cinnamon/theme]
    name='Mint-Y-Dark-Aqua'
    
    [org/gnome/desktop/interface]
    document-font-name='Noto Sans CJK SC 11'
    monospace-font-name='Source Code Variable 11'
    
    [org/cinnamon/desktop/keybindings/custom-keybindings/custom0]
    binding=['<Super>Print']
    command='flameshot gui'
    name='Flameshot'
    
    [org/cinnamon/desktop/keybindings]
    custom-list=['custom0']
    
    [org/nemo/preferences]
    show-open-in-terminal-toolbar=true
    show-search-icon-toolbar=false
    default-folder-viewer='list-view'
    date-format='iso'
    show-location-entry=true
    
    [org/nemo/desktop]
    computer-icon-visible=false
    home-icon-visible=false
    font='Noto Sans CJK SC 11'
    
    [org/x/pix/browser]
    thumbnail-list-visible=false
    
    [org/nemo/plugins]
    disabled-actions=['mint-artwork-cinnamon-thunderbird.nemo_action', 'set-as-background.nemo_action', 'send-by-mail.nemo_action', 'change-background.nemo_action']
    
    [org/gnome/terminal/legacy/profiles:]
    list=['b1dcc9dd-5262-4d8d-a863-c897e6d979b9']
    
    [org/gnome/terminal/legacy/profiles:/:b1dcc9dd-5262-4d8d-a863-c897e6d979b9]
    foreground-color='rgb(191,205,207)'
    visible-name='default'
    palette=['rgb(46,52,54)', 'rgb(204,0,0)', 'rgb(78,154,6)', 'rgb(196,160,0)', 'rgb(52,101,164)', 'rgb(117,80,123)', 'rgb(6,152,154)', 'rgb(211,215,207)', 'rgb(85,87,83)', 'rgb(239,41,41)', 'rgb(138,226,52)', 'rgb(252,233,79)', 'rgb(114,159,207)', 'rgb(173,127,168)', 'rgb(52,226,226)', 'rgb(238,238,236)']
    default-size-columns=110
    default-size-rows=32
    use-system-font=false
    use-transparent-background=true
    use-theme-colors=false
    font='Source Code Variable Medium 12'
    use-theme-transparency=false
    background-color='rgb(0,43,54)'
    background-transparency-percent=4
    
    " > /etc/dconf/db/local.d/50_custom_settings
    
    rm /etc/dconf/db/local
    dconf update
    
    • User Dirs
    mkdir -p /etc/skel/.config/ \
      /etc/skel/Desktop/ \
      /etc/skel/downloads/ \
      /etc/skel/.templates/ \
      /etc/skel/documents/ \
      /etc/skel/public/ \
      /etc/skel/music/ \
      /etc/skel/pictures/ \
      /etc/skel/videos/
    
    echo '
    XDG_DESKTOP_DIR="$HOME/Desktop"
    XDG_DOWNLOAD_DIR="$HOME/downloads"
    XDG_TEMPLATES_DIR="$HOME/.templates"
    XDG_DOCUMENTS_DIR="$HOME/documents"
    XDG_PUBLICSHARE_DIR="$HOME/public"
    XDG_MUSIC_DIR="$HOME/music"
    XDG_PICTURES_DIR="$HOME/pictures"
    XDG_VIDEOS_DIR="$HOME/videos"
    ' > /etc/skel/.config/user-dirs.dirs
    
    • 移除部分语言包的依赖

    TODO: 升级可能导致被覆盖

    sed -i "/ibus-table-wubi/d" /usr/share/language-selector/data/pkg_depends
    sed -i "/fcitx-table-wubi/d" /usr/share/language-selector/data/pkg_depends
    sed -i "/fcitx-module-cloudpinyin/d" /usr/share/language-selector/data/pkg_depends
    sed -i "/fcitx-sunpinyin/d" /usr/share/language-selector/data/pkg_depends
    sed -i "/fcitx-table-wubi/d" /usr/share/language-selector/data/pkg_depends
    sed -i "/fonts-arphic-uming/d" /usr/share/language-selector/data/pkg_depends
    sed -i "/fonts-arphic-ukai/d" /usr/share/language-selector/data/pkg_depends
    

    收尾

    重建 initrd

    update-initramfs -u -k $(uname -r)
    mkinitramfs -c lzma -o /tmp/initrd.lz
    

    退出 chroot & 卸载

    dpkg-query -W --showformat='${Package} ${Version}\n' > /tmp/filesystem.manifest
    rm -rf /root/.wget-hsts /var/lib/dbus/machine-id
    mv /etc/resolv.conf.bak /etc/resolv.conf
    
    umount /dev/pts
    umount /sys
    umount /proc
    exit
    
    umount ${V_CUSTOM_SRC}/var/cache/apt
    umount ${V_CUSTOM_SRC}/dev/
    

    更新 Kernel & manifest

    mv ${V_CUSTOM_SRC}/tmp/filesystem.manifest ${V_ISO_SRC}/casper/
    ## 保留 GParted,这么好用的工具怎么能删掉呢
    sed -i '/gparted/d' ${V_ISO_SRC}/casper/filesystem.manifest-remove
    
    rm ${V_CUSTOM_SRC}/boot/initrd.img-${V_KN_NEW}-generic.old-dkms
    cp ${V_CUSTOM_SRC}/tmp/initrd.lz ${V_ISO_SRC}/casper/
    cp ${V_CUSTOM_SRC}/boot/vmlinuz-${V_KN_NEW}-generic ${V_ISO_SRC}/casper/vmlinuz
    

    打包 ISO

    rm -rf ${V_CUSTOM_SRC}/tmp/* \
      ${V_CUSTOM_SRC}/root/.bash_history
    
    rm ${V_ISO_SRC}/casper/filesystem.squashfs
    mksquashfs ${V_CUSTOM_SRC} ${V_ISO_SRC}/casper/filesystem.squashfs
    
    cd ${V_ISO_SRC}
    find -type f -print0 | xargs -0 md5sum | grep -Ev "./MD5SUMS|./isolinux/" > ${V_ISO_SRC}/MD5SUMS
    
    mkisofs -D -r -V "${V_ISO_TITLE}" -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o ${V_ISO_OUT} .
    

    Tips

    • 可以使用 VirtualBox 测试生成的 ISO
    • 不需要 “刻录” 到 U 盘, 强大的 EFI + Grub2 来帮你,硬盘安装就可以
    menuentry "Install LinuxMint ZQQ" {
        set isofile="/boot/iso/linuxmint-20.1-zqq.iso"
        echo "Search $isofile ..."
        search --file $isofile --set=root
        echo "Loopback $isofile ..."
        loopback loop $isofile
        echo "vmlinuz ..."
        linux (loop)/casper/vmlinuz persistent boot=casper iso-scan/filename="$isofile" acpi_osi="Linux" quiet splash locale=zh_CN.UTF-8 noprompt --
        echo "initrd ..."
        initrd (loop)/casper/initrd.lz
    }
    

    参考

    相关文章

      网友评论

          本文标题:[Linux] 定制 Linux Mint 20.2 开发镜像

          本文链接:https://www.haomeiwen.com/subject/kqbumltx.html