virtualbox vdi和filesystem的扩容
virtualbox 下的 centos6 空间满了
[root@centos6 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
6.5G 6.5G 0 100% /
tmpfs 625M 0 625M 0% /dev/shm
/dev/sda1 477M 29M 424M 7% /boot
【解决方案】
virtualbox 有一个工具叫 VBoxmanage
我们可以在CMD中,使用这个工具调整vdi文件的大小,同时找到vid文件的位置
扩容命令如下:VBoxmanage modifyhd vdi文件 --resize 大小(Mbyte)
2秒不到,便从8G变为15G了
既然加大了硬盘空间,接着就得让linux filesystem识别,这需要一个linux版本的分区助手: disk partition manager 可以通过命令安装
yum install gparted
因为gparted是图形界面工具,所以我们把centos切换成图形界面
init 5
接着大开一个terminal启动gparted,命令刚好就是gparted
可以看到unallocated黑色部分就是还没有分配的空间
[root@centos6 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
6.5G 6.5G 0 100% /
tmpfs 625M 0 625M 0% /dev/shm
/dev/sda1 477M 29M 424M 7% /boot
这个分区/dev/mapper/VolGroup-lv_root写法的意思是. root分区是"逻辑分区lv(logical volume)" , 而这个逻辑分区属于"volGroup卷用户组“这个大家庭的,volGroup的全称是volume group(vg),可以被切割成很多个可以弹性伸缩的”lv逻辑分区“,使用fdisk -l可以看到这块大的volume group切分出两个
1./dev/mapper/VolGroup-lv_root
2./dev/VolGroup/lv_swap
[root@centos6 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/VolGroup/lv_root
LV Name lv_root
VG Name VolGroup
LV UUID kUI3F2-mQi4-Tuor-5cDv-Ds2Z-NOti-0GEim5
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2015-12-18 11:12:06 +0800
LV Status available
# open 1
LV Size 6.71 GiB
Current LE 1718
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/VolGroup/lv_swap
LV Name lv_swap
VG Name VolGroup
LV UUID IBGEKO-R4zR-1bw9-lUjh-0647-XjZ7-rZHglC
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2015-12-18 11:12:11 +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
用图标可以这样表示
在gparted上,我们清楚知道 /dev/sda2 是对应 volume group的
如果不用gparted,我们怎么知道volume group是来源于哪个physical volume呢?可以使用命令:pvdisplay
[root@centos6 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup
PV Size 7.51 GiB / not usable 1.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 3603
Free PE 1681
Allocated PE 1922
PV UUID KDRXxB-j3qx-gzN0-d6Zb-vmcX-GtiF-Wfrt4Y
所以我想要增加lvm2 pv的容量,但是有一个锁的图标,表示不能动,因为那个分区正在使用中,官方文档如是说
Partition operations such as delete, move, copy, format, check, label, and often resize require the partition to be unmounted.
为了不让/dev/sda2分区使用,就换一种操作系统的启动方式,好比使用老毛桃的PE来启动centos,gparted也有这个功能,重新到官网下载ISO版本,有点大250MB,使用方法和安装centos的iso文件,把光盘设置成第一启动方式,把VDI文件设置成第二启动方式
启动后会出现一个很丑陋的界面
因为没有PE系统,没有使用里面任何一块分区,所以可以对他们进行扩容,甚至删除,用鼠标拖动大小即可
完了以后退出,把光盘的第一启动方式删除掉即可,重新进入系统
[root@centos6 ~]# fdisk -l
Disk /dev/sda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 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: 0x0006d4bf
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 1902 14758912 8e Linux LVM
Disk /dev/mapper/VolGroup-lv_root: 7205 MB, 7205814272 bytes
255 heads, 63 sectors/track, 876 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: 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
这里显示第一块硬盘/dev/sda已经变成了16G了,但是文件系统的大小还是一样没有变化
[root@centos6 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
6.5G 6.1G 85M 99% /
tmpfs 625M 0 625M 0% /dev/shm
/dev/sda1 477M 29M 424M 7% /boot
这是因为办事要按流程,而这个流程是
1.增加硬盘的容量(virtualbox通过modifyhd办到了)
2.增加volume group的容量(通过gparted增大了/dev/sda2容量,实质就是增大了volume group容量)
3.增加从volume group 切分出来的 logical volume 容量
4.增加 logical volume 上的filesystem 容量
咱们只完成了第一步,所以filesytem的容量依旧没有变化
第2步,检查一下volume group容量是否增大了
[root@centos6 ~]# vgdisplay
--- Volume group ---
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 1
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 1
Act PV 1
VG Size 14.07 GiB
PE Size 4.00 MiB
Total PE 3603
Alloc PE / Size 1922 / 7.51 GiB
Free PE / Size 1681 / 6.57 GiB
VG UUID ZHa3HN-rMUw-GSr9-U4ie-x1Zm-seHb-KXtKf2
第3步,检查一下logical volume容量是否有增大了
[root@centos6 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/VolGroup/lv_root
LV Name lv_root
VG Name VolGroup
LV UUID kUI3F2-mQi4-Tuor-5cDv-Ds2Z-NOti-0GEim5
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2015-12-18 11:12:06 +0800
LV Status available
# open 1
LV Size 6.71 GiB
Current LE 1718
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/VolGroup/lv_swap
LV Name lv_swap
VG Name VolGroup
LV UUID IBGEKO-R4zR-1bw9-lUjh-0647-XjZ7-rZHglC
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2015-12-18 11:12:11 +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
依然是6.7G,所以我们需要的是增加logical volume的容量
[root@centos6 ~]# lvextend -L12G /dev/mapper/VolGroup-lv_root
Size of logical volume VolGroup/lv_root changed from 6.71 GiB (1718 extents) to 12.00 GiB (3072 extents).
Logical volume lv_root successfully resized
这时我们完成了第三步,逻辑分区(logical volume)加大了,然而在lv上面的fileystem还是没有变化
[root@centos6 ~]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
6.5G 6.1G 75M 99% /
tmpfs 625M 0 625M 0% /dev/shm
/dev/sda1 477M 29M 424M 7% /boot
我们首先要确认 /dev/mapper/VolGroup-lv_root这个逻辑分区上的filesytem是什么类型的?是ext4还是ext3?还是xfs?因为不同的file system类型扩容的方式不同
[root@centos6 ~]# df --help
Usage: df [OPTION]... [FILE]...
Show information about the file system on which each FILE resides,
or all file systems by default.
Mandatory arguments to long options are mandatory for short options too.
-a, --all include dummy file systems
-B, --block-size=SIZE use SIZE-byte blocks
--direct show statistics for a file instead of mount point
--total produce a grand total
-h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)
-H, --si likewise, but use powers of 1000 not 1024
-i, --inodes list inode information instead of block usage
-k like --block-size=1K
-l, --local limit listing to local file systems
--no-sync do not invoke sync before getting usage info (default)
-P, --portability use the POSIX output format
--sync invoke sync before getting usage info
-t, --type=TYPE limit listing to file systems of type TYPE
-T, --print-type print file system type
-x, --exclude-type=TYPE limit listing to file systems not of type TYPE
-v (ignored)
--help display this help and exit
--version output version information and exit
[root@centos6 ~]# df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root
ext4 6795192 6367072 76276 99% /
tmpfs tmpfs 639164 0 639164 0% /dev/shm
/dev/sda1 ext4 487652 28684 433368 7% /boot
我们知道它是ext4类型的
[root@centos6 mysql]# 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 = 1
Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 3145728 (4k) blocks.
The filesystem on /dev/mapper/VolGroup-lv_root is now 3145728 blocks long.
在这里也普及一下block这个概念,中文翻译是”块“,上面写着1 block = 4K ,可以得出block是有4kB组成的,但也可以是1kB组成的
[root@centos7 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/centos-root 7022592 4890768 2131824 70% /
devtmpfs 498344 0 498344 0% /dev
tmpfs 508428 0 508428 0% /dev/shm
tmpfs 508428 6684 501744 2% /run
tmpfs 508428 0 508428 0% /sys/fs/cgroup
/dev/sda1 508588 149180 359408 30% /boot
tmpfs 101688 0 101688 0% /run/user/0
在file系统调整大小的时候,默认也是用block做单位的,那block的定义是什么呢?
In computing (specifically data transmission and data storage), a block, sometimes called a physical record, is a sequence of bytes or bits, usually containing some whole number of records, having a maximum length, a block size.[1]