13.5. 移除旧磁盘

假设你有一块旧的 IDE 硬盘在 /dev/hdb 上。你想移除这块旧磁盘,但是上面有很多文件。

Caution备份你的系统
 

在尝试 pvmove 操作之前,你应该始终备份你的系统。

13.5.1. 将旧盘区分配到卷组中现有的磁盘

如果你的卷组中其他磁盘上有足够的空闲盘区,那就很容易了。只需运行

# pvmove /dev/hdb
pvmove -- moving physical extents in active volume group "dev"
pvmove -- WARNING: moving of active logical volumes may cause data loss!
pvmove -- do you want to continue? [y/n] y
pvmove -- 249 extents of physical volume "/dev/hdb" successfully moved
          
这将把已分配的物理盘区从 /dev/hdb 移动到卷组中的其余磁盘上。

Notepvmove 命令速度很慢
 

请注意,pvmove 命令非常慢,因为它必须将磁盘的内容逐块复制到一个或多个磁盘。如果你想要来自 pvmove 命令更稳定的状态报告,请使用-v标志。

13.5.1.1. 移除未使用的磁盘

现在我们可以从卷组中移除旧的 IDE 磁盘。

# vgreduce dev /dev/hdb
vgreduce -- doing automatic backup of volume group "dev"
vgreduce -- volume group "dev" successfully reduced by physical volume:
vgreduce -- /dev/hdb
            
现在,当机器下次关机时,驱动器可以被物理移除,或者重新分配给其他用户。

13.5.2. 将旧盘区分配到新的替换磁盘

如果你没有足够的空闲物理盘区来分配旧的物理盘区,你将不得不向卷组添加一块磁盘并将盘区移动到它上面。

13.5.2.1. 准备磁盘

首先,你需要 pvcreate 新磁盘,使其可用于 LVM。在这个技巧中,我们展示了你不需要分区磁盘也能使用它。

# pvcreate /dev/sdf
pvcreate -- physical volume "/dev/sdf" successfully created
            

13.5.2.2. 将其添加到卷组

由于开发人员使用大量的磁盘空间,这是一个很好的卷组来添加它。

# vgextend dev /dev/sdf
vgextend -- INFO: maximum logical volume size is 255.99 Gigabyte
vgextend -- doing automatic backup of volume group "dev"
vgextend -- volume group "dev" successfully extended
            

13.5.2.3. 移动数据

接下来,我们将数据从旧磁盘移动到新磁盘上。请注意,在执行此操作之前没有必要卸载文件系统。尽管 *强烈* 建议你在尝试此操作之前进行完整备份,以防断电或某些其他可能中断它的问题。 pvmove 命令可能需要相当长的时间才能完成,并且它还会对两个卷产生性能影响,所以,虽然不是必须的,但建议在卷不太繁忙时执行此操作。

# pvmove /dev/hdb /dev/sdf
pvmove -- moving physical extents in active volume group "dev"
pvmove -- WARNING: moving of active logical volumes may cause data loss!
pvmove -- do you want to continue? [y/n] y
pvmove -- 249 extents of physical volume "/dev/hdb" successfully moved
            

13.5.2.4. 移除未使用的磁盘

现在我们可以从卷组中移除旧的 IDE 磁盘。

# vgreduce dev /dev/hdb
vgreduce -- doing automatic backup of volume group "dev"
vgreduce -- volume group "dev" successfully reduced by physical volume:
vgreduce -- /dev/hdb
            
现在,当机器下次关机时,驱动器可以被物理移除,或者重新分配给其他用户。