更换大量小文件的硬盘时,最快速的复制方案
硬盘不够用了,里面在大量的小文件,cp或rsync都非常慢。
开始又没有做LVM,现在要拿两个大硬盘做LVM,去换这个硬盘。
怎么COPY数据是最快的?
我的想法是用DD:
比如现在的硬盘是73G的,/dev/sdb1
拿两块147的做LVM,/dev/mapper/VolGroup00-LogVol01
我现在:
dd if=/dev/sdb1 of=/dev/mapper/VolGroup00-LogVol01
这样是否可行?
/dev/mapper/VolGroup00-LogVol01比/dev/sdb1
大,会不会有问题?
下面是操作步骤,测试结果说明方案可行:
有三块硬盘:
fdisk -l
Disk /dev/sdb: 1073 MB, 1073741824 bytes
Disk /dev/sdc: 1610 MB, 1610612736 bytes
Disk /dev/sdd: 2147 MB, 2147483648 bytes
先分区:
/dev/sdb1为linux分区。 /dev/sdc1和/dev/sdd为linux lvm分区。
格式化并复制一些测试文件进去
mkfs -t ext3 /dev/sdb1
mkdir /sdb1
mount /dev/sdb1 /sdb1
cp -rf /* /sdb1
磁盘占用:
[root@rhel4 /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 6.8G 1.9G 4.7G 28% /
/dev/sda1 99M 12M 82M 13% /boot
none 252M 0 252M 0% /dev/shm
/dev/sdb1 1004M 1004M 0 100% /sdb1
建立lvm:
[root@rhel4 /]# pvcreate /dev/sdc1
Physical volume “/dev/sdc1” successfully created
[root@rhel4 /]# pvcreate /dev/sdd1
Physical volume “/dev/sdd1” successfully created
[root@rhel4 /]# vgcreate vg1 /dev/sdc1 /dev/sdd1
/dev/cdrom: open failed: No medium found
Volume group “vg1” successfully created
[root@rhel4 /]# vgdisplay
— Volume group —
VG Name vg1
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 3.49 GB
PE Size 4.00 MB
Total PE 893
Alloc PE / Size 0 / 0
Free PE / Size 893 / 3.49 GB
VG UUID sE9vmk-Kuma-ITAI-irkv-qyey-G1cl-mVilAy
[root@rhel4 /]# lvcreate -L 3.48G -n lv1 vg1
Rounding up size to full physical extent 3.48 GB
Logical volume “lv1” created
[root@rhel4 /]# lvdisplay
— Logical volume —
LV Name /dev/vg1/lv1
VG Name vg1
LV UUID 8zkO0q-mmYv-Km4y-aw4q-5BAw-H7hI-cKtrK7
LV Write Access read/write
LV Status available
# open 0
LV Size 3.48 GB
Current LE 891
Segments 2
Allocation inherit
Read ahead sectors 0
Block device 253:0
建立文件系统:
[root@rhel4 /]# mkfs -t ext3 /dev/vg1/lv1
[root@rhel4 /]# mkdir /lv1
[root@rhel4 /]# mount /dev/vg1/lv1 /lv1
[root@rhel4 /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 6.8G 1.9G 4.7G 28% /
/dev/sda1 99M 12M 82M 13% /boot
none 252M 0 252M 0% /dev/shm
/dev/sdb1 1004M 1004M 0 100% /sdb1
/dev/mapper/vg1-lv1 3.5G 39M 3.3G 2% /lv1
卸下/dev/sdb1 及/dev/mapper/vg1-lv1:
[root@rhel4 /]# umount /dev/sdb1
[root@rhel4 /]# umount /dev/mapper/vg1-lv1
把/dev/sdb1复制到/dev/mapper/vg1-lv1:
[root@rhel4 /]# dd if=/dev/sdb1 of=/dev/mapper/vg1-lv1 bs=8MB
133+1 records in
133+1 records out
bs是块大小,这里是8MB,块越大速度越快,只要内存够用。这里花了30秒就跑完了。测试在vmware进行,内存是512M
挂上LVM,看下:
[root@rhel4 /]# mount /dev/mapper/vg1-lv1 /lv1
[root@rhel4 /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 6.8G 1.9G 4.7G 28% /
/dev/sda1 99M 12M 82M 13% /boot
none 252M 0 252M 0% /dev/shm
/dev/mapper/vg1-lv1 1004M 1004M 0 100% /lv1
[root@rhel4 /]# ls /lv1/
bin boot dev etc home initrd lib lost+found media misc mnt opt proc usr
里面内容都在。就是最大容量也变成和/dev/sdb1一样了,我们需要扩展一下:
RHEL 4:
ext2online /dev/mapper/vg1-lv1
RHEL 5:
resize2fs -p /dev/mapper/vg1-lv1
[root@rhel4 /]# ext2online /dev/mapper/vg1-lv1
ext2online v1.1.18 - 2001/03/18 for EXT2FS 0.5b
[root@rhel4 /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 6.8G 1.9G 4.7G 28% /
/dev/sda1 99M 12M 82M 13% /boot
none 252M 0 252M 0% /dev/shm
/dev/mapper/vg1-lv1 3.5G 1005M 2.3G 31% /lv1
OK,完成复制。以上在centos4及centos 5上测试通过