root@xxx:~# pvcreate /dev/vdb Can't initialize physical volume "/dev/vdb" of volume group "vg_root" without -ff /dev/vdb: physical volume not initialized.
3.在卷组中创建逻辑卷
1
lvcreate -l 100%FREE -n lv_root vg_root
期望输出
1 2 3 4
root@xxx:~# lvcreate -l 100%FREE -n lv_root vg_root WARNING: ext4 signature detected on /dev/vg_root/lv_root at offset 1080. Wipe it? [y/n]: y Wiping ext4 signature on /dev/vg_root/lv_root. Logical volume "lv_root" created.
# /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # systemd generates mount units based on this file, see systemd.mount(5). # Please run 'systemctl daemon-reload' after making changes here. # # <file system> <mount point> <type> <options> <dump> <pass> # / was on /dev/vda1 during installation UUID=63dc08fe-cf76-4097-b849-c9db03ce9b84 / ext4 errors=remount-ro 01 # swap was on /dev/vda5 during installation UUID=155c5478-3b21-4c5c-ab1d-5bc39961d1b7 none swap sw 00 /dev/sr0 /media/cdrom0 udf,iso9660 user,noauto 0 0
# /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # systemd generates mount units based on this file, see systemd.mount(5). # Please run 'systemctl daemon-reload' after making changes here. # # <file system> <mount point> <type> <options> <dump> <pass> # / was on /dev/vda1 during installation UUID=a8a07510-2b4c-4ac7-8524-cafcb4393283 / ext4 errors=remount-ro 01 # swap was on /dev/vda5 during installation UUID=155c5478-3b21-4c5c-ab1d-5bc39961d1b7 none swap sw 00 /dev/sr0 /media/cdrom0 udf,iso9660 user,noauto 0 0
6.挂载此逻辑卷并将原根目录同步到此卷
1 2
mount /dev/mapper/vg_root-lv_root /mnt rsync -axHAWX --numeric-ids --info=progress2 / /mnt
mount --types proc /proc /mnt/proc mount --rbind /sys /mnt/sys mount --make-rslave /mnt/sys mount --rbind /dev /mnt/dev mount --make-rslave /mnt/dev mount --rbind /run /mnt/run mount --bind /etc/resolv.conf /mnt/etc/resolv.conf
8.chroot到新的根目录并更新grub和initramfs
1 2 3 4
chroot /mnt grub-install /dev/vda update-grub update-initramfs -u -k all
期望输出
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
root@xxx:~# chroot /mnt root@xxx:/# grub-install /dev/vda Installing for i386-pc platform. Installation finished. No error reported.
root@xxx:/# update-grub Generating grub configuration file ... Found linux image: /boot/vmlinuz-6.1.0-18-amd64 Found initrd image: /boot/initrd.img-6.1.0-18-amd64 Warning: os-prober will not be executed to detect other bootable partitions. Systems on them will not be added to the GRUB boot configuration. Check GRUB_DISABLE_OS_PROBER documentation entry. done
root@xxx:/# update-initramfs -u -k all update-initramfs: Generating /boot/initrd.img-6.1.0-18-amd64