主页 > 运维知识 > LVM分区无法格式化的问题解决[原创]

LVM分区无法格式化的问题解决[原创]

2012年12月4日 发表评论 查看评论
格式化lvm分区
明月的服务器新加了一块硬盘,并且在新硬盘上安装了操作系统,把久硬盘的内容复制后,将旧硬盘格式化作为一个单盘给分布式文件系统使用。
使用fdisk -l查看,
[root@web1 conf]# fdisk -l
Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00010f18
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sdb2              64      121602   976248832   8e  Linux LVM
 
Disk /dev/sda: 300.0 GB, 300000000000 bytes
255 heads, 63 sectors/track, 36472 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003daf8
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26       13080   104857600   83  Linux
/dev/sda3           13080       15169    16777216   83  Linux
/dev/sda4           15169       36473   171127808    5  Extended
/dev/sda5           15169       36473   171126784   83  Linux
 
Disk /dev/dm-0: 36.0 GB, 35953573888 bytes
255 heads, 63 sectors/track, 4371 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
 
Disk /dev/dm-0 doesn't contain a valid partition table
 
Disk /dev/dm-1: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
 
Disk /dev/dm-1 doesn't contain a valid partition table
 
Disk /dev/dm-2: 910.0 GB, 910033944576 bytes
255 heads, 63 sectors/track, 110638 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
 
Disk /dev/dm-2 doesn't contain a valid partition table
 
旧硬盘是做了lvm。一开始明月没理会,认为删除了最sdb1和sdb2,就可以了。
fdisk /dev/sdb  命令顺序:m -> d -> d -> w
命令执行成功,然后新建分区:
fdisk /dev/sdb  命令顺序:m -> n -> 1(只要一个分区) -> 默认 -> 默认(整个硬盘作为一个分区) -> w
这是时候报错了:
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
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)
既然提示要重新读取硬盘,那就执行:
[root@web1 conf]# partprobe /dev/sdb
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (设备或资源忙).  As a result, it may not reflect all of your changes until after reboot.
sdb不行,改成sdb1:
[root@web1 conf]# partprobe /dev/sdb1
执行成功,格式化:
mkfs -t ext3 -c /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
128016 inodes, 512000 blocks
25600 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=67633152
63 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks: 
        8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409
 
Checking for bad blocks (read-only test): 完成                                
正在写入inode表: 完成                            
Creating journal (8192 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
 
This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
 
挂载/dev/sdb1到/cloudfs目录,发现只有500M。 
[root@web1 /]# mount /dev/sdb1 /cloudfs
[root@web1 /]# df -h
文件系统              容量  已用  可用 已用%% 挂载点
/dev/sda2              99G  9.6G   84G  11% /
tmpfs                  16G     0   16G   0% /dev/shm
/dev/sda1             194M   30M  155M  16% /boot
/dev/sda5             161G   30G  124G  20% /data
/dev/sda3              16G  172M   15G   2% /opt
192.168.1.10:/data/help 148G   13G  128G   9% /data/help
192.168.1.10:/data/upload 148G   13G  128G   9% /data/upload
/dev/sdb1             485M   11M  449M   3% /cloudfs
明月这时候可以确定是LVM在搞鬼,所以开始删除LV,PV,VG:
[root@web1 /]# lvdisplay
  — Logical volume —
  LV Name                /dev/VolGroup/lv_root
  VG Name                VolGroup
  LV UUID                nQJ3Gz-uPTQ-hDV5-Ddli-mBnr-bEE9-qYNqZ0
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  – currently set to     256
  Block device           253:1
   
  — Logical volume —
  LV Name                /dev/VolGroup/lv_home
  VG Name                VolGroup
  LV UUID                XfWO6R-w3w3-j7ju-eWhU-NfaX-3b2n-MJHuye
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                847.54 GiB
  Current LE             216969
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  – currently set to     256
  Block device           253:2
   
  — Logical volume —
  LV Name                /dev/VolGroup/lv_swap
  VG Name                VolGroup
  LV UUID                sD3vhC-M6eQ-fcAp-Cu4H-QDpm-Gw5f-c9AyaB
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                33.48 GiB
  Current LE             8572
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  – currently set to     256
  Block device           253:0
[root@web1 /]# lvremove /dev/VolGroup/lv_swap
  Can't remove open logical volume "lv_swap"
[root@web1 /]# lvremove /dev/VolGroup/lv_root
Do you really want to remove active logical volume lv_root? [y/n]: y
  Logical volume "lv_root" successfully removed
[root@web1 /]# lvremove /dev/VolGroup/lv_home
Do you really want to remove active logical volume lv_home? [y/n]: y
  Logical volume "lv_home" successfully removed
这里swap删除报错了,状态时available,正在使用。谁在使用?检查了下/dev/fstab
[root@web1 /]# cat /etc/fstab
UUID=f86fac0d-28a8-45b3-9480-dcfbfea888e6 /     ext4  defaults  1 1
UUID=f911fe76-f6cf-4b51-8cc0-85b8e55b066d /boot ext4  defaults  1 2
UUID=381cedf2-5a0c-4c34-adcd-296e0ee0066a /data ext4  defaults  1 2
UUID=e4a3961b-d98a-40ff-9a81-bece6ed080dc /opt  ext4  defaults  1 2
/dev/mapper/VolGroup-lv_swap              swap  swap  defaults  0 0
tmpfs        /dev/shm    tmpfs   defaults        0 0
devpts       /dev/pts    devpts  gid=5,mode=620  0 0
sysfs        /sys        sysfs   defaults        0 0
proc         /proc       proc    defaults        0 0
新硬盘上面跑的系统,swap居然用的是旧硬盘的swap分区。明月觉得有点蛋疼。
执行下面命令:
关闭交换分区
swapoff /dev/mapper/VolGroup-lv_swap
删除lvswap和vggroup:
[root@web1 /]# lvremove /dev/VolGroup/lv_swap
Do you really want to remove active logical volume lv_swap? [y/n]: y
  Logical volume "lv_swap" successfully removed
[root@web1 /]# vgremove VolGroup
  Volume group "VolGroup" successfully removed
查看是否删除干净:
[root@web1 /]# fdisk -l
 
Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00010f18
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1      121601   976760001   83  Linux
 
Disk /dev/sda: 300.0 GB, 300000000000 bytes
255 heads, 63 sectors/track, 36472 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003daf8
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26       13080   104857600   83  Linux
/dev/sda3           13080       15169    16777216   83  Linux
/dev/sda4           15169       36473   171127808    5  Extended
/dev/sda5           15169       36473   171126784   83  Linux
重新格式化分区:
fdisk /dev/sdb   命令顺序:m -> d  -> w
fdisk /dev/sdb  命令顺序:m -> n -> 1 -> 默认 -> 默认 -> w
OK,这次可以了
运行完开始格式化:
mkfs -t ext3 -c /dev/sdb1
为什么要用ext3,不用ext4。因为明月系统的内核是2.6.32。ext4有个BUG,会造成大量IO浪费。领导又不想升级内核,那只能用回ext3.
这个内核bug是由于jbd2 process也就是ext4的日志进程引起的,具体可以看: https://bbs.archlinux.org/viewtopic.php?id=113516
格式换完挂载上去。
 
明月没忘记swap被干掉了。所以还需要下面几步:
建立一个2G的空白文件,dd命令是直接磁盘对拷,/dev/zero是一个返回空字节的字符设备,bs是block size,count是块数目。
dd if=/dev/zero of=/home/swap bs=1024 count=2048000
将/home/swap设置为交换区文件,记下UUID: 
mkswap /home/swap
立即启用交换分区文件
swapon /home/swap 
最后还需要修改/etc/fstab,不然下次启动要报错:
/dev/mapper/VolGroup-lv_swap swap  swap    defaults   0 0
修改为:
UUID=7881cde3-5c4a-4ce5-b68b-80e9d5715d09 swap swap  defaults  0 0
UUID是mkswap记下的那串值。

原创文章,转载请注明: 转载自肚腩照明月'blog

本文链接地址: LVM分区无法格式化的问题解决[原创]

文章的脚注信息由WordPress的wp-posturl插件自动生成


  1. 本文目前尚无任何评论.

SEO Powered by Platinum SEO from Techblissonline