将根目录从 LVM 移至标准 ext4 分区

将根目录从 LVM 移至标准 ext4 分区

我在一台装有 Ubuntu 18.04LTS 的服务器上,LVM 分区中有单个磁盘。启动分区是 ext2 ,根分区是 ext4 ,位于卷组 beta-root 中(如下所示)

Filesystem             Size  Used Avail Use% Mounted on
udev                   3.9G     0  3.9G   0% /dev
tmpfs                  798M  3.3M  795M   1% /run
/dev/mapper/beta-root  293G  129G  152G  46% /
tmpfs                  3.9G     0  3.9G   0% /dev/shm
tmpfs                  5.0M     0  5.0M   0% /run/lock
tmpfs                  3.9G     0  3.9G   0% /sys/fs/cgroup
tmpfs                  512M     0  512M   0% /clam-tmp
/dev/sda1              228M  111M  106M  52% /boot
tmpfs                  798M     0  798M   0% /run/user/1001
tmpfs                  798M     0  798M   0% /run/user/0


Disk /dev/sda: 300 GiB, 322122547200 bytes, 629145600 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x000456c7

Device     Boot     Start       End   Sectors  Size Id Type
/dev/sda1  *         2048    499711    497664  243M 83 Linux
/dev/sda2          501758 125827071 125325314 59.8G  5 Extended
/dev/sda3       125827072 629145599 503318528  240G 8e Linux LVM
/dev/sda5          501760 125827071 125325312 59.8G 8e Linux LVM

# /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).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    nodev,noexec,nosuid 0       0
/dev/mapper/beta-root /               ext4    errors=remount-ro,acl 0       1
# /boot was on /dev/sda1 during installation
UUID=9b35bbcc-61f6-410a-bc43-f06516bfedd6 /boot           ext2    defaults        0       2
/dev/mapper/beta-swap_1 none            swap    sw              0       0

tmpfs   /dev/shm        tmpfs   defaults,noexec,nosuid  0       0

tmpfs /clam-tmp tmpfs defaults,noatime,nosuid,nodev,noexec,mode=1777,size=512M 0 0

是否有一种可以理解的方法可以将整个系统从混合环境(LVM 和非 LVM)迁移到具有相同布局但根本没有 LVM 的新硬盘(假设为 /dev/sdb)?

感谢你的支持!

答案1

简而言之,我要遵循的步骤如下:

  1. 从启动直播USB
  2. 安装启动修复

    sudo add-apt-repository ppa:yannubuntu/boot-repair
    sudo apt-get update
    sudo apt-get install -y boot-repair
    
  3. 按照说明安装并挂载 LVM 驱动器这里

    sudo apt-get install software-properties-common
    sudo apt-get install lvm2   #This step may or may not be required.
    sudo pvscan                 #Use this to verify your LVM partition(s) is/are detected.
    sudo vgscan                 #Scans for LVM Volume Group(s)
    sudo vgchange -ay           #Activates LVM Volume Group(s)
    sudo lvscan                 #Scans for available Logical Volumes
    sudo mount /dev/YourVolGroup00/YourLogVol00 /YourMountPoint
    
  4. 安装要移动数据的驱动器

  5. 将数据从旧驱动器复制到新驱动器:

    复制启动分区:

    sudo dd if=/dev/sda1 of=/dev/sdb1 bs=4096 
    

    复制根分区:¹

    sudo dd if=/dev/beta/root | pv -s 300G | dd of=/dev/sdb2 bs=4096
    
  6. 在新驱动器上运行 Boot-Repair

    sudo boot-repair
    
  7. 重启

注1:这可能需要非常很久。

相关内容