
实验目的:
测试在老版本的Linux上摘掉LVM管理的磁盘,然后挂载到新版本的主机上,数据是否仍然可用。
测试环境:
VMware Workstation 11 64-bit
系统版本:
源主机:Red Hat Enterprise Linux Server release 5.7 x86_64
目的主机:CentOS Linux release 7.0.1406 (Core) x86_64
测试流程:
1.在源主机创建LVM管理的VG、LV和文件系统并挂载,创建文件并添加内容;
2.备份VG信息,然后摘掉VG;
3.在目的主机挂载磁盘,扫描硬件;
3.挂载VG,检查VG、LV状态;
4.挂载文件系统;
5.验证文件系统功能。
操作过程:
在源主机上创建LVM的相关资源:
打开虚拟机的配置,选中“硬盘”,点击下方的“添加”:
添加硬件类型选择“硬盘”:
选择创建新虚拟磁盘:
创建容量为0.5G,保存为单个文件,方便复制,简化操作:
磁盘命名为 “disk4test.vmdk”:
点击完成后即刻创建磁盘了:
随后便可看到虚拟机配置信息里有新分配的硬盘信息:
系统里可以看到认到了新的设备信息:
root@dbserver ~]# fdisk -l
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 3916 31350847+ 8e Linux LVM
Disk /dev/sdb: 536 MB, 536870912 bytes
64 heads, 32 sectors/track, 512 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Disk /dev/sdb doesn't contain a valid partition table
创建PV:
[root@dbserver ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created
查看PV信息,当然也可以用pvs和pvdisplay等命令查看相关信息:
PV /dev/sda2 VG VolGroup00 lvm2 [29.88 GB / 0 free]
PV /dev/sdb lvm2 [512.00 MB]
Total: 2 [30.38 GB] / in use: 1 [29.88 GB] / in no VG: 1 [512.00 MB]
创建VG:
[root@dbserver ~]# vgcreate mail /dev/sdb
Volume group "mail" successfully created
查看VG信息,同样也可以用vgs和vgdisplay等命令查看相关信息:
[root@dbserver ~]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "mail" using metadata type lvm2
Found volume group "VolGroup00" using metadata type lvm2
创建LV:
[root@dbserver ~]# lvcreate -L 500M -n MAILlv mail
Logical volume "MAILlv" created
查看LV信息,同上,也可以用那3种命令查看更多信息:
ACTIVE '/dev/mail/MAILlv' [500.00 MB] inherit
ACTIVE '/dev/VolGroup00/LogVol00' [25.97 GB] inherit
ACTIVE '/dev/VolGroup00/LogVol01' [3.91 GB] inherit
创建文件系统:
root@dbserver ~]# mkfs -t ext3 /dev/mail/MAILlv
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
128016 inodes, 512000 blocks
25600 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
63 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
创建挂载点并挂载文件系统:
[root@dbserver /]# mkdir mail
[root@dbserver /]# mount /dev/mail/MAILlv /mail
确认文件系统状态:
[root@dbserver /]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVol00
26G 20G 4.5G 82% /
/dev/sda1 99M 21M 73M 23% /boot
tmpfs 1.3G 248M 1.1G 19% /dev/shm
none 1.3G 104K 1.3G 1% /var/lib/xenstored
/dev/mapper/mail-MAILlv 485M 11M 449M 3% /mail
进入/mail创建测试文件:
[root@dbserver mail]# touch test_moving
[root@dbserver mail]# vi test_moving
[root@dbserver mail]# cat test_moving
This is a testing file for moving storage.
迁移存储:
生产环境上的话,任何操作都要注意细节,都要注意事先想好下一步的思路和回退的方案,备份终于泰山,对客户负责、对项目负责也要对公司负责。
备份VG信息:
[root@dbserver /]# vgcfgbackup mail
Volume group "mail" successfully backed up.
确认信息已经备份,并记住备份位置:
[root@dbserver backup]# ls -lt
总计 12
-rw------- 1 root root 1166 08-01 12:25 mail
-rw------- 1 root root 1539 2013-07-07 VolGroup00
[root@dbserver backup]# pwd
/etc/lvm/backup
-an参数的含义是:deactivate
[root@dbserver /]# lvchange -an /dev/mail/MAILlv
[root@dbserver /]# vgchange -an mail
0 logical volume(s) in volume group "mail" now active
摘掉mail VG:
[root@dbserver /]# vgexport mail
Volume group "mail" successfully exported
接下来关闭源主机,可以把文件拷贝到目的主机文件夹下也可以是任何地方,也可以不动,我直接复制到了上层文件夹。
接下来需要在目的主机上识别设备:
打开目的主机的配置菜单:
根据图示往下走即可:
直到在配置里看到新的硬盘就可以。
接下来启动虚拟机进入系统(或重启系统),检查硬件信息是否已更新:
[root@cafe ~]# fdisk -l
磁盘 /dev/sda:64.4 GB, 64424509440 字节,125829120 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0009cfc6
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 125829119 62401536 8e Linux LVM
磁盘 /dev/sdb:536 MB, 536870912 字节,1048576 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-swap:2181 MB, 2181038080 字节,4259840 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-root:41.5 GB, 41469083648 字节,80994304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/mail-MAILlv:524 MB, 524288000 字节,1024000 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-home:20.2 GB, 20245905408 字节,39542784 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
导入VG信息:
[root@cafe ~]# vgimport mail
Volume group "mail" successfully imported
[root@cafe ~]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "mail" using metadata type lvm2
Found volume group "centos" using metadata type lvm2
查看LV信息是否已更新,同样也可以用 **s、**scan和**display命令查看:
[root@cafe ~]# lvscan
ACTIVE '/dev/mail/MAILlv' [500.00 MiB] inherit
ACTIVE '/dev/centos/swap' [2.03 GiB] inherit
ACTIVE '/dev/centos/home' [18.86 GiB] inherit
ACTIVE '/dev/centos/root' [38.62 GiB] inherit
创建挂载点,并挂载文件系统:
[root@cafe ~]# cd /
[root@cafe /]# mkdir mail
[root@cafe /]# mount /dev/mail/MAILlv /mail
验证数据可用:
[root@cafe /]# cd mail
[root@cafe mail]# ls
lost+found test_moving
[root@cafe mail]# cat test_moving
This is a testing file for moving storage.
测试磁盘的基本功能:
复制:
[root@cafe mail]# cp test_moving.bak test_moving
删除:
[root@cafe mail]# rm -f test_moving.bak
[root@cafe mail]# ls -lt
总用量 14
-rw-r--r-- 1 root root 43 9月 18 15:00 test_moving
-rw-r--r-- 1 root root 6 9月 18 14:59 check
drwx------ 2 root root 12288 8月 1 12:12 lost+found
读取:
[root@cafe mail]# cat test_moving
This is a testing file for moving storage.
写入:
[root@cafe mail]#vi check
[root@cafe mail]# cat check
OK!~
激活操作如下:
[root@cafe /]# vgchange -ay mail
1 logical volume(s) in volume group "mail" now active
[root@cafe /]# lvchange -ay /dev/mail/MAILlv
[root@cafe /]#