导语
我们都知道使用lv逻辑卷可以方便的扩容。 但是当原盘不是逻辑卷且其上有数据的时候,如何扩容呢? 因为扩容只能是磁盘type为逻辑卷lvm才可以。 那么将有数据的盘直接pvcreate为虚拟卷lvm以后,是否对数据有损害? 我们今天就来测试一下。
添加硬盘
- 虚拟机添加一个5G的磁盘作为实验用
查看当前分区情况
lsblk
[root@C8-196 ~]
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 199G 0 part
├─cl-root 253:0 0 70G 0 lvm /
├─cl-swap 253:1 0 2G 0 lvm [SWAP]
└─cl-home 253:2 0 127G 0 lvm /home
sdb 8:16 0 5G 0 disk
使用传统方式分区
fdisk /dev/sdb
[root@C8-196 ~]
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x53b270c9.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-10485759, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-10485759, default 10485759):
Created a new partition 1 of type 'Linux' and of size 5 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
- 再次查看分区情况,sdb被分成了一个主分区,TYPE为part,大小为5G
[root@C8-196 ~]
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 199G 0 part
├─cl-root 253:0 0 70G 0 lvm /
├─cl-swap 253:1 0 2G 0 lvm [SWAP]
└─cl-home 253:2 0 127G 0 lvm /home
sdb 8:16 0 5G 0 disk
└─sdb1 8:17 0 5G 0 part
在新创建的分区上创建文件系统
[root@C8-196 ~]
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=327616 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=1310464, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
创建挂载点并挂载新建分区
[root@C8-196 ~]
mkdir: created directory '/data'
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 876M 0 876M 0% /dev
tmpfs tmpfs 896M 0 896M 0% /dev/shm
tmpfs tmpfs 896M 17M 879M 2% /run
tmpfs tmpfs 896M 0 896M 0% /sys/fs/cgroup
/dev/mapper/cl-root xfs 70G 2.3G 68G 4% /
/dev/mapper/cl-home xfs 127G 939M 126G 1% /home
/dev/sda1 xfs 1014M 197M 818M 20% /boot
tmpfs tmpfs 180M 0 180M 0% /run/user/0
/dev/sdb1 xfs 5.0G 68M 5.0G 2% /data
创建测试文件在新建磁盘分区上
- 写100个文件到磁盘上做数据测试
for i in {1..100};do $(time dd if=/dev/zero of=/data/testw$i.db bs=4k count=10000);done&&ll /data&&df -Th
[root@C8-196 ~]
10000+0 records in
10000+0 records out
40960000 bytes (41 MB, 39 MiB) copied, 0.0162844 s, 2.5 GB/s
real 0m0.016s
user 0m0.002s
sys 0m0.014s
10000+0 records in
10000+0 records out
40960000 bytes (41 MB, 39 MiB) copied, 0.0153671 s, 2.7 GB/s
real 0m0.017s
user 0m0.001s
sys 0m0.015s
total 4000000
-rw-r--r-- 1 root root 40960000 Mar 2 21:15 testw100.db
-rw-r--r-- 1 root root 40960000 Mar 2 21:15 testw10.db
-rw-r--r-- 1 root root 40960000 Mar 2 21:15 testw11.db
-rw-r--r-- 1 root root 40960000 Mar 2 21:15 testw99.db
-rw-r--r-- 1 root root 40960000 Mar 2 21:15 testw9.db
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 876M 0 876M 0% /dev
tmpfs tmpfs 896M 0 896M 0% /dev/shm
tmpfs tmpfs 896M 17M 879M 2% /run
tmpfs tmpfs 896M 0 896M 0% /sys/fs/cgroup
/dev/mapper/cl-root xfs 70G 2.3G 68G 4% /
/dev/mapper/cl-home xfs 127G 939M 126G 1% /home
/dev/sda1 xfs 1014M 197M 818M 20% /boot
tmpfs tmpfs 180M 0 180M 0% /run/user/0
/dev/sdb1 xfs 5.0G 3.9G 1.2G 78% /data
直接对有数据的分区做pvcreate
- 很显然,处于安全考虑,已经mount的分区不能直接pvcreate
[root@C8-196 ~]
[root@C8-196 ~]
pvcreate is /usr/sbin/pvcreate
[root@C8-196 ~]
Can't open /dev/sdb1 exclusively. Mounted filesystem?
Can't open /dev/sdb1 exclusively. Mounted filesystem?
umount以后再次pvcreate
- umount掉以后做pvcreate居然成功了,虽然提示了有xfs文件系统在分区上
[root@C8-196 ~]
[root@C8-196 ~]
WARNING: xfs signature detected on /dev/sdb1 at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/sdb1.
Physical volume "/dev/sdb1" successfully created.
创建逻辑卷
[root@C8-196 ~]
Volume group "vg_data" successfully created
[root@C8-196 ~]
Logical volume "data_lv" created.
[root@C8-196 ~]
PV VG Fmt Attr PSize PFree
/dev/sda2 cl lvm2 a-- <199.00g 0
/dev/sdb1 vg_data lvm2 a-- <5.00g 0
VG
cl 1 3 0 wz--n- <199.00g 0
vg_data 1 1 0 wz--n- <5.00g 0
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home cl -wi-ao---- 126.96g
root cl -wi-ao---- 70.00g
swap cl -wi-ao---- 2.03g
data_lv vg_data -wi-a----- <5.00g
再次尝试挂载/dev/sdb1
[root@C8-196 ~]
mount: /data: unknown filesystem type 'LVM2_member'.
尝试直接挂载新创建的lvm逻辑卷
[root@C8-196 ~]
lrwxrwxrwx 1 root root 7 Mar 2 21:28 /dev/mapper/vg_data-data_lv -> ../dm-3
[root@C8-196 ~]
total 0
lrwxrwxrwx 1 root root 7 Mar 2 21:28 data_lv -> ../dm-3
[root@C8-196 ~]
mount: /data: wrong fs type, bad option, bad superblock on /dev/mapper/vg_data-data_lv, missing codepage or helper program, or other error.
[root@C8-196 ~]
mount: /data: wrong fs type, bad option, bad superblock on /dev/mapper/vg_data-data_lv, missing codepage or helper program, or other error.
在新逻辑卷上创建文件系统
[root@C8-196 ~]
meta-data=/dev/mapper/vg_data-data_lv isize=512 agcount=4, agsize=327424 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=1309696, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
挂载逻辑卷到曾经的data目录
mount /dev/mapper/vg_data-data_lv /data
[root@C8-196 ~]
[root@C8-196 ~]
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 876M 0 876M 0% /dev
tmpfs tmpfs 896M 0 896M 0% /dev/shm
tmpfs tmpfs 896M 17M 879M 2% /run
tmpfs tmpfs 896M 0 896M 0% /sys/fs/cgroup
/dev/mapper/cl-root xfs 70G 2.3G 68G 4% /
/dev/mapper/cl-home xfs 127G 939M 126G 1% /home
/dev/sda1 xfs 1014M 197M 818M 20% /boot
tmpfs tmpfs 180M 0 180M 0% /run/user/0
/dev/mapper/vg_data-data_lv xfs 5.0G 68M 5.0G 2% /data
查看目录下是否有文件
/dev/mapper/vg_data-data_lv xfs 5.0G 68M 5.0G 2% /data
[root@C8-196 ~]
total 0
- 很显然,毛线都没有了。
- 这目录下要是有生产数据,你就可以走人了!
- 又是一种删库跑路的新方法!
结论
- 使用pvcreate对已经挂载的分区不能直接创建pv
- 使用pvcreate对有数据且已解挂载的分区可以直接创建pv,会提示文件系统存在
使用pvcreate对有数据的分区创建pv会摧毁文件系统,文件就无啦~
使用pvcreate对有数据的分区创建pv会摧毁文件系统,文件就无啦~
使用pvcreate对有数据的分区创建pv会摧毁文件系统,文件就无啦~
|