1.故障现象:

有一台服务器需要将/data卷扩大,做fdisk时候是正常的,但做完fdisk保存退出后就看不到这个新的分区,当ls 这个新建的卷时出现以下报错: ls: cannot access /dev/vdb2: No such file or directory

[root@test-nginx ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p

Disk /dev/vdb: 386.5 GB, 386547056640 bytes, 754974720 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0a27e493

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048   125829119    62913536   8e  Linux LVM

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (125829120-754974719, default 125829120): 
Using default value 125829120
Last sector, +sectors or +size{K,M,G} (125829120-754974719, default 754974719): 
Using default value 754974719
Partition 2 of type Linux and of size 300 GiB is set

Command (m for help): p

Disk /dev/vdb: 386.5 GB, 386547056640 bytes, 754974720 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0a27e493

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048   125829119    62913536   8e  Linux LVM
/dev/vdb2       125829120   754974719   314572800   83  Linux

Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@test-nginx ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda             253:0    0   40G  0 disk 
├─vda1          253:1    0    1G  0 part /boot
└─vda2          253:2    0   27G  0 part /
vdb             253:16   0  360G  0 disk 
└─vdb1          253:17   0   60G  0 part 
  └─datavg-lv01 252:0    0   60G  0 lvm  /data
[root@test-nginx ~]# pvcreate /dev/vdb2
  Device /dev/vdb2 not found.
[root@test-nginx ~]# ls /dev/vdb2
ls: cannot access /dev/vdb2: No such file or directory

2. 解决方法

partprobe命令的作用就是:
将磁盘分区表变化信息通知内核,请求操作系统重新加载分区表。
直接执行partprobe扫描所有磁盘
也可以partprobe /dev/vdb只扫描某个磁盘的分区表

[root@test-nginx ~]# partprobe
[root@test-nginx ~]# ls /dev/vdb2
/dev/vdb2

后续再做了磁盘扩展

[root@test-nginx ~]# pvcreate /dev/vdb2
  Physical volume "/dev/vdb2" successfully created.
[root@test-nginx ~]# vgextend datavg /dev/vdb2
  Volume group "datavg" successfully extended
[root@test-nginx ~]# vgdisplay 
  --- Volume group ---
  VG Name               datavg
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               359.99 GiB
  PE Size               4.00 MiB
  Total PE              92158
  Alloc PE / Size       15359 / <60.00 GiB
  Free  PE / Size       76799 / <300.00 GiB
  VG UUID               Drx224-cfwF-gDrb-8w56-FH3K-E4Y9-a49xj0
   
[root@test-nginx ~]# lvextend -r -l +100%free /dev/mapper/datavg-lv01
  Size of logical volume datavg/lv01 changed from <60.00 GiB (15359 extents) to 359.99 GiB (92158 extents).
  Logical volume datavg/lv01 successfully resized.
meta-data=/dev/mapper/datavg-lv01 isize=512    agcount=4, agsize=3931904 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=15727616, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=7679, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 15727616 to 94369792
[root@test-nginx ~]# df -TH
Filesystem              Type      Size  Used Avail Use% Mounted on
devtmpfs                devtmpfs  8.3G     0  8.3G   0% /dev
tmpfs                   tmpfs     8.3G     0  8.3G   0% /dev/shm
tmpfs                   tmpfs     8.3G  572M  7.8G   7% /run
tmpfs                   tmpfs     8.3G     0  8.3G   0% /sys/fs/cgroup
/dev/vda2               ext4       29G   21G  7.4G  74% /
/dev/vda1               ext4      1.1G  111M  886M  12% /boot
/dev/mapper/datavg-lv01 xfs       387G   41G  347G  11% /data
tmpfs                   tmpfs     1.7G     0  1.7G   0% /run/user/0
[root@test-nginx ~]# 
Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐