案例的环境和需求描述如下:公司准备在Internet中搭建邮件服务器(RHEL 6系统平台),面向全国各地的员工及部分VIP客户提供电子邮箱空间。由于用户数量众多,邮件存储需要大量的空间,考虑到动态扩容的需要,计划增加两块SCSI硬盘并构建LVM逻辑卷 (挂载到“/mailbox”目录下)专门用于存放邮件数据。
[root@test2 /]# fdisk /dev/sdb WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): 8e Changed system type of partition 2 to 8e (Linux LVM) Command (m for help): p Disk /dev/sdb: 85.9 GB, 85899345920 bytes 255 heads, 63 sectors/track, 10443 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: 0xa8f24694 Device Boot Start End Blocks Id System /dev/sdb1 1 2612 20980858+ 83 Linux /dev/sdb2 2613 5224 20980890 8e Linux LVM /dev/sdb3 5225 10443 41921617+ 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@test2 /]# 截图:
[root@test2 /]# fdisk /dev/sdc WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): n Command action e extended p primary partition (1-4) 2 Invalid partition number for type `2' Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (2613-10443, default 2613): Using default value 2613 Last cylinder, +cylinders or +size{K,M,G} (2613-10443, default 10443): +20F Unsupported suffix: 'F'. Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte) 2^N: K (KibiByte), M (MebiByte), G (GibiByte) Last cylinder, +cylinders or +size{K,M,G} (2613-10443, default 10443): +20G Command (m for help): P Disk /dev/sdc: 85.9 GB, 85899345920 bytes 255 heads, 63 sectors/track, 10443 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: 0x8967e34e Device Boot Start End Blocks Id System /dev/sdc1 1 2612 20980858+ 83 Linux /dev/sdc2 2613 5224 20980890 83 Linux 转换类型错误操作:Command (m for help): T Partition number (1-4): be Partition number (1-4): 2 Hex code (type L to list codes): b Changed system type of partition 2 to b (W95 FAT32) 分析:LVM的分区代码是8e.转换成LVM分区的正确操作:Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): 8e Changed system type of partition 2 to 8e (Linux LVM) Command (m for help): p Disk /dev/sdc: 85.9 GB, 85899345920 bytes 255 heads, 63 sectors/track, 10443 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: 0x8967e34e Device Boot Start End Blocks Id System /dev/sdc1 1 2612 20980858+ 83 Linux /dev/sdc2 2613 5224 20980890 8e Linux LVM Command (m for help):
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) WARNING: If you have created or modified any DOS 6.x partitions, please see the fdisk manual page for additional information. Syncing disks.
探测失败[root@test2 /]# partx /dev/sdc sdc sdc1 [root@test2 /]# partx /dev/sdc sdc sdc1 [root@test2 /]# partx -a /dev/sdc sdc sdc1 [root@test2 /]# partx -a /dev/sdc sdc sdc1 重启虚拟机(略)重启后识别成功:[root@test2 jason]# partprobe /dev/sdc sdc sdc1 sdc2 [root@test2 jason]# partprobe /dev/sdc 截图:
当前pv的信息[root@test2 jason]# pvscan PV /dev/sda2 VG vg_jason lvm2 [19.51 GiB / 0 free] PV /dev/sdb1 lvm2 [20.01 GiB] PV /dev/sdb2 lvm2 [20.01 GiB] Total: 3 [59.53 GiB] / in use: 1 [19.51 GiB] / in no VG: 2 [40.02 GiB] [root@test2 jason]# 截图:
将sdc2创建成physical volume(物理卷):[root@test2 jason]# pvcreate /dev/sdc2 Physical volume "/dev/sdc2" successfully created [root@test2 jason]# 再次查看pv信息:[root@test2 jason]# pvscan PV /dev/sda2 VG vg_jason lvm2 [19.51 GiB / 0 free] PV /dev/sdb1 lvm2 [20.01 GiB] PV /dev/sdb2 lvm2 [20.01 GiB] PV /dev/sdc2 lvm2 [20.01 GiB] Total: 4 [79.53 GiB] / in use: 1 [19.51 GiB] / in no VG: 3 [60.03 GiB] [root@test2 jason]# 截图:
创建名称为“mail_store”的volume group(卷组):[root@test2 jason]# pvcreate mail_store /dev/sdb2 /dev/sdc2 Device mail_store not found (or ignored by filtering). dev_is_mpath: failed to get device for 8:18 Physical volume "/dev/sdb2" successfully created Physical volume "/dev/sdc2" successfully created [root@test2 jason]# 截图:
再次查看vg信息:[root@test2 jason]# vgscan Reading all physical volumes. This may take a while... Found volume group "vg_jason" using metadata type lvm2 截图:
分析是因为上面的命令用错了,应该是vgcreate,而不是pvcreate重新创建:[root@test2 jason]# vgcreate mail_store /dev/sdb2 /dev/sdc2 Volume group "mail_store" successfully created 查看VG[root@test2 jason]# vgscan Reading all physical volumes. This may take a while... Found volume group "mail_store" using metadata type lvm2 Found volume group "vg_jason" using metadata type lvm2 [root@test2 jason]# 截图:
名称为“mail_store”de vg(卷组)创建成功
创建前的lvscan:[root@test2 jason]# lvscan ACTIVE '/dev/vg_jason/lv_root' [17.51 GiB] inherit ACTIVE '/dev/vg_jason/lv_swap' [2.00 GiB] inherit 截图:
创建名称为“mbox”的lv并查看:[root@test2 jason]# lvcreate -L 35G -n mbox mail_store Logical volume "mbox" created [root@test2 jason]# lvscan ACTIVE '/dev/mail_store/mbox' [35.00 GiB] inherit ACTIVE '/dev/vg_jason/lv_root' [17.51 GiB] inherit ACTIVE '/dev/vg_jason/lv_swap' [2.00 GiB] inherit [root@test2 jason]# 截图:
创建目录[root@test2 /]# mkdir /mailbox
将新建立的mail_box格式化成ext4[root@test2 /]# mkfs.ext4 /dev/mail_store/mbox mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 2293760 inodes, 9175040 blocks 458752 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 280 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 30 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@test2 /]# 截图:
[root@test2 /]# mount /dev/mail_store/mbox /mailbox/ [root@test2 /]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/vg_jason-lv_root ext4 18G 4.3G 13G 27% / tmpfs tmpfs 3.9G 72K 3.9G 1% /dev/shm /dev/sda1 ext4 485M 40M 421M 9% /boot /dev/sdc1 ext4 20G 421M 19G 3% /home /dev/mapper/mail_store-mbox ext4 35G 176M 33G 1% /mailbox [root@test2 /]# 截图:
截图:
[root@test2 jason]# fdisk /dev/sdd Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xef9a8da9. 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) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-13054, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-13054, default 13054): Using default value 13054 Command (m for help): t Selected partition 1 Hex code (type L to list codes): 8e Changed system type of partition 1 to 8e (Linux LVM) Command (m for help): p Disk /dev/sdd: 107.4 GB, 107374182400 bytes 255 heads, 63 sectors/track, 13054 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: 0xef9a8da9 Device Boot Start End Blocks Id System /dev/sdd1 1 13054 104856223+ 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@test2 jason]# 探测:[root@test2 jason]# partprobe /dev/sdd sdd sdd1 [root@test2 jason]# partprobe /dev/sdd
[root@test2 jason]# pvcreate /dev/sdd1 dev_is_mpath: failed to get device for 8:49 Physical volume "/dev/sdd1" successfully created
[root@test2 jason]# vgextend mail_store /dev/sdd1 Volume group "mail_store" successfully extended vgdisplay mail_store:[root@test2 jason]# vgdisplay mail_store --- Volume group --- VG Name mail_store System ID Formatlvm2 Metadata Areas3 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV0 Cur LV1 Open LV 0 Max PV0 Cur PV3 Act PV3 VG Size 140.01 GiB PE Size 4.00 MiB Total PE 35843 Alloc PE / Size 8960 / 35.00 GiB Free PE / Size 26883 / 105.01 GiB VG UUID yHpVfR-lbFL-vs9A-mzgz-m800-JLE2-Dt2z6F [root@test2 jason]# 截图:
错误的语法:[root@test2 jason]# lvextend -L +85G mbox mail_store Path required for Logical Volume "mbox" Please provide a volume group name Run `lvextend --help' for more information. 正确的lv扩容操作:[root@test2 jason]# lvextend -L +85G /dev/mail_store/mbox Extending logical volume mbox to 120.00 GiB Logical volume mbox successfully resized 扩容后查看:[root@test2 jason]# lvscan ACTIVE '/dev/mail_store/mbox' [120.00 GiB] inherit ACTIVE '/dev/vg_jason/lv_root' [17.51 GiB] inherit ACTIVE '/dev/vg_jason/lv_swap' [2.00 GiB] inherit
刚才为了重新加一个100G的硬盘重启,重启后的mount信息:[root@test2 jason]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/vg_jason-lv_root ext4 18G 4.3G 13G 27% / tmpfs tmpfs 3.9G 72K 3.9G 1% /dev/shm /dev/sda1 ext4 485M 40M 421M 9% /boot /dev/sdc1 ext4 20G 421M 19G 3% /home [root@test2 jason]# mount /dev/mapper/vg_jason-lv_root on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw) /dev/sda1 on /boot type ext4 (rw) /dev/sdc1 on /home type ext4 (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other) 重新挂载并查看:[root@test2 jason]# mount /dev/mail_store/mbox /mailbox/ [root@test2 jason]# mount /dev/mapper/vg_jason-lv_root on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw) /dev/sda1 on /boot type ext4 (rw) /dev/sdc1 on /home type ext4 (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other) /dev/mapper/mail_store-mbox on /mailbox type ext4 (rw) 查看mbox的容量:[root@test2 jason]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/vg_jason-lv_root ext4 18G 4.3G 13G 27% / tmpfs tmpfs 3.9G 72K 3.9G 1% /dev/shm /dev/sda1 ext4 485M 40M 421M 9% /boot /dev/sdc1 ext4 20G 421M 19G 3% /home /dev/mapper/mail_store-mbox ext4 35G 176M 33G 1% /mailbox
查看resize2fs的用法:[root@test2 jason]# resize2fs resize2fs 1.41.12 (17-May-2010) Usage: resize2fs [-d debug_flags] [-f] [-F] [-M] [-P] [-p] device [new_size] 使用resize2fs更新mbox的容量:[root@test2 jason]# resize2fs /dev/mail_store/mbox resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/mail_store/mbox is mounted on /mailbox; on-line resizing required old desc_blocks = 3, new_desc_blocks = 8 Performing an on-line resize of /dev/mail_store/mbox to 31457280 (4k) blocks. The filesystem on /dev/mail_store/mbox is now 31457280 blocks long. 更新成功:[root@test2 jason]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/vg_jason-lv_root ext4 18G 4.3G 13G 27% / tmpfs tmpfs 3.9G 72K 3.9G 1% /dev/shm /dev/sda1 ext4 485M 40M 421M 9% /boot /dev/sdc1 ext4 20G 421M 19G 3% /home /dev/mapper/mail_store-mbox ext4 119G 188M 112G 1% /mailbox [root@test2 jason]#(责任编辑:IT) |