1.问题
linux使用逻辑卷管理磁盘空间,现在磁盘空间不足:
[root@test1 log]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_test1-lv_root 16G 15G 16M 100% /
tmpfs 499M 224K 498M 1% /dev/shm
/dev/sda1 485M 35M 426M 8% /boot
2.确认
[root@test1 log]# lvdisplay #确认vg_test1-lv_root确认是逻辑卷
--- Logical volume ---
LV Path /dev/vg_test1/lv_root
LV Name lv_root
VG Name vg_test1
LV UUID Kvt5rT-03rj-dnfn-kpNA-1Ham-ZPzh-kuBAO9
LV Write Access read/write
LV Creation host, time test1, 2016-05-11 10:56:46 +0800
LV Status available
# open 1
LV Size 15.71 GiB
Current LE 4022
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/vg_test1/lv_swap
LV Name lv_swap
VG Name vg_test1
LV UUID aeULjI-OeNe-eNjr-iGE0-Wz2O-4bXA-3Kb8n4
LV Write Access read/write
LV Creation host, time test1, 2016-05-11 10:56:47 +0800
LV Status available
# open 1
LV Size 816.00 MiB
Current LE 204
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
3.加磁盘
[root@test1 log]# shutdown -h now
Broadcast message from root@test1
(/dev/pts/2) at 6:19 ...
The system is going down for halt NOW!
这里用的是Oracle VM VirtualBox,加块磁盘如下:
设置->存储->控制器 SATA->添加 虚拟 磁盘->创建新的虚拟盘->类型选VDI->动态分配大小->起个名字,调整好大小,点创建->启动虚拟机
[root@test1 ~]# fdisk -l #看一下有没有新加的磁盘
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 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: 0x00093d66
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 1045 7875584 8e Linux LVM
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0xb7312e9f
Device Boot Start End Blocks Id System
/dev/sdb1 1 1305 10482381 83 Linux
Disk /dev/sdc: 8589 MB, 8589934592 bytes #这就是我们刚加的磁盘,大小8G
255 heads, 63 sectors/track, 1044 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_test1-lv_root: 16.9 GB, 16869490688 bytes
255 heads, 63 sectors/track, 2050 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_test1-lv_swap: 855 MB, 855638016 bytes
255 heads, 63 sectors/track, 104 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@test1 ~]# fdisk /dev/sdc #分区
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x27410e25.
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-1044, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044):
Using default value 1044
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@test1 ~]# fdisk -l #验证一下,这时会看到分区/dev/sdc1
4.扩展空间
[root@test1 ~]# pvcreate /dev/sdc1 #创建物理卷
Physical volume "/dev/sdc1" successfully created
[root@test1 ~]# pvdisplay #验证
PV VG Fmt Attr PSize PFree
/dev/sda2 vg_test1 lvm2 a-- 7.51g 0
/dev/sdb1 vg_test1 lvm2 a-- 9.99g 1016.00m
/dev/sdc1 lvm2 a-- 8.00g 8.00g
[root@test1 ~]# lvs #确认要扩展空间的逻辑卷所属的卷组
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
lv_root vg_test1 -wi-ao---- 15.71g
lv_swap vg_test1 -wi-ao---- 816.00m
[root@test1 ~]# vgextend vg_test1 /dev/sdc1 #扩展卷
Volume group "vg_test1" successfully extended
[root@test1 ~]# vgs #验证
VG #PV #LV #SN Attr VSize VFree
vg_test1 3 2 0 wz--n- 25.50g 8.99g
[root@test1 ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
lv_root vg_test1 -wi-ao---- 15.71g
lv_swap vg_test1 -wi-ao---- 816.00m
[root@test1 ~]# lvextend -L +8.99g /dev/vg_test1/lv_root
Rounding size to boundary between physical extents: 8.99 GiB
Extending logical volume lv_root to 24.70 GiB
Insufficient free space: 2302 extents needed, but only 2301 available #报错,因为加大了
[root@test1 ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
lv_root vg_test1 -wi-ao---- 15.71g #没加成功
lv_swap vg_test1 -wi-ao---- 816.00m
[root@test1 ~]# lvextend -L +8.90g /dev/vg_test1/lv_root
Rounding size to boundary between physical extents: 8.90 GiB
Extending logical volume lv_root to 24.61 GiB
Logical volume lv_root successfully resized
[root@test1 ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
lv_root vg_test1 -wi-ao---- 24.61g #加成功
lv_swap vg_test1 -wi-ao---- 816.00m
[root@test1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_test1-lv_root 16G 15G 18M 100% / #大小没变,需要resize下逻辑卷才行
tmpfs 499M 72K 499M 1% /dev/shm
/dev/sda1 485M 35M 426M 8% /boot
[root@test1 ~]# resize2fs /dev/vg_test1/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_test1/lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/vg_test1/lv_root to 6452224 (4k) blocks.
The filesystem on /dev/vg_test1/lv_root is now 6452224 blocks long.
[root@test1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_test1-lv_root 25G 15G 8.4G 64% / #OK,加空间完成。
tmpfs 499M 72K 499M 1% /dev/shm
/dev/sda1 485M 35M 426M 8% /boot
[root@test1 ~]#