Sep 162013
一直以来对VG都不是很理解,不过这次有人逼一下,就顺便好好理解一下。
其实现在如果是服务器,基本上架的时候,硬盘就是配置好,基本没啥机会添加硬盘,不过对于虚拟机,这样的机会还是很多的。
在Openstack下,给虚拟机添加一块硬盘倒是比较简单,不过有时候你会发现你添加的硬盘,虚拟机必须重启才能发现这块硬盘,现在终于有办法,不需要重启就可以找到硬盘。
运行这个脚本就可以 用http://www.garloff.de/kurt/linux/rescan-scsi-bus.sh
运行就可以。
这个时候,你通过
fdisk –l
就可以看到新增加的硬盘。应该是 /dev/sdb
第二磁盘格式化为LVM分区
[root@example1 ~]# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xebb1f38a. 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): m Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-10240, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-10240, default 10240): Using default value 10240 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): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@example1 ~]# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes 64 heads, 32 sectors/track, 20480 cylinders Units = cylinders of 2048 * 512 = 1048576 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x8e290e00 Device Boot Start End Blocks Id System /dev/sda1 * 2 5 4096 41 PPC PReP Boot Partition 1 does not end on cylinder boundary. /dev/sda2 6 505 512000 83 Linux Partition 2 does not end on cylinder boundary. /dev/sda3 506 20480 20454400 8e Linux LVM Partition 3 does not end on cylinder boundary. Disk /dev/mapper/VolGroup-lv_root: 16.7 GB, 16747855872 bytes 255 heads, 63 sectors/track, 2036 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/mapper/VolGroup-lv_swap: 4194 MB, 4194304000 bytes 255 heads, 63 sectors/track, 509 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/sdb: 10.7 GB, 10737418240 bytes 64 heads, 32 sectors/track, 10240 cylinders Units = cylinders of 2048 * 512 = 1048576 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xebb1f38a Device Boot Start End Blocks Id System /dev/sdb1 1 10240 10485744 8e Linux LVM
创建PV
pvcreate /dev/sdb1
查看当前的VG情况
# vgdisplay --- Volume group --- VG Name VolGroup System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 19.50 GiB PE Size 4.00 MiB Total PE 4993 Alloc PE / Size 4993 / 19.50 GiB Free PE / Size 0 / 0 VG UUID 9qJAbQ-G6No-EO6b-3Rjk-0JMa-8plQ-wyMLBl
扩展VG
# vgextend VolGroup /dev/sdb1
Volume group "VolGroup" successfully extended
查看VG
# vgdisplay --- Volume group --- VG Name VolGroup System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 2 Act PV 2 VG Size 29.50 GiB PE Size 4.00 MiB Total PE 7552 Alloc PE / Size 4993 / 19.50 GiB Free PE / Size 2559 / 10.00 GiB VG UUID 9qJAbQ-G6No-EO6b-3Rjk-0JMa-8plQ-wyMLBl
扩展LV
# lvextend -L +9G /dev/VolGroup/lv_root /dev/sdb1 Extending logical volume lv_root to 24.60 GiB Logical volume lv_root successfully resized
认出分区
# resize2fs /dev/mapper/VolGroup-lv_root resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/mapper/VolGroup-lv_root is mounted on /; on-line resizing required old desc_blocks = 1, new_desc_blocks = 2 Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 6448128 (4k) blocks. The filesystem on /dev/mapper/VolGroup-lv_root is now 6448128 blocks long.
查看磁盘状况
# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 25G 1.8G 22G 8% / tmpfs 233M 0 233M 0% /dev/shm /dev/sda2 485M 44M 416M 10% /boot
创建/dev/sdb1的过程是多余的,pvcreate可以直接从物理盘创建pv,即pvcreate /dev/sdb就OK了。
貌似这个脚本已经下载不了了,可以提供在博客里提供下下载吗?
google搜索 rescan-scsi-bus.sh,估计能找到。