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. js、jquery、css属性及出错集合

    *)注意使用jquery设置css的语法 css("propertyname","value");#单个时时逗号 css({"propertyname ...

  2. Vim操作:打开文件

    1.打开文件并定位到某一行 vim +20 vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php # 定位至第20行 2 ...

  3. 场sharepoint2016数据库恢复站点

    前不久公司support方,不小心把IIS的应用删除了,算是灼急了,不过有过原来恢复的经历,似乎有了心理准备,可是这次比上次严重些.技术操作复杂些,不过通过此事,也是进一步了解了SP2016数据库结构 ...

  4. 在 React 项目中引入 GG-Editor 编辑可视化流程

    蚂蚁金服数据可视化团队曾经开源了一款G6-Editor,但后来停止了对外支持,学习成本太高 好在后来他们团队的大牛高力结合 React + G6 开源了一个 GG-Editor(其实就是G6-Edit ...

  5. Hibernate基于注解实现自关联树形结构实现

    很久没用过Hibernate了,项目需求需要使用,并建立树形结构,在开发中遇到一些问题,在这里记录一下. 1.创建数据库表,主要是设置标志信息,不然插入数据库会报id不能插入null的错误. 2.创建 ...

  6. Nginx01(Nginx简介)

    一:序言 Nginx是lgor Sysoev为俄罗斯访问量第二的rambler.ru站点设计开发的.从2004年发布至今,凭借开源的力量,已经接近成熟与完善. 二:Nginx常用功能 1.Http代理 ...

  7. 玩转淘宝SVN

    http://guojun2sq.blog.163.com/blog/static/64330861201492965059142/(参考) 三步走: 1.注册账号http://code.taobao ...

  8. opencv鼠标事件

    #include <opencv2\opencv.hpp> using namespace cv; struct mouse_para { cv::Mat org; cv::Mat img ...

  9. 02-numpy-笔记-amin

    >>> a = np.arange(4).reshape((2,2)) >>> a array([[0, 1], [2, 3]]) >>> np. ...

  10. python SSL 错误

    python 使用pip 安装模块是提示SSL错误 出现该问题的原因由于系统的openssl是1.0.1的版本,对于python3.7太老了,需要更新为openssl1.0.2或者libressl2. ...