本文介绍下,在ubuntu中扩展LVM磁盘的具体方法,有需要的朋友参考下吧。
当LV空间利用率较大即将耗尽LV空间时,可以将一块新的磁盘或一块磁盘上的/空间加入LV中。
现在/ 空间如下:
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/ubuntu-root
4.5G 792M 3.5G 19% /
none 244M 224K 243M 1% /dev
none 249M 4.0K 249M 1% /dev/shm
none 249M 36K 249M 1% /var/run
none 249M 0 249M 0% /var/lock
none 249M 0 249M 0% /lib/init/rw
/dev/sda1 228M 19M 198M 9% /boot
查看磁盘状态:
root@ubuntu :~# fdisk -l
Disk /dev/sda: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 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: 0x0000d2ec
Device Boot Start End Blocks Id System
/dev/sda1 * 1 32 248832 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 32 653 4990977 5 Extended
Partition 2 does not end on cylinder boundary.
/dev/sda5 32 653 4990976 8e Linux LVM
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 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: 0×00000000
Disk /dev/sdb doesn’t contain a valid partition table
1. 新建LVM类型分区:
root@ubuntu :~# fdisk /dev/sdb \\对硬盘sdb进行分区
Command (m for help): n \\创建新的分区
Command action
e extended
p primary partition (1-4)
p \\创建主分区
Partition number (1-4): 1
First cylinder (1-522, default 1): \\默认值
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-522, default 522): \\默认值
Using default value 522
Command (m for help): p //查看当前分区
Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 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: 0x542e4b15
Device Boot Start End Blocks Id System
/dev/sdb1 1 522 4192933+ 83 Linux
Command (m for help): t \\改变分区类型
Selected partition 1
Hex code (type L to list codes): 8e \\更改为LVM类型分区
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): w \\ 保持退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
2.创建新的PV
root@ubuntu :~# partprobe \\使用partprobe指令更新内核的中硬盘分区表
root@ubuntu :~# pvcreate /dev/sdb1 \\创建新的PV
Physical volume “/dev/sdb1″ successfully created
root@ubuntu :~# pvscan \\新创建的PV但是尚未加入任何VG组
PV /dev/sda5 VG ubuntu lvm2 [4.76 GiB / 12.00 MiB free]
PV /dev/sdb1 lvm2 [4.00 GiB]
Total: 2 [8.76 GiB] / in use: 1 [4.76 GiB] / in no VG: 1 [4.00 GiB]
3. 将PV加入VG组中
root@ubuntu :~# vgdisplay //查看VG组的详细信息
— Volume group —
VG Name ubuntu
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 4.76 GiB
PE Size 4.00 MiB
Total PE 1218
Alloc PE / Size 1215 / 4.75 GiB
Free PE / Size 3 / 12.00 MiB
VG UUID jeRoTV-fYcT-e5qf-N2rk-m6Ky-eH1W-NSRm1s
root@ubuntu :~# vgextend ubuntu /dev/sdb1 //添加磁盘到VG组
Volume group “ubuntu” successfully extended
root@ubuntu :~# pvscan // /dev/sdb1加入到ubuntu组中
PV /dev/sda5 VG ubuntu lvm2 [4.76 GiB / 12.00 MiB free]
PV /dev/sdb1 VG ubuntu lvm2 [4.00 GiB / 4.00 GiB free]
Total: 2 [8.75 GiB] / in use: 2 [8.75 GiB] / in no VG: 0 [0 ]
4.将VG组中的free空间划出4G到/分区所在的LV
root@ubuntu :~# lvdisplay //查看LV Name
— Logical volume —
LV Name /dev/ubuntu/root
VG Name ubuntu
LV UUID ig0Es7-8tMQ-Uyiq-szHY-V8b0-pnC1-1lFyKn
LV Write Access read/write
LV Status available
# open 1
LV Size 4.49 GiB
Current LE 1149
root@ubuntu :~# lvextend -L +4G /dev/ubuntu/root // 将VG组中的free空间4G加到/分区所在的LV
Extending logical volume root to 8.49 GiB
Logical volume root successfully resized
5. 使用resizefs2命令重新加载逻辑卷的大小才能生效
resize2fs 1.41.11 (14-Mar-2010)
Filesystem at /dev/ubuntu/root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/ubuntu/root to 2225152 (4k) blocks.
The filesystem on /dev/ubuntu/root is now 2225152 blocks long.
6.查看增加空间后的/空间
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/ubuntu-root
8.4G 793M 7.2G 10% /
none 244M 228K 243M 1% /dev
none 249M 4.0K 249M 1% /dev/shm
none 249M 36K 249M 1% /var/run
none 249M 0 249M 0% /var/lock
none 249M 0 249M 0% /lib/init/rw
/dev/sda1 228M 19M 198M 9% /boot
现在发现/ 分区已变大。
以上介绍了,在ubuntu下对即将用尽的LVM磁盘扩容的方法,希望对大家有所帮助。
原文:http://www.jbxue.com/LINUXjishu/10305.html