Linux上增加硬盘和文件目录的大小
通过扩展Volume Group、Logical Volume来达到扩展文件系统的大小,
?
我的服务器是建在虚机上的,
?
分配硬盘空间时,通过修改参数把原来硬盘加大的。
?
[root@localhost ~]# fdisk -l
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
?? Device Boot????? Start???????? End????? Blocks?? Id? System
/dev/sda1?? *?????????? 1????????? 13????? 104391?? 83? Linux
/dev/sda2????????????? 14??????? 1044???? 8281507+? 8e? Linux LVM
先创建物理分区
#fdisk /dev/sda
?
通n键,创建一个主分区;
通t键,输入8e转换为LVM分区?
w键,写入分区表
Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
?? Device Boot????? Start???????? End????? Blocks?? Id? System
/dev/sda1?? *?????????? 1????????? 13????? 104391?? 83? Linux
/dev/sda2????????????? 14??????? 1044???? 8281507+? 8e? Linux LVM
/dev/sda3??????????? 1045??????? 3916??? 23069340?? 8e? Linux LVM
?
?
重启生效,然后创建物理卷(physical volume)
?
#pvcreate /dev/sda3
? Physical volume "/dev/sda3" successfully created
?
查看现有的vg
?
#vgdisplay
?
? --- Volume group ---
VG Name?????????????? VolGroup00
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?????????????? 7.88 GB
PE Size?????????????? 32.00 MB
Total PE????????????? 252
Alloc PE / Size?????? 250 / 7.81 GB
Free? PE / Size?????? 2 / 64.00 MB
VG UUID?????????????? Zv74Nv-kqbn-SpF3-yBcg-brXn-2X0G-5mbJcx
通过vgextend命令扩展现有的vg
?
#vgextend? VolGroup00 /dev/sda3
?? Volume group "VolGroup00" successfully extended
?
#vgdisplay
?
? --- Volume group ---
VG Name?????????????? VolGroup00
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.88 GB
PE Size?????????????? 32.00 MB
Total PE????????????? 956
Alloc PE / Size?????? 250 / 7.81 GB
Free? PE / Size?????? 706 / 22.06 GB
VG UUID?????????????? Zv74Nv-kqbn-SpF3-yBcg-brXn-2X0G-5mbJcx
?
?
#mount
?
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)
none on /proc type proc (rw)
none on /sys type sysfs (rw)
none on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
none on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
可以看到文件系统的 / 是挂载在/dev/mapper/VolGroup00-LogVol00上的,
因此,通过改变lv LogVol00的大小来达到给/增减空间的目的。
?
# lvscan
ACTIVE??????????? '/dev/VolGroup00/LogVol00' [5.88 GB] inherit
ACTIVE??????????? '/dev/VolGroup00/LogVol01' [1.94 GB] inherit
通过lvresize命令扩展Logical Volume
?
# lvresize -L +22.06G /dev/VolGroup00/LogVol00
Rounding up size to full physical extent 22.06 GB
Extending logical volume LogVol00 to 27.94 GB
Logical volume LogVol00 successfully resized
调整完后,查看一下文件系统使用情况
#df -h?
?
Filesystem??????????? Size? Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
5.8G? 3.5G? 2.1G? 63% /
/dev/sda1????????????? 99M?? 14M?? 81M? 14% /boot
none????????????????? 506M???? 0? 506M?? 0% /dev/shm
发现并没有没发生改变
?
通过ext2online命令在线resize文件系统
或者该命令如果不存在,可以使用resize2fs
#ext2online /dev/mapper/VolGroup00-LogVol00
?
#df -h
?
Filesystem??????????? Size? Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
28G? 3.5G?? 23G? 14% /
/dev/sda1????????????? 99M?? 14M?? 81M? 14% /boot
none????????????????? 506M???? 0? 506M?? 0% /dev/shm
大小调整成功!
?
检查分区
#e2fsck /dev/VolGroup00/LogVol00