导语
我们都知道使用lv逻辑卷可以方便的扩容。 但是当原盘不是逻辑卷且其上有数据的时候,如何扩容呢? 因为扩容只能是磁盘type为逻辑卷lvm才可以。 新增数据盘创建逻辑卷分区后在将原分区创建逻辑卷之后再合并。 我们今天就来测试一下。
添加硬盘
- 添加两块磁盘
查看分区情况
[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
sdc 8:32 0 5G 0 disk
对sdb进行传统分区并挂载数据目录
- 使用fdisk对/dev/sdb进行分区,
- 创建一个主分区并格式化为xfs
- 挂载数据目录/data
[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 0x72dee268.
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.
[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 ~]
[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/sdb1 xfs 5.0G 68M 5.0G 2% /data
写入数据模拟数据盘写100个文件到磁盘上做数据测试
- 写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
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
在sdc上创建逻辑卷lvm模拟新增盘扩容
- 不分区直接对sdc整盘创建逻辑卷
pvcreate /dev/sdc&&vgcreate datavg /dev/sdc&&lvcreate -l 100%FREE -n datalv datavg&&lsblk
[root@C8-196 ~]
Physical volume "/dev/sdc" successfully created.
Volume group "datavg" successfully created
Logical volume "datalv" created.
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 /data
sdc 8:32 0 5G 0 disk
└─datavg-datalv 253:3 0 5G 0 lvm
尝试直接使用dd命令拷贝sdb1上的数据到sdc逻辑卷
- 据说dd有格式化的功能
- 尝试逻辑卷不创建文件系统直接dd
- 结果dd了个寂寞
[root@C8-196 ~]
dd: writing to '/dev/mapper/datavg-datalv': No space left on device
10477569+0 records in
10477568+0 records out
5364514816 bytes (5.4 GB, 5.0 GiB) copied, 63.8898 s, 84.0 MB/s
real 1m3.891s
user 0m0.823s
sys 0m22.107s
[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/sdb1 xfs 5.0G 3.9G 1.2G 78% /data
[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 /data
sdc 8:32 0 5G 0 disk
└─datavg-datalv 253:3 0 5G 0 lvm
[root@C8-196 ~]
mount: /data: wrong fs type, bad option, bad superblock on /dev/mapper/datavg-datalv, missing codepage or helper program, or other error.
尝试创建文件系统后再dd
- 创建文件系统的时候告诉我已经有了
- 难道是惊喜?告诉我什么是TMD惊喜?
[root@C8-196 ~]
mkfs.xfs: /dev/mapper/datavg-datalv appears to contain an existing filesystem (xfs).
mkfs.xfs: Use the -f option to force overwrite.
尝试先解挂载后再挂载新创建的逻辑卷
- 之前dd后没有umount就直接挂载,提示出错了
- 这回试试先umount以后,再挂载同一个目录同一个梦想
[root@C8-196 ~]
[root@C8-196 ~]
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 919M 0 919M 0% /dev
tmpfs tmpfs 939M 0 939M 0% /dev/shm
tmpfs tmpfs 939M 18M 922M 2% /run
tmpfs tmpfs 939M 0 939M 0% /sys/fs/cgroup
/dev/mapper/cl-root xfs 76G 2.5G 73G 4% /
/dev/mapper/cl-home xfs 137G 984M 136G 1% /home
/dev/sda1 xfs 1.1G 207M 857M 20% /boot
tmpfs tmpfs 188M 0 188M 0% /run/user/0
[root@C8-196 ~]
mount: /data: can't read superblock on /dev/mapper/datavg-datalv.
尝试创建文件系统后再dd
[root@C8-196 ~]
testw100.db testw25.db testw40.db testw56.db testw71.db testw87.db
testw10.db testw26.db testw41.db testw57.db testw72.db testw88.db
testw11.db testw27.db testw42.db testw58.db testw73.db testw89.db
testw12.db testw28.db testw43.db testw59.db testw74.db testw8.db
testw13.db testw29.db testw44.db testw5.db testw75.db testw90.db
testw14.db testw2.db testw45.db testw60.db testw76.db testw91.db
testw15.db testw30.db testw46.db testw61.db testw77.db testw92.db
testw16.db testw31.db testw47.db testw62.db testw78.db testw93.db
testw17.db testw32.db testw48.db testw63.db testw79.db testw94.db
testw18.db testw33.db testw49.db testw64.db testw7.db testw95.db
testw19.db testw34.db testw4.db testw65.db testw80.db testw96.db
testw1.db testw35.db testw50.db testw66.db testw81.db testw97.db
testw20.db testw36.db testw51.db testw67.db testw82.db testw98.db
testw21.db testw37.db testw52.db testw68.db testw83.db testw99.db
testw22.db testw38.db testw53.db testw69.db testw84.db testw9.db
testw23.db testw39.db testw54.db testw6.db testw85.db
testw24.db testw3.db testw55.db testw70.db testw86.db
[root@C8-196 ~]
meta-data=/dev/mapper/datavg-datalv 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
[root@C8-196 ~]
dd: writing to '/dev/mapper/datavg-datalv': No space left on device
10477569+0 records in
10477568+0 records out
5364514816 bytes (5.4 GB, 5.0 GiB) copied, 59.9753 s, 89.4 MB/s
real 0m59.977s
user 0m0.669s
sys 0m19.805s
[root@C8-196 ~]
mount: /data: wrong fs type, bad option, bad superblock on /dev/mapper/datavg-datalv, missing codepage or helper program, or other error.
[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
[root@C8-196 ~]
mount: /data: can't read superblock on /dev/mapper/datavg-datalv.
- 同样的结果,再次出现,看来dd果然是带有格式化功能呢
正经挂载逻辑卷吧
[root@C8-196 ~]
meta-data=/dev/mapper/datavg-datalv 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
[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/datavg-datalv xfs 5.0G 68M 5.0G 2% /data
[root@C8-196 ~]
[root@C8-196 ~]
total 0
创建一个新目录挂原数据盘
[root@C8-196 ~]
[root@C8-196 ~]
testw100.db testw25.db testw40.db testw56.db testw71.db testw87.db
testw10.db testw26.db testw41.db testw57.db testw72.db testw88.db
testw11.db testw27.db testw42.db testw58.db testw73.db testw89.db
testw12.db testw28.db testw43.db testw59.db testw74.db testw8.db
testw13.db testw29.db testw44.db testw5.db testw75.db testw90.db
testw14.db testw2.db testw45.db testw60.db testw76.db testw91.db
testw15.db testw30.db testw46.db testw61.db testw77.db testw92.db
testw16.db testw31.db testw47.db testw62.db testw78.db testw93.db
testw17.db testw32.db testw48.db testw63.db testw79.db testw94.db
testw18.db testw33.db testw49.db testw64.db testw7.db testw95.db
testw19.db testw34.db testw4.db testw65.db testw80.db testw96.db
testw1.db testw35.db testw50.db testw66.db testw81.db testw97.db
testw20.db testw36.db testw51.db testw67.db testw82.db testw98.db
testw21.db testw37.db testw52.db testw68.db testw83.db testw99.db
testw22.db testw38.db testw53.db testw69.db testw84.db testw9.db
testw23.db testw39.db testw54.db testw6.db testw85.db
testw24.db testw3.db testw55.db testw70.db testw86.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/mapper/datavg-datalv xfs 5.0G 68M 5.0G 2% /data
/dev/sdb1 xfs 5.0G 3.9G 1.2G 78% /datasrc
用dd直接拷贝目录吧
[root@C8-196 ~]
dd: failed to open '/data': Is a directory
real 0m0.001s
user 0m0.000s
sys 0m0.001s
老老实实的用CP吧
time cp -av /datasrc /data
[root@C8-196 ~]
'/datasrc' -> '/data/datasrc'
'/datasrc/testw1.db' -> '/data/datasrc/testw1.db'
'/datasrc/testw2.db' -> '/data/datasrc/testw2.db'
'/datasrc/testw3.db' -> '/data/datasrc/testw3.db'
'/datasrc/testw99.db' -> '/data/datasrc/testw99.db'
'/datasrc/testw100.db' -> '/data/datasrc/testw100.db'
real 0m2.541s
user 0m0.006s
sys 0m2.155s
数据迁移完了就搞原来的数据盘弄成逻辑卷就行了
[root@C8-196 ~]
[root@C8-196 ~]
Cannot use /dev/sdb: device is partitioned
[root@C8-196 ~]
No device found for /dev/sdv1.
[root@C8-196 ~]
WARNING: xfs signature detected on /dev/sdb1 at offset 0. Wipe it? [y/n]: n
Aborted wiping of xfs.
1 existing signature left on the device.
[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.
/dev/datavg: already exists in filesystem
Run `vgcreate --help' for more information.
[root@C8-196 ~]
vgexport vgextend
[root@C8-196 ~]
cl datavg
[root@C8-196 ~]
Volume group "datavg" successfully extended
Size of logical volume datavg/datalv unchanged from <5.00 GiB (1279 extents).
Logical volume datavg/datalv successfully resized.
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
sdc 8:32 0 5G 0 disk
└─datavg-datalv 253:3 0 5G 0 lvm /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/mapper/datavg-datalv xfs 5.0G 3.9G 1.2G 78% /data
- sdb1怎么还没变? /data目录的空间也没变大啊!
查看当前逻辑卷的状态
[root@C8-196 ~]
PV VG Fmt Attr PSize PFree
/dev/sda2 cl lvm2 a-- <199.00g 0
/dev/sdb1 datavg lvm2 a-- <5.00g <5.00g
/dev/sdc datavg lvm2 a-- <5.00g 0
[root@C8-196 ~]
VG
cl 1 3 0 wz--n- <199.00g 0
datavg 2 1 0 wz--n- 9.99g <5.00g
[root@C8-196 ~]
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
datalv datavg -wi-ao---- <5.00g
再搞一次扩展
[root@C8-196 ~]
Size of logical volume datavg/datalv unchanged from <5.00 GiB (1279 extents).
Logical volume datavg/datalv successfully resized.
[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/datavg-datalv xfs 5.0G 3.9G 1.2G 78% /data
[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
sdc 8:32 0 5G 0 disk
└─datavg-datalv 253:3 0 5G 0 lvm /data
[root@C8-196 ~]
- 结果还是没变???
- 所以lvextend不好用,哈哈哈!
一步到位的逻辑卷扩容大法来了!
[root@C8-196 ~]
Size of logical volume datavg/datalv unchanged from <5.00 GiB (1279 extents).
Logical volume datavg/datalv successfully resized.
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/datavg-datalv xfs 5.0G 3.9G 1.2G 78% /data
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
sdc 8:32 0 5G 0 disk
└─datavg-datalv 253:3 0 5G 0 lvm /data
- 结果还是一样的,那个sdb1就有问题在那
- 看他不爽,搞掉他
[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.
Command (m for help): d
Selected partition 1
Partition 1 has been deleted.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[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
sdc 8:32 0 5G 0 disk
└─datavg-datalv 253:3 0 5G 0 lvm /data
逻辑分区再次搞起!
[root@C8-196 ~]
WARNING: dos signature detected on /dev/sdb at offset 510. Wipe it? [y/n]: y
Wiping dos signature on /dev/sdb.
Physical volume "/dev/sdb" successfully created.
WARNING: Couldn't find device with uuid l7TGdc-G8Zg-ZqCJ-Ef7X-wF2R-den5-njtWyV.
WARNING: VG datavg is missing PV l7TGdc-G8Zg-ZqCJ-Ef7X-wF2R-den5-njtWyV (last written to /dev/sdb1).
WARNING: Couldn't find device with uuid l7TGdc-G8Zg-ZqCJ-Ef7X-wF2R-den5-njtWyV.
WARNING: Couldn't find device with uuid l7TGdc-G8Zg-ZqCJ-Ef7X-wF2R-den5-njtWyV.
Volume group "datavg" successfully extended
WARNING: Couldn't find device with uuid l7TGdc-G8Zg-ZqCJ-Ef7X-wF2R-den5-njtWyV.
WARNING: VG datavg is missing PV l7TGdc-G8Zg-ZqCJ-Ef7X-wF2R-den5-njtWyV (last written to [unknown]).
Cannot change VG datavg while PVs are missing.
See vgreduce --removemissing and vgextend --restoremissing.
Cannot process volume group datavg
[root@C8-196 ~]
WARNING: Couldn't find device with uuid l7TGdc-G8Zg-ZqCJ-Ef7X-wF2R-den5-njtWyV.
WARNING: VG datavg is missing PV l7TGdc-G8Zg-ZqCJ-Ef7X-wF2R-den5-njtWyV (last written to [unknown]).
PV VG Fmt Attr PSize PFree
/dev/sda2 cl lvm2 a-- <199.00g 0
/dev/sdb datavg lvm2 a-- <5.00g <5.00g
/dev/sdc datavg lvm2 a-- <5.00g 0
[unknown] datavg lvm2 a-m <5.00g <5.00g
[root@C8-196 ~]# vgs
WARNING: Couldn't find device with uuid l7TGdc-G8Zg-ZqCJ-Ef7X-wF2R-den5-njtWyV.
WARNING: VG datavg is missing PV l7TGdc-G8Zg-ZqCJ-Ef7X-wF2R-den5-njtWyV (last written to [unknown]).
VG
cl 1 3 0 wz--n- <199.00g 0
datavg 3 1 0 wz-pn- <14.99g 9.99g
[root@C8-196 ~]
WARNING: Couldn't find device with uuid l7TGdc-G8Zg-ZqCJ-Ef7X-wF2R-den5-njtWyV.
WARNING: VG datavg is missing PV l7TGdc-G8Zg-ZqCJ-Ef7X-wF2R-den5-njtWyV (last written to [unknown]).
PV VG Fmt Attr PSize PFree
/dev/sda2 cl lvm2 a-- <199.00g 0
/dev/sdb datavg lvm2 a-- <5.00g <5.00g
/dev/sdc datavg lvm2 a-- <5.00g 0
[unknown] datavg lvm2 a-m <5.00g <5.00g
[root@C8-196 ~]# vgreduce --removemissing datavg
WARNING: Couldn't find device with uuid l7TGdc-G8Zg-ZqCJ-Ef7X-wF2R-den5-njtWyV.
WARNING: VG datavg is missing PV l7TGdc-G8Zg-ZqCJ-Ef7X-wF2R-den5-njtWyV (last written to [unknown]).
WARNING: Couldn't find device with uuid l7TGdc-G8Zg-ZqCJ-Ef7X-wF2R-den5-njtWyV.
Wrote out consistent volume group datavg.
[root@C8-196 ~]
VG
cl 1 3 0 wz--n- <199.00g 0
datavg 2 1 0 wz--n- 9.99g <5.00g
[root@C8-196 ~]
PV VG Fmt Attr PSize PFree
/dev/sda2 cl lvm2 a-- <199.00g 0
/dev/sdb datavg lvm2 a-- <5.00g <5.00g
/dev/sdc datavg lvm2 a-- <5.00g
华丽丽的成功了!哈哈哈!
lvresize -r -l +100%FREE /dev/mapper/datavg-datalv&&df -Th &&lsblk
[root@C8-196 ~]
Physical volume '/dev/sdb' is already in volume group 'datavg'
Unable to add physical volume '/dev/sdb' to volume group 'datavg'
/dev/sdb: physical volume not initialized.
[root@C8-196 ~]
Size of logical volume datavg/datalv changed from <5.00 GiB (1279 extents) to 9.99 GiB (2558 extents).
Logical volume datavg/datalv successfully resized.
meta-data=/dev/mapper/datavg-datalv 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 blocks changed from 1309696 to 2619392
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/datavg-datalv xfs 10G 4.0G 6.1G 40% /data
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
└─datavg-datalv 253:3 0 10G 0 lvm /data
sdc 8:32 0 5G 0 disk
└─datavg-datalv 253:3 0 10G 0 lvm /data
总结
- 先将新挂载盘做成逻辑卷,
- 接着老老实实用cp -av拷贝文件
- 拷贝完文件踏踏实实把原来的分区干掉
- 在原分区或磁盘上创建新的逻辑分区
- 扩展逻辑分区命令
lvresize -r -l +100%FREE /dev/mapper/datavg-datalv
- 不要试图使用dd命令拷贝文件夹,逻辑卷和物理分区完全不是一回事
- 最好对原盘的分区彻底搞一下,如果是独立盘,要把分区删掉最好
- 逻辑卷往下摘物理盘是有顺序的
从卷组里剔除物理卷
- 先要从卷组中将被占用的空间挪走 将被占用的pe挪走
挪之前pe的个数要小于整个vg剩余的pe数 pvmove /dev/sdc 将pv上被占用的pe挪到同vg上的其他pv上 - 挪完以后从vg中删掉pv vgreduce vof /dev/sdc
- 再删除pv属性 pvremove /dev/sdc
|