LVM管理扩充/缩减分区
#lvs 查看lvm
#pvcreate /dev/sda4 创建pv
Physical volume "/dev/sda4" successfully created
[root@localhost ~]# vgextend VolGroup00 /dev/sda4
(将创建的pv加入vg VolGroup00是当前需要扩充的vg名,通过vgdisplay显示vg)
Physical volume "/dev/sda4" successfully created
Volume group "VolGroup00" successfully extended
[root@localhost ~]# vgdisplay 查看vg
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 13.88 GB
PE Size 32.00 MB
Total PE 444
Alloc PE / Size 312 / 9.75 GB
Free PE / Size 132 / 4.12 GB
VG UUID 1tWPvj-N1a5-T7uQ-yXqG-oAbB-MP4z-5k0bEe
(主要查看 Free PE / Size 132 / 4.12 GB ,说明我们最多可以有4.12G的扩充空间。一般选择小于4.12G)
[root@localhost ~]# lvextend -L +4.11G /dev/VolGroup00/LogVol00 /dev/sda4
(如果没有“+” 则表示增加到的数值,比如lvextend -L 20G....,则此lv就设置为20G 而不是增加20G)
/dev/hdc: open failed: 找不到介质
Rounding up size to full physical extent 4.12 GB
Extending logical volume LogVol00 to 13.88 GB
Logical volume LogVol00 successfully resized
(做fsck,检查文件系统)
e2fsck -a /dev/VolGroup00/LogVol00
重新加载逻辑卷的大小使其生效。需要使用resize2fs命令将文件系统扩展到增加的空间上:
[root@turbolinux ~]# resize2fs /dev/VolGroup00/LogVol00 (lv path)
注:如果是xfs的文件系统 用 xfs_growfs /dev/VolGroup00/LogVol00
#df -h 查看一下你的系统磁盘空间"/"目录是否增加
缩减lv大小
[root@localhost ~]# lvreduce -L -1G /dev/VolGroup00/LogVol01
/dev/hdc: open failed: 找不到介质
WARNING: Reducing active and open logical volume to 2.91 GB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce LogVol01? [y/n]: y
Reducing logical volume LogVol01 to 2.91 GB
Logical volume LogVol01 successfully resized
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 7
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 49.88 GB
PE Size 32.00 MB
Total PE 1596
Alloc PE / Size 1564 / 48.88 GB
Free PE / Size 32 / 1.00 GB
VG UUID JeJ3dU-sKI6-Pvfw-2ddT-CLnC-fy3O-ywVc0Z
增加硬盘(磁盘挂在)
[root@localhost ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 2088.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): m 列出fdisk的帮助
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 命令n用于添加新分区
Command action
e extended
p primary partition (1-4)
p 这里命令p选择创建主分区
Selected partition 4
First cylinder (1550-2088, default 1550):
Using default value 1550
Last cylinder or +size or +sizeM or +sizeK (1550-2088, default 2088):
Using default value 2088
Command (m for help): t 命令t改变主分区的ID
Partition number (1-4): 4 fdisk会让你选择主分区的编号,如果已经有了主分区sda1,sda2,这里选4,即要创建的该分区为sda4
Hex code (type L to list codes): 8e 指定要改成的id号,8e代表LVM
Changed system type of partition 4 to 8e (Linux LVM)
Command (m for help): p 打印分区表
Disk /dev/sda: 17.1 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 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 1288 10241437+ 8e Linux LVM
/dev/sda3 1289 1549 2096482+ 82 Linux swap / Solaris
/dev/sda4 1550 2088 4329517+ 8e Linux LVM
Command (m for help): w 命令w保存
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@oracle ~]# fdisk -l
Disk /dev/sda: 17.1 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 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 1288 10241437+ 8e Linux LVM
/dev/sda3 1289 1549 2096482+ 82 Linux swap / Solaris
/dev/sda4 1550 2088 4329517+ 8e Linux LVM
格式化分区 mkfs -t ext3 /dev/sda4
[root@localhost ~]# mkfs -t ext3 /dev/sda4
mke2fs 1.39 (29-May-2006)
The device apparently does not exist; did you specify it correctly?
(此处需重启,增加硬盘则不用重启)
[root@localhost ~]# mkfs -t ext3 /dev/sda4
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
541824 inodes, 1082379 blocks
54118 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1111490560
34 block groups
32768 blocks per group, 32768 fragments per group
15936 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
转载请注明:梦绘设计 » linux服务 » linux LVM管理扩充/缩减分区
版权声明
本站《作品展示》类文章均为原创,转载必须注明出处,技术分享类文章部分来源于网络,版权归原作者所有,若侵权请留言。