IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> Linux下非逻辑卷扩容之新增盘扩容 -> 正文阅读

[系统运维]Linux下非逻辑卷扩容之新增盘扩容

导语

我们都知道使用lv逻辑卷可以方便的扩容。
但是当原盘不是逻辑卷且其上有数据的时候,如何扩容呢?
因为扩容只能是磁盘type为逻辑卷lvm才可以。
新增数据盘创建逻辑卷分区后在将原分区创建逻辑卷之后再合并。
我们今天就来测试一下。

添加硬盘

  • 添加两块磁盘
    添加两块磁盘

查看分区情况

  • 我们看到新添加的两块盘已经可以用了
[root@C8-196 ~]# lsblk
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 ~]# fdisk /dev/sdb

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 ~]# mkfs.xfs /dev/sdb1
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 ~]# mount /dev/sdb1 /data
[root@C8-196 ~]# 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   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 ~]# pvcreate /dev/sdc&&vgcreate datavg /dev/sdc&&lvcreate -l 100%FREE -n datalv datavg&&lsblk
  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 ~]# time dd if=/dev/sdb1 of=/dev/mapper/datavg-datalv
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 ~]# 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
[root@C8-196 ~]# lsblk
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 /dev/mapper/datavg-datalv /data
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
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 ~]# umount /dev/sdb1
[root@C8-196 ~]# df -TH
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 -t xfs /dev/mapper/datavg-datalv /data
mount: /data: can't read superblock on /dev/mapper/datavg-datalv.
  • 白兴奋了,还是挂了个寂寞

尝试创建文件系统后再dd

  • 先把目录挂回来,保持挂载状态,看看dd有啥效果
[root@C8-196 ~]# mount /dev/sdb1 /data&&ls /data
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 ~]# mkfs.xfs /dev/mapper/datavg-datalv -f
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
  • 再次dd,哈哈哈!
[root@C8-196 ~]# time dd if=/dev/sdb1 of=/dev/mapper/datavg-datalv
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 /dev/mapper/datavg-datalv /data
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 ~]# umount /dev/sdb1
[root@C8-196 ~]# 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
[root@C8-196 ~]# mount /dev/mapper/datavg-datalv /data
mount: /data: can't read superblock on /dev/mapper/datavg-datalv.
  • 同样的结果,再次出现,看来dd果然是带有格式化功能呢

正经挂载逻辑卷吧

  • 按照正常步骤来是肯定能挂上的
[root@C8-196 ~]# mkfs.xfs /dev/mapper/datavg-datalv -f
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 ~]# mount /dev/mapper/datavg-datalv /data
[root@C8-196 ~]# 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/mapper/datavg-datalv xfs       5.0G   68M  5.0G   2% /data
[root@C8-196 ~]# ls /data
[root@C8-196 ~]# ll /data
total 0

创建一个新目录挂原数据盘

  • 创建新的目录用来挂载原来的数据盘,数据都在里边
[root@C8-196 ~]# mkdir /datasrc
[root@C8-196 ~]# mount /dev/sdb1 /datasrc/&&ls /datasrc&&df -Th
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直接拷贝目录吧

  • 想的太美了,dd不能拷贝目录
[root@C8-196 ~]# time dd if=/datasrc of=/data
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 ~]# time cp -av /datasrc /data
'/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 ~]# umount /datasrc 
[root@C8-196 ~]# pvcreate /dev/sdb
  Cannot use /dev/sdb: device is partitioned
[root@C8-196 ~]# pvcreate /dev/sdv1
  No device found for /dev/sdv1.
[root@C8-196 ~]# pvcreate /dev/sdb1
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 ~]# pvcreate /dev/sdb1&&vgcreate datavg /dev/sdb1&&lvextend -rl 100%FREE /dev/mapper/datavg-datalv
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 ~]# vgex
vgexport  vgextend  
[root@C8-196 ~]# vgextend 
cl      datavg  
[root@C8-196 ~]# vgextend datavg /dev/sdb1&&lvextend -rl 100%FREE /dev/mapper/datavg-datalv&&lsblk&&df -Th
  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 ~]# pvs
  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 ~]# vgs
  VG     #PV #LV #SN Attr   VSize    VFree 
  cl       1   3   0 wz--n- <199.00g     0 
  datavg   2   1   0 wz--n-    9.99g <5.00g
[root@C8-196 ~]# lvs
  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 ~]# lvextend -r -l 100%FREE /dev/mapper/datavg-datalv
Size of logical volume datavg/datalv unchanged from <5.00 GiB (1279 extents).
Logical volume datavg/datalv successfully resized.
[root@C8-196 ~]# 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/mapper/datavg-datalv xfs       5.0G  3.9G  1.2G  78% /data
[root@C8-196 ~]# lsblk
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 ~]# lvresize -r -l 100%FREE /dev/mapper/datavg-datalv&&df -Th &&lsblk
  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 ~]# fdisk /dev/sdb

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 ~]# lsblk
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 ~]# pvcreate /dev/sdb&&vgextend datavg /dev/sdb&&lvresize -r -l +100%FREE /dev/mapper/datavg-datalv&&df -Th &&lsblk
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 ~]# pvs
  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     #PV #LV #SN Attr   VSize    VFree
  cl       1   3   0 wz--n- <199.00g    0 
  datavg   3   1   0 wz-pn-  <14.99g 9.99g
  • 结果搞挂了!哈哈哈!
  • 忘了把原来的vg拿掉了
[root@C8-196 ~]# pvs
  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 ~]# vgs
  VG     #PV #LV #SN Attr   VSize    VFree 
  cl       1   3   0 wz--n- <199.00g     0 
  datavg   2   1   0 wz--n-    9.99g <5.00g
[root@C8-196 ~]# pvs
  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 ~]# vgextend datavg /dev/sdb&&lvresize -r -l +100%FREE /dev/mapper/datavg-datalv&&df -Th &&lsblk
  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 ~]# lvresize -r -l +100%FREE /dev/mapper/datavg-datalv&&df -Th &&lsblk
  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

总结

  • 总体思路是
  1. 先将新挂载盘做成逻辑卷,
  2. 接着老老实实用cp -av拷贝文件
  3. 拷贝完文件踏踏实实把原来的分区干掉
  4. 在原分区或磁盘上创建新的逻辑分区
  5. 扩展逻辑分区命令lvresize -r -l +100%FREE /dev/mapper/datavg-datalv
  • 上边踩过的坑
  1. 不要试图使用dd命令拷贝文件夹,逻辑卷和物理分区完全不是一回事
  2. 最好对原盘的分区彻底搞一下,如果是独立盘,要把分区删掉最好
  3. 逻辑卷往下摘物理盘是有顺序的

从卷组里剔除物理卷

  1. 先要从卷组中将被占用的空间挪走 将被占用的pe挪走
    挪之前pe的个数要小于整个vg剩余的pe数
    pvmove /dev/sdc 将pv上被占用的pe挪到同vg上的其他pv上
  2. 挪完以后从vg中删掉pv vgreduce vof /dev/sdc
  3. 再删除pv属性 pvremove /dev/sdc
  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2022-03-04 16:00:29  更:2022-03-04 16:03:48 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/16 3:26:36-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码