ubuntu下扩展LVM磁盘的方法分享

本文介绍下,在ubuntu中扩展LVM磁盘的具体方法,有需要的朋友参考下吧。

当LV空间利用率较大即将耗尽LV空间时,可以将一块新的磁盘或一块磁盘上的/空间加入LV中。

现在/ 空间如下:

代码示例:

root@ubuntu :~# df -h文件系统??????????? 容量? 已用 可用 已用% 挂载点/dev/mapper/ubuntu-root4.5G? 792M? 3.5G? 19% /none????????????????? 244M? 224K? 243M?? 1% /devnone????????????????? 249M? 4.0K? 249M?? 1% /dev/shmnone????????????????? 249M?? 36K? 249M?? 1% /var/runnone????????????????? 249M???? 0? 249M?? 0% /var/locknone????????????????? 249M???? 0? 249M?? 0% /lib/init/rw/dev/sda1???????????? 228M?? 19M? 198M?? 9% /boot

查看磁盘状态:

代码示例:

root@ubuntu :~# fdisk -lDisk /dev/sda: 5368 MB, 5368709120 bytes255 heads, 63 sectors/track, 652 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x0000d2ec

Device Boot????? Start???????? End????? Blocks?? Id? System/dev/sda1?? *?????????? 1????????? 32????? 248832?? 83? LinuxPartition 1 does not end on cylinder boundary./dev/sda2????????????? 32???????? 653???? 4990977??? 5? ExtendedPartition 2 does not end on cylinder boundary./dev/sda5????????????? 32???????? 653???? 4990976?? 8e? Linux?LVM

Disk /dev/sdb: 4294 MB, 4294967296 bytes255 heads, 63 sectors/track, 522 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk 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 actione?? extendedp?? primary partition (1-4)p???????????????? \\创建主分区Partition number (1-4): 1First cylinder (1-522, default 1):? \\默认值Using default value 1Last 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 bytes255 heads, 63 sectors/track, 522 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x542e4b15

Device Boot????? Start???????? End????? Blocks?? Id? System/dev/sdb1?????????????? 1???????? 522???? 4192933+? 83? Linux

Command (m for help): t? \\改变分区类型Selected partition 1Hex 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? \\创建新的PVPhysical 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?????????????? ubuntuSystem IDFormat??????????????? lvm2Metadata Areas??????? 1Metadata Sequence No? 3VG Access???????????? read/writeVG Status???????????? resizableMAX LV??????????????? 0Cur LV??????????????? 2Open LV?????????????? 2Max PV??????????????? 0Cur PV??????????????? 1Act PV??????????????? 1VG Size?????????????? 4.76 GiBPE Size?????????????? 4.00 MiBTotal PE????????????? 1218Alloc PE / Size?????? 1215 / 4.75 GiBFree? PE / Size?????? 3 / 12.00 MiBVG 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/rootVG Name??????????????? ubuntuLV UUID??????????????? ig0Es7-8tMQ-Uyiq-szHY-V8b0-pnC1-1lFyKnLV Write Access??????? read/writeLV Status????????????? available# open???????????????? 1LV Size??????????????? 4.49 GiBCurrent LE???????????? 1149

root@ubuntu :~# lvextend -L +4G? /dev/ubuntu/root // 将VG组中的free空间4G加到/分区所在的LVExtending logical volume root to 8.49 GiBLogical volume root successfully resized

5. 使用resizefs2命令重新加载逻辑卷的大小才能生效

代码示例:

root@ubuntu :~# resize2fs /dev/ubuntu/rootresize2fs 1.41.11 (14-Mar-2010)Filesystem at /dev/ubuntu/root is?mounted on /; on-line resizing requiredold desc_blocks = 1, new_desc_blocks = 1Performing an on-line resize of /dev/ubuntu/root to 2225152 (4k) blocks.The filesystem on /dev/ubuntu/root is now 2225152 blocks long.

6.查看增加空间后的/空间

代码示例:

root@ubuntu :~# df -h文件系统??????????? 容量? 已用 可用 已用% 挂载点/dev/mapper/ubuntu-root8.4G? 793M? 7.2G? 10% /none????????????????? 244M? 228K? 243M?? 1% /devnone????????????????? 249M? 4.0K? 249M?? 1% /dev/shmnone????????????????? 249M?? 36K? 249M?? 1% /var/runnone????????????????? 249M???? 0? 249M?? 0% /var/locknone????????????????? 249M???? 0? 249M?? 0% /lib/init/rw/dev/sda1???????????? 228M?? 19M? 198M?? 9% /boot

现在发现/ 分区已变大。

以上介绍了,在ubuntu下对即将用尽的LVM磁盘扩容的方法,希望对大家有所帮助。

原文:http://www.jbxue.com/LINUXjishu/10305.html

ubuntu下扩展LVM磁盘的方法分享

相关文章:

你感兴趣的文章:

标签云: