lvm扩展根目录

1.lvm的基本概念

physical volume (PV)

通常是一快硬盘。相当于一个物理设备,磁盘空间物理卷PV。

volume group (VG)

相当于LVM的卷组,属于一个抽象下的组概念,一个VG可以包括多个PV。我的实操是我的VG下面,包含了PV(/dev/sda5)和PV(/dev/sdb1)如下:

root@ubuntudoc:~# pvdisplay
--- Physical volume ---
PV Name /dev/sda5
VG Name ubuntudoc-vg
PV Size 49.76 GiB / not usable 2.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 12738
Free PE 0
Allocated PE 12738
PV UUID ADh3K6-fjVA-5lLY-9vzu-eIxe-utiL-pOYtZa --- Physical volume ---
PV Name /dev/sdb1
VG Name ubuntudoc-vg
PV Size 16.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4095
Free PE 0
Allocated PE 4095
PV UUID 2RwFCw-lLul-8CIf-gHvb-0rC1-U0aG-SfHZGd root@ubuntudoc:~# pvs
PV VG Fmt Attr PSize PFree
/dev/sda5 ubuntudoc-vg lvm2 a-- 49.76g 0
/dev/sdb1 ubuntudoc-vg lvm2 a-- 16.00g 0

logical volume (LV)

LV简单的理解是可以挂载到分区下的磁盘空间了。如下 :根分区/下的空间,代表着root这个lv。

root@ubuntudoc:~# lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
root ubuntudoc-vg -wi-ao--- 53.76g
swap_1 ubuntudoc-vg -wi-ao--- 12.00g

2.lvm扩展根目录分区的实战

2.1 设置硬盘/dev/sdb为linux lvm

先决条件:在vmware虚拟化平台下,我先添加了一块/dev/sdb的硬盘,并把硬盘设置为linux lvm,操作如下:

root@ubuntudoc:~# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x502d7728.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) Command (m for help): p Disk /dev/sdb: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders, total 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x502d7728 Device Boot Start End Blocks Id System Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-33554431, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-33554431, default 33554431):
Using default value 33554431 Command (m for help): p Disk /dev/sdb: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders, total 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x502d7728 Device Boot Start End Blocks Id System
/dev/sdb1 2048 33554431 16776192 83 Linux Command (m for help): t
Selected partition 1
Hex code (type L to list codes): L 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM) Command (m for help): p Disk /dev/sdb: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 cylinders, total 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x502d7728 Device Boot Start End Blocks Id System
/dev/sdb1 2048 33554431 16776192 8e Linux LVM Command (m for help): wq
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.

2.2 把pv(/dev/sb1)添加至vg中。

命令如下:

root@ubuntudoc:~# vgs
VG #PV #LV #SN Attr VSize VFree
ubuntudoc-vg 1 2 0 wz--n- 49.76g 32.00m root@ubuntudoc:~# vgextend ubuntudoc-vg /dev/sdb1
No physical volume label read from /dev/sdb1
Physical volume "/dev/sdb1" successfully created
Volume group "ubuntudoc-vg" successfully extended root@ubuntudoc:~# vgs
VG #PV #LV #SN Attr VSize VFree
ubuntudoc-vg 2 2 0 wz--n- 65.75g 16.03g

上述结果,可以看出ubuntudoc-vg添加至65GB了。

2.3 vg中空闲的空间加入lv中

命令如下:

root@ubuntudoc:~# lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
root ubuntudoc-vg -wi-ao--- 37.73g
swap_1 ubuntudoc-vg -wi-ao--- 12.00g root@ubuntudoc:~# lvextend --help
lvextend: Add space to a logical volume lvextend
[-A|--autobackup y|n]
[--alloc AllocationPolicy]
[-d|--debug]
[-f|--force]
[-h|--help]
[-i|--stripes Stripes [-I|--stripesize StripeSize]]
{-l|--extents [+]LogicalExtentsNumber[%{VG|LV|PVS|FREE|ORIGIN}] |
-L|--size [+]LogicalVolumeSize[bBsSkKmMgGtTpPeE]}
[-m|--mirrors Mirrors]
[--nosync]
[--use-policies]
[-n|--nofsck]
[--noudevsync]
[-r|--resizefs]
[-t|--test]
[--type VolumeType]
[-v|--verbose]
[--version]
LogicalVolume[Path] [ PhysicalVolumePath... ] root@ubuntudoc:~# lvextend -l +100%free /dev/ubuntudoc-vg/root (100%剩余的空闲空间全部给与root的lv)
Extending logical volume root to 53.76 GiB
Logical volume root successfully resized
root@ubuntudoc:~# lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
root ubuntudoc-vg -wi-ao--- 53.76g
swap_1 ubuntudoc-vg -wi-ao--- 12.00g

2.4 根分区识别空闲的磁盘空间

操作如下:

root@ubuntudoc:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 989M 4.0K 989M 1% /dev
tmpfs 200M 712K 200M 1% /run
/dev/dm-0 38G 2.6G 33G 8% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 5.0M 0 5.0M 0% /run/lock
none 1000M 0 1000M 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/sda1 236M 40M 184M 18% /boot root@ubuntudoc:~# resize2fs /dev/ubuntudoc-vg/root
resize2fs 1.42.9 (4-Feb-2014)
Filesystem at /dev/ubuntudoc-vg/root is mounted on /; on-line resizing required
old_desc_blocks = 3, new_desc_blocks = 4
The filesystem on /dev/ubuntudoc-vg/root is now 14092288 blocks long. root@ubuntudoc:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 989M 4.0K 989M 1% /dev
tmpfs 200M 712K 200M 1% /run
/dev/dm-0 53G 2.6G 48G 6% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 5.0M 0 5.0M 0% /run/lock
none 1000M 0 1000M 0% /run/shm
none 100M 0 100M 0% /run/user
/dev/sda1 236M 40M 184M 18% /boot
root@ubuntudoc:~#

至此,/分区扩展至53G。

【linux】lvm扩展根分区的更多相关文章

  1. Linux系统使用lvm扩展根分区

    Linux系统使用lvm扩展根分区 背景:买的云主机虚拟机封装镜像是40G的系统盘,后期适用不规范或者其他需求需要扩展系统盘,而非挂载在一个盘至新建目录. 1.原本目录磁盘等信息: 2.使用vgdis ...

  2. Linux LVM 扩展磁盘分区

    系统:centos 6.3--新建分区 fdisk -l /dev/sdc       # 查看分区 fdisk /dev/sdc          # 创建分区 :n                 ...

  3. 10: VMware中扩展根分区

    1.1 添加一块硬盘 1.先给VMware添加一块60G硬盘 2.必须重启虚拟机才能识别到新加磁盘 fdisk -l        # 查看刚刚添加的硬盘 3.查看当前磁盘使用情况 df -hl   ...

  4. CentOS 挂载(U盘NTFS格式,新硬盘,增加交换分区,扩展根分区等)

    1.挂载fat或者fat32分区的U盘 如果是用VM安装的linux,在vm里挂载U盘有两个前提: 第一,主机里的service要启动: 第二,U盘是连接到虚拟机,而不是主机,需要确认这点: 2.使用 ...

  5. 在线扩展根分区 red hat 4.8.3-9

    跑程序的时候发现报错,提示空间不足,仔细查看后发现是根分区已满 27G的空间只有20k剩余 考虑从/data分区压缩一点空间到/分区 切换到root用户 执行下面的命令 1. umount /data ...

  6. centos7扩展根分区

    参考网站:http://www.360doc.com/content/18/0128/11/52410512_725728162.shtml VirtualBox中安装了CentOS 7,给同事用来做 ...

  7. LVM缩小根分区

    逻辑卷不是根分区都可以在线扩容和缩小 根分区是可以在线扩容,但不可以在线缩小 Linux系统进入救援模式 依次选择: 欢迎界面 ---------- Rescue installed system C ...

  8. linux下扩展root分区

    1 查看当前磁盘情况 fdisk -l /dev/sda1 2048 6143 2048 83 Linux /dev/sda2 * 6144 1054719 524288 83 Linux /dev/ ...

  9. RHEL7虚拟机中不重启的情况下加新硬盘及扩展根分区容量

    在VMware中添加一块新的5G硬盘 显示当前分区 # fdisk -l 通常在你在虚拟机中添加一块新硬盘时,你可能会看到新硬盘没有自动加载.这是因为连接到硬盘的SCSI总线需要重新扫描来使得新硬盘可 ...

随机推荐

  1. Django models 单表查询

    从数据库中查询出来的结果一般是一个集合,这个集合叫做 QuerySet 1. 查看Django QuerySet执行的SQL .query.__str__()或 .query属性打印执行的sql语句 ...

  2. Linux CentOS 防止SSH暴力破解

    一. 问题的发现 昨晚苦逼加班完后,今早上班继续干活时,SSH连接服务器发现异常的提示,仔细看了一下吓一小跳,昨晚9点钟到现在,一夜之间被人尝试连接200+,慌~~~ 1. 速度查一下log [roo ...

  3. ansible服务部署

    1.ansible.cfg配置文件 [defaults] #inventory= /home/op/ansible/testing #sudo_user=root remote_port=9122 r ...

  4. Prometheus node_exporter grafana部署安装

    1.环境 centos7 prometheus-2.10.0.linux-amd64.tar.gz node_exporter-0.18.1.linux-amd64.tar.gz 2.安装 创建sys ...

  5. BitTorrent协议与MagNet协议原理【转】

    转自:https://blog.csdn.net/u012785382/article/details/70674875 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog ...

  6. linux下各文件夹的结构说明及用途介绍:Linux目录结构介绍

    linux下各文件夹的结构说明及用途介绍: /bin:二进制可执行命令. /dev:设备特殊文件. /etc:系统管理和配置文件. /etc/rc.d:启动的配 置文件和脚本. /home:用户主目录 ...

  7. Qt 之 qwt 和 qwtpolar 的编译配置

    1  Qwt Qwt 全称为 Qt Widgets for Technical Applications,用于专业技术领域的可视化显示,如下所示: 左图为二阶系统的频率响应:中图为德国小城 Fried ...

  8. pytest中怎么引用前置中的变量

    本文主要总结的是pytest中的前置后置怎么返回参数 我们在做自动化的过程中,如果运用的是pytest的话,会遇到怎么使用前置条件中的变量 比如: @pytest.fixture() def init ...

  9. 1_ZedBoard开发板测试

    启动 将SD卡插入电脑进行格式化 格式化时,要将SD卡格式化为FAT32文件系统.块大小格式化为4096字节时后面会出现无法启动的情况,可以先复现一下这个错误.块大小我选择4096字节. 然后将Zed ...

  10. 第十二周博客作业 <西北师范大学| 周安伟>

    第十二周作业 助教博客链接https://home.cnblogs.com/u/zaw-315/ 作业要求链接https://www.cnblogs.com/nwnu-daizh/p/10831971 ...