我有下一个分区:
/dev/sda1 → /boot
/dev/sda2 → LUKS → LVM
/dev/vg1/root → /
/dev/vg1/home → /home
/dev/vg1/opt → /opt
/dev/vg1/var → /var
/dev/vg1/tmp → /tmp
/dev/vg1/swap → swap
/dev/sdb1 - SSD disk, currently not in use
我得到了一个 SSD 驱动器。已经使用以下命令将所有内容从“/”(使用 LVM 快照)复制到 SSD“/dev/sdb1”
cp -ax …
命令。
那么,如何才能让“/dev/sdb1”在操作系统启动期间成为根目录,并在需要时可以恢复到旧根目录?
答案1
对于问题描述的情况,我使用了脚本。您需要将数据复制到 SSD 并在那里更改 /etc/fstab。
#!/bin/bash
# Stop script on single error
set -e
# Script must be run from root user
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
# Temporary mount point for guest root
MountDir="/media/root"
# Create mount point if not exist
if [ ! -d "$MountDir" ]; then
mkdir -p "$MountDir"
fi
# Set ownership
chown root:root "$MountDir"
# Mount guest root (change for your system)
mount /dev/sdb1 "$MountDir"
# Mount other paritions (change for your system)
mount /dev/sda1 "${MountDir}/boot"
mount /dev/mapper/vg1-var "${MountDir}/var"
mount /dev/mapper/vg1-opt "${MountDir}/opt"
mount /dev/mapper/vg1-tmp "${MountDir}/tmp"
mount /dev/mapper/vg1-home "${MountDir}/home"
# Mount some system in-memory directories for correct operation of guest system
mount -B /proc "${MountDir}/proc"
mount -B /dev "${MountDir}/dev"
mount -B /sys "${MountDir}/sys"
# Enter to guest root and run commands to update OS boot configuration
chroot "$MountDir" /bin/bash -c "update-initramfs -u; update-grub"
# Unmount partitions (change for your system)
umount "${MountDir}/boot"
umount "${MountDir}/var"
umount "${MountDir}/opt"
umount "${MountDir}/tmp"
umount "${MountDir}/home"
# Unmount in-memory directories
umount "${MountDir}/proc"
umount "${MountDir}/dev"
umount "${MountDir}/sys"
# Unmount guest root
umount "$MountDir"
这基本上是从其他答案中写出来的:
https://askubuntu.com/a/118928/27255- 复制
https://askubuntu.com/a/3409/27255——但还udpate-grub
不够,你需要先跑update-initramfs -u
……