Disk /dev/mapper/vg-var doesn't contain a valid partition table

问题描述

root@compute-44:~# fdisk -l

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 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 identifier: 0x000261d7

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   390625279   195311616   8e  Linux LVM
/dev/sda2       390627326   410157055     9764865    5  Extended
/dev/sda3       410157056   605468671    97655808   83  Linux
/dev/sda4   *   605468672   976771071   185651200   83  Linux
/dev/sda5       390627328   410157055     9764864   82  Linux swap / Solaris

Disk /dev/mapper/vg-root: 50.0 GB, 49996103680 bytes
89 heads, 26 sectors/track, 42199 cylinders, total 97648640 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 identifier: 0xd69bbd0b

              Device Boot      Start         End      Blocks   Id  System
/dev/mapper/vg-root1            2048    97648639    48823296   83  Linux

Disk /dev/mapper/vg-var: 100.0 GB, 99996401664 bytes
255 heads, 63 sectors/track, 12157 cylinders, total 195305472 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 identifier: 0x00000000

Disk /dev/mapper/vg-var doesn't contain a valid partition table

Disk /dev/mapper/vg-boot: 9999 MB, 9999220736 bytes
255 heads, 63 sectors/track, 1215 cylinders, total 19529728 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 identifier: 0x00000000

Disk /dev/mapper/vg-boot doesn't contain a valid partition table

问题解决

在出问题的磁盘上用fdisk重新分区,然后写入分区表

root@compute-44:~# fdisk /dev/mapper/vg-var 
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xd0982e54.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 
Using default response p
Partition number (1-4, default 1): 
Using default value 1
First sector (2048-195305471, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-195305471, default 195305471): 
Using default value 195305471

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 22: Invalid argument.
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.

再看一下/dev/mapper/var没有那一行字了

root@compute-44:~# fdisk -l

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 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 identifier: 0x000261d7

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   390625279   195311616   8e  Linux LVM
/dev/sda2       390627326   410157055     9764865    5  Extended
/dev/sda3       410157056   605468671    97655808   83  Linux
/dev/sda4   *   605468672   976771071   185651200   83  Linux
/dev/sda5       390627328   410157055     9764864   82  Linux swap / Solaris

Disk /dev/mapper/vg-root: 50.0 GB, 49996103680 bytes
89 heads, 26 sectors/track, 42199 cylinders, total 97648640 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 identifier: 0xd69bbd0b

              Device Boot      Start         End      Blocks   Id  System
/dev/mapper/vg-root1            2048    97648639    48823296   83  Linux

Disk /dev/mapper/vg-var: 100.0 GB, 99996401664 bytes
52 heads, 54 sectors/track, 69553 cylinders, total 195305472 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 identifier: 0xd0982e54

             Device Boot      Start         End      Blocks   Id  System
/dev/mapper/vg-var1            2048   195305471    97651712   83  Linux

Disk /dev/mapper/vg-boot: 9999 MB, 9999220736 bytes
255 heads, 63 sectors/track, 1215 cylinders, total 19529728 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 identifier: 0x00000000
<think> 我们正在处理一个具体问题:`/dev/mapper/ubantu--vg--ubantu--lv` 的可用磁盘空间为0。这是一个逻辑卷(Logical Volume),属于LVM(Logical Volume Manager)管理的一部分。当这个逻辑卷的可用空间为0时,可能会导致系统运行异常,甚至无法写入新数据。我们需要扩展该逻辑卷的空间。 解决步骤通常如下: 1. 检查当前磁盘空间使用情况(确认问题) 2. 检查卷组(VG)是否有剩余空间 3. 如果有剩余空间,则扩展逻辑卷(LV) 4. 如果没有剩余空间,则需要先扩展物理卷(PV)或添加新磁盘 5. 扩展文件系统(以便操作系统可以使用新扩展的空间) 注意:由于我们是在处理根文件系统(如果这个逻辑卷是根文件系统的话),操作需要谨慎。如果可能,建议在恢复模式下操作或确保有备份。 具体步骤: 步骤1:确认问题 使用 `df -h` 命令确认 `/dev/mapper/ubantu--vg--ubantu--lv` 的空间使用情况。 步骤2:检查卷组(VG)的剩余空间 使用 `vgdisplay` 命令查看卷组(例如 `ubantu-vg`)的剩余空间。 步骤3:如果卷组有足够空间,扩展逻辑卷 假设卷组名为 `ubantu-vg`,逻辑卷名为 `ubantu-lv`(注意:在设备映射中,名称中的空格被替换为双横线,所以实际卷组名可能是`ubantu-vg`,逻辑卷名可能是`ubantu-lv`,但显示为`ubantu--vg--ubantu--lv`,这是正常的命名转换)。 扩展逻辑卷的命令为: ```bash lvextend -l +100%FREE /dev/mapper/ubantu--vg--ubantu--lv ``` 或者指定具体大小,例如扩展10G: ```bash lvextend -L +10G /dev/mapper/ubantu--vg--ubantu--lv ``` 步骤4:如果卷组没有足够空间,需要先扩展卷组 4.1 查看当前物理卷(PV)情况:`pvdisplay` 4.2 如果有未使用的磁盘分区,将其加入卷组: 首先创建物理卷(如果这个磁盘分区还未被初始化为PV): ```bash pvcreate /dev/sdX # 替换sdX为实际磁盘分区 ``` 然后将其扩展到卷组中: ```bash vgextend ubantu-vg /dev/sdX ``` 4.3 如果没有未使用的磁盘分区,可能需要添加新磁盘或扩展虚拟机磁盘(如果是虚拟机环境),然后按照上述步骤创建物理卷并扩展卷组。 步骤5:扩展文件系统 仅仅扩展逻辑卷并不会自动扩展文件系统。需要根据文件系统类型扩展文件系统。 常见的文件系统类型是ext4(Ubuntu默认),可以使用: ```bash resize2fs /dev/mapper/ubantu--vg--ubantu--lv ``` 如果是xfs文件系统,则使用: ```bash xfs_growfs / ``` 注意:如果逻辑卷挂载的是根目录,那么应该挂载点为`/`,所以在扩展xfs文件系统时,可以直接指定挂载点。 注意:在扩展文件系统之前,确保逻辑卷已经扩展。 完整流程示例(假设卷组有足够空间,文件系统为ext4): ```bash # 1. 检查磁盘空间 df -h # 2. 查看卷组空间 vgdisplay ubantu-vg # 3. 扩展逻辑卷(使用卷组中所有剩余空间) lvextend -l +100%FREE /dev/mapper/ubantu--vg--ubantu--lv # 4. 扩展文件系统 resize2fs /dev/mapper/ubantu--vg--ubantu--lv ``` 如果逻辑卷是根文件系统,可能需要在恢复模式下执行,或者确保在系统运行时执行(但某些情况下,如果根文件系统满了,可能无法执行命令,这时需要从Live CD/USB启动)。 注意:操作前最好备份重要数据。 引用说明: [^1]:`df`命令用于查看磁盘空间。 [^2]:LVM管理相关命令(`vgdisplay`, `lvextend`, `resize2fs`等)的文档。 相关问题: 1. 如何检查LVM的逻辑卷、卷组和物理卷的状态? 2. 当卷组没有剩余空间时,如何添加新的物理卷? 3. 如何调整ext4和xfs文件系统的大小? </think>### 解决 `/dev/mapper/ubuntu--vg--ubuntu--lv` 磁盘空间为 0 的方法 当逻辑卷 `/dev/mapper/ubuntu--vg--ubuntu--lv` 显示可用空间为 0 时,通常表示 LVM 逻辑卷空间已耗尽。以下是完整的解决方法(操作需要 root 权限): --- ### 🔍 步骤 1:确认空间使用情况 ```bash df -h | grep ubuntu--vg--ubuntu--lv lvs # 查看逻辑卷详情 vgdisplay ubuntu-vg # 检查卷组剩余空间 ``` 输出示例: ``` VG Name ubuntu-vg Free PE / Size 0 / 0 # 关键看此处是否有剩余空间 ``` --- ### 🛠️ 步骤 2:扩展逻辑卷(根据卷组空间情况) #### ✅ 情况 A:卷组有剩余空间 ```bash # 扩展逻辑卷(+10G 示例,按需调整) lvextend -L +10G /dev/mapper/ubuntu--vg--ubuntu--lv # 扩展文件系统(EXT4/XFS) ## EXT4 文件系统: resize2fs /dev/mapper/ubuntu--vg--ubuntu--lv ## XFS 文件系统: xfs_growfs / ``` #### ❌ 情况 B:卷组无剩余空间(需先扩展卷组) ```bash # 1. 创建新分区(假设新磁盘为 /dev/sdb) fdisk /dev/sdb # 创建 Linux LVM 类型分区(8e) # 2. 创建物理卷 pvcreate /dev/sdb1 # 3. 扩展卷组 vgextend ubuntu-vg /dev/sdb1 # 4. 再执行情况 A 的扩展操作 ``` --- ### 🧹 步骤 3:清理临时文件(释放应急空间) ```bash # 清理日志和缓存 journalctl --vacuum-size=200M # 清理 systemd 日志 apt clean # 删除 apt 缓存 rm -rf /tmp/* # 清理临时文件 # 查找大文件 ncdu / # 或使用 du -sh /* | sort -h ``` --- ### 🔒 步骤 4:验证结果 ```bash df -h / # 检查根分区空间 lsblk # 查看块设备扩展情况 ``` 成功扩展后输出示例: ``` /dev/mapper/ubuntu--vg--ubuntu--lv 50G 45G 5.0G 90% / ``` --- ### ⚠️ 注意事项 1. **操作风险**:对根分区操作建议在 Live CD 环境下进行,或确保有完整备份 2. **虚拟机扩展**:如果是 VMware/VirtualBox - 先扩展虚拟磁盘大小 - 再执行 `pvresize /dev/sda2`(调整物理卷) 3. **空间规划**:建议保留至少 10% 的磁盘空间防止系统卡顿 4. **LVM 原理**: $$ \text{物理卷 (PV)} \rightarrow \text{卷组 (VG)} \rightarrow \text{逻辑卷 (LV)} $$ 扩展流程:物理磁盘 → PV → VG → LV → 文件系统[^1][^2] --- ### 📚 补充命令参考 | 命令 | 功能 | |------|------| | `pvresize /dev/sda2` | 调整物理卷大小 | | `lvresize -r -L +5G /dev/ubuntu-vg/ubuntu-lv` | 扩展 LV 并自动调整文件系统 | | `vgs --units g` | 以 GB 显示卷组空间 | [^1]: LVM 扩展需按 PV→VG→LV 顺序进行 [^2]: 文件系统操作必须匹配类型(ext4/xfs)
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值