原 : 20g 磁盘 使用centos默认分区 创建的逻辑卷信息如下
pv
[root@test ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 vg_centos lvm2 a-- 19.51g 0
vg
[root@test ~]# vgs VG #PV #LV #SN Attr VSize VFree vg_centos 1 2 0 wz--n- 19.51g 0
lv
[root@test ~]# lvs LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert lv_root vg_centos -wi-ao--- 17.57g lv_swap vg_centos -wi-ao--- 1.94g
添加一块20g新磁盘后扩展root分区
操作如下
查看新添磁盘
[root@test ~]# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 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: 0x000c3d64 Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 2611 20458496 8e Linux LVM Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 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/vg_centos-lv_root: 18.9 GB, 18865979392 bytes 255 heads, 63 sectors/track, 2293 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/vg_centos-lv_swap: 2080 MB, 2080374784 bytes 255 heads, 63 sectors/track, 252 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
对新添磁盘分区(使用所有空间也可直接使用整个磁盘 不用分区)
[root@test ~]# 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 0xb996e29b. 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-2610, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): Using default value 2610 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
添加新加磁盘为pv
[root@test ~]# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created
扩展vg_centos
[root@test ~]# vgextend vg_centos /dev/sdb1 Volume group "vg_centos" successfully extended
扩展lv_root
[root@test ~]# lvextend -l +100%FREE /dev/vg_centos/lv_root Extending logical volume lv_root to 37.56 GiB Logical volume lv_root successfully resized
查看lv
[root@test ~]# lvs LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert lv_root vg_centos -wi-ao--- 37.56g lv_swap vg_centos -wi-ao--- 1.94g
查看根分区所剩空间
[root@test ~]# df -h 文件系统 容量 已用 可用 已用%% 挂载点 /dev/mapper/vg_centos-lv_root 18G 1.1G 16G 7% / tmpfs 932M 0 932M 0% /dev/shm /dev/sda1 485M 32M 428M 7% /boot
发现跟分区未变大 使用resize2fs 识别新添空间
[root@test ~]# resize2fs /dev/mapper/vg_centos-lv_root resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/mapper/vg_centos-lv_root is mounted on /; on-line resizing required old desc_blocks = 2, new_desc_blocks = 3 Performing an on-line resize of /dev/mapper/vg_centos-lv_root to 9846784 (4k) blocks. The filesystem on /dev/mapper/vg_centos-lv_root is now 9846784 blocks long. [root@test ~]# df -h 文件系统 容量 已用 可用 已用%% 挂载点 /dev/mapper/vg_centos-lv_root 37G 1.1G 35G 3% / tmpfs 932M 0 932M 0% /dev/shm /dev/sda1 485M 32M 428M 7% /boot
lvm 缩小:http://my.oschina.net/firxiao/blog/387397