运行未对齐磁盘分区的系统,需要在不丢失所有分区(包括 mbr)上数据的情况下进行对齐,并且停机时间最短甚至无停机时间。
答案1
创建新的对齐分区
DISK=/dev/sdd(假设新磁盘指向sdd)
dd if=/dev/zero of=$DISK count=1 bs=1M
parted -s -- $DISK mklabel msdos
parted -s -- $DISK mkpart primary ext3 64s 401624s
parted -s -- $DISK mkpart primary 401628s 6144866s
parted -s -- $DISK mkpart primary 6144868s 100%
parted $DISK unit s print
(echo t; echo 1; echo 83;echo t; echo 2; echo 82;echo t; echo 3; echo 8e; echo w) | fdisk $DISK
(echo a; echo 1; echo w) | fdisk $DISK
安装GRUB:
mkfs –t ext3 –L /boot dev/sdd1
mount $DSIK1 /mnt
cd /mnt
dump -0 -b 1024 -f - /boot/ | restore -r -f - -b 1024
cd /
umount /mnt
幼虫:
grub> device (hd1) /dev/sdd
device (hd1) /dev/sdd
grub>root (hd1,0)
root (hd1,0)
Filesystem type is ext2fs, partition type 0x83
grub> setup (hd1)
setup (hd1)
Checking if "/boot/grub/stage1" exists... no
Checking if "/grub/stage1" exists... yes
Checking if "/grub/stage2" exists... yes
Checking if "/grub/e2fs_stage1_5" exists... yes
Running "embed /grub/e2fs_stage1_5 (hd1)"... 15 sectors are embedded.
succeeded
Running "install /grub/stage1 (hd1) (hd1)1+15 p (hd1,0)/grub/stage2 /grub/grub.conf"...
succeeded
Done.
grub> quit
将新磁盘添加到 LVM:
pvcreate /dev/sdd3
将 sdd 扩展到 myvg lvm 组:
vgextend /dev/myvg /dev/sdd
将数据移动到新磁盘(假设旧磁盘指向 sda):
pvmove –verbose /dev/sda3 /dev/sdd3
如果还有其他分区可以合并为单个分区:
pvmove –verbose /dev/sdd1 /dev/sdd3
删除旧的 LVM:
vgreduce /dev/myvg /dev/sda3
vgreduce /dev/myvg /dev/sda1
pvremove /dev/sda1
pvremove /dev/sda3
请注意,不需要立即重新启动系统。您可能需要确认重新启动以确保在删除未对齐的磁盘后启动。