mount --rbind /dev dev
mount --rbind /proc proc
mount --rbind /sys sys
mount --rbind /run run
mount --rbind /tmp tmp
chroot . /bin/bash -l
用于在livecd中切换到已经挂载好的根文件系统去执行修复操作。
使用方法(请根据你的磁盘实际情况修改sdx1
和sdx2
):
# 切换到root
sudo -i
# 挂载EFI分区(重要,之前未进行)
mount /dev/sdx1 /boot/efi
# 挂载根文件系统
mount /dev/sdx2 /mnt
# 进入根文件系统
chroot-system /mnt
# 挂载系统需要的其他分区
mount -a
# 查看mount是否成功
mount
# 重建initramfs
update-initramfs -k all -u
# 更新GRUB
update-grub
# 修复并升级软件包
apt install -f
apt update
apt dist-upgrade#!/bin/sh
if [ "$1" = "" ]; then
chroot
exit
fi
cd "$1"
mount --bind /dev dev
mount --bind /dev/pts dev/pts
mount --bind /dev/shm dev/shm
mount --bind /dev/snd dev/snd
mount --bind /proc proc
mount --bind /sys sys
mount --bind /run run
mount --bind /tmp tmp
mount --bind /boot/efi boot/efi
if ! [ -f "etc/resolv.conf" ]; then
rm etc/resolv.conf
touch etc/resolv.conf
fi
mount --bind /etc/resolv.conf etc/resolv.conf
shift
chroot . "$@"
umount etc/resolv.conf boot/efi tmp run sys proc dev/shm dev/pts dev/snd dev
内容,注意创建文件后要给执行权限才能用:
chmod +x /usr/local/bin/chroot-system
#!/bin/sh
if [ "$1" = "" ]; then
chroot
exit
fi
cd "$1"
mount --bind /dev dev
mount --bind /dev/pts dev/pts
mount --bind /dev/shm dev/shm
mount --bind /dev/snd dev/snd
mount --bind /proc proc
mount --bind /sys sys
mount --bind /run run
mount --bind /tmp tmp
mount --bind /boot/efi boot/efi
if ! [ -f "etc/resolv.conf" ]; then
rm etc/resolv.conf
touch etc/resolv.conf
fi
mount --bind /etc/resolv.conf etc/resolv.conf
shift
chroot . "$@"
umount etc/resolv.conf boot/efi tmp run sys proc dev/shm dev/pts dev/snd dev
https://wiki.archlinux.org/index.php/Systemd-nspawn_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)