Skip to content

不格式化的 Ubuntu 系统重装

准备一个 ubuntu iso 镜像,从 BIOS 通过该镜像启动。

  1. 新建一个目录(如 /t),将原来的 rootfs 盘挂载到该目录

  2. cd /t,将失效系统软链接与 /tmp 文件删除,新建一个目录 /t/oldroot,将 /t 中除了 oldroot/lost+found/ 的目录都移进 /t/oldroot/

  3. 修改 /etc/apt/source.list.d/ubuntu.sources 文件,替换源为国内镜像源(如 mirrors.ustc.edu.cn,然后 apt update

  4. apt install debootstrap arch-install-scripts

  5. debootstrap noble /t http::/mirrors.ustc.edu.cn/ubuntu,然后 /t 下就有了新的 rootfs

  6. arch-chroot /t 进入新装的系统中

  7. 将原系统中的 /boot/boot/efi 所在的分区挂载到新系统的 /boot/boot/efi

    • 在重启之前应该注意分区名是什么,如果忘记看了,可以通过大小估计(一般最小的那个是 /boot/efi,次小的是 /boot),或者通过 /oldrootfs/etc/fstab 文件查看
  8. apt install vimvim /etc/apt/sources.list

    查看镜像站

  9. apt update

  10. apt-mark hold snapd

  11. apt install ubuntu-minimal ubuntu-standard ubuntu-server linux-generic grub-efi-amd64 bash-completion command-not-found ssh

  12. 加公钥,捞配置

    • /etc/fstab :NFS 暂时注释掉
    • /etc/netplan/*
    • /etc/ssh/ssh_host_* /etc/ssh/sshd_config.d/* systemctl enable sshd
    • /etc/passwd 暂时把 root 的密码删掉,以防配置错误进不了 root,进入后立即加回去