格式化lvm分区
明月的服务器新加了一块硬盘,并且在新硬盘上安装了操作系统,把久硬盘的内容复制后,将旧硬盘格式化作为一个单盘给分布式文件系统使用。
使用fdisk -l查看,
[root@web1 conf]# fdisk -lDisk /dev/sdb: 1000.2 GB, 1000204886016 bytes255 heads, 63 sectors/track, 121601 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00010f18Device Boot Start End Blocks Id System/dev/sdb1 * 1 64 512000 83 LinuxPartition 1 does not end on cylinder boundary./dev/sdb2 64 121602 976248832 8e Linux LVMDisk /dev/sda: 300.0 GB, 300000000000 bytes255 heads, 63 sectors/track, 36472 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x0003daf8Device Boot Start End Blocks Id System/dev/sda1 * 1 26 204800 83 LinuxPartition 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 LinuxDisk /dev/dm-0: 36.0 GB, 35953573888 bytes255 heads, 63 sectors/track, 4371 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/dm-0 doesn't contain a valid partition tableDisk /dev/dm-1: 53.7 GB, 53687091200 bytes255 heads, 63 sectors/track, 6527 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/dm-1 doesn't contain a valid partition tableDisk /dev/dm-2: 910.0 GB, 910033944576 bytes255 heads, 63 sectors/track, 110638 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /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 atthe next reboot or after you run partprobe(8) or kpartx(8)
既然提示要重新读取硬盘,那就执行:
[root@web1 conf]# partprobe /dev/sdbWarning: 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/sdb1mke2fs 1.41.12 (17-May-2010)文件系统标签=操作系统:Linux块大小=1024 (log=0)分块大小=1024 (log=0)Stride=0 blocks, Stripe width=0 blocks128016 inodes, 512000 blocks25600 blocks (5.00%) reserved for the super user第一个数据块=1Maximum filesystem blocks=6763315263 block groups8192 blocks per group, 8192 fragments per group2032 inodes per groupSuperblock backups stored on blocks:8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409Checking 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 or180 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% /opt192.168.1.10:/data/help 148G 13G 128G 9% /data/help192.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_rootVG Name VolGroupLV UUID nQJ3Gz-uPTQ-hDV5-Ddli-mBnr-bEE9-qYNqZ0LV Write Access read/writeLV Status available# open 0LV Size 50.00 GiBCurrent LE 12800Segments 1Allocation inheritRead ahead sectors auto– currently set to 256Block device 253:1— Logical volume —LV Name /dev/VolGroup/lv_homeVG Name VolGroupLV UUID XfWO6R-w3w3-j7ju-eWhU-NfaX-3b2n-MJHuyeLV Write Access read/writeLV Status available# open 0LV Size 847.54 GiBCurrent LE 216969Segments 1Allocation inheritRead ahead sectors auto– currently set to 256Block device 253:2— Logical volume —LV Name /dev/VolGroup/lv_swapVG Name VolGroupLV UUID sD3vhC-M6eQ-fcAp-Cu4H-QDpm-Gw5f-c9AyaBLV Write Access read/writeLV Status available# open 1LV Size 33.48 GiBCurrent LE 8572Segments 1Allocation inheritRead ahead sectors auto– currently set to 256Block device 253:0[root@web1 /]# lvremove /dev/VolGroup/lv_swapCan't remove open logical volume "lv_swap"[root@web1 /]# lvremove /dev/VolGroup/lv_rootDo you really want to remove active logical volume lv_root? [y/n]: yLogical volume "lv_root" successfully removed[root@web1 /]# lvremove /dev/VolGroup/lv_homeDo you really want to remove active logical volume lv_home? [y/n]: yLogical volume "lv_home" successfully removed
这里swap删除报错了,状态时available,正在使用。谁在使用?检查了下/dev/fstab
[root@web1 /]# cat /etc/fstabUUID=f86fac0d-28a8-45b3-9480-dcfbfea888e6 / ext4 defaults 1 1UUID=f911fe76-f6cf-4b51-8cc0-85b8e55b066d /boot ext4 defaults 1 2UUID=381cedf2-5a0c-4c34-adcd-296e0ee0066a /data ext4 defaults 1 2UUID=e4a3961b-d98a-40ff-9a81-bece6ed080dc /opt ext4 defaults 1 2/dev/mapper/VolGroup-lv_swap swap swap defaults 0 0tmpfs /dev/shm tmpfs defaults 0 0devpts /dev/pts devpts gid=5,mode=620 0 0sysfs /sys sysfs defaults 0 0proc /proc proc defaults 0 0
新硬盘上面跑的系统,swap居然用的是旧硬盘的swap分区。明月觉得有点蛋疼。
执行下面命令:
关闭交换分区
swapoff /dev/mapper/VolGroup-lv_swap
删除lvswap和vggroup:
[root@web1 /]# lvremove /dev/VolGroup/lv_swapDo you really want to remove active logical volume lv_swap? [y/n]: yLogical volume "lv_swap" successfully removed[root@web1 /]# vgremove VolGroupVolume group "VolGroup" successfully removed
查看是否删除干净:
[root@web1 /]# fdisk -lDisk /dev/sdb: 1000.2 GB, 1000204886016 bytes255 heads, 63 sectors/track, 121601 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00010f18Device Boot Start End Blocks Id System/dev/sdb1 1 121601 976760001 83 LinuxDisk /dev/sda: 300.0 GB, 300000000000 bytes255 heads, 63 sectors/track, 36472 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x0003daf8Device Boot Start End Blocks Id System/dev/sda1 * 1 26 204800 83 LinuxPartition 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 -> wfdisk /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插件自动生成
LVM分区无法格式化的问题解决[原创]