【linux】lvm扩展根分区
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扩展根分区的更多相关文章
- Linux系统使用lvm扩展根分区
Linux系统使用lvm扩展根分区 背景:买的云主机虚拟机封装镜像是40G的系统盘,后期适用不规范或者其他需求需要扩展系统盘,而非挂载在一个盘至新建目录. 1.原本目录磁盘等信息: 2.使用vgdis ...
- Linux LVM 扩展磁盘分区
系统:centos 6.3--新建分区 fdisk -l /dev/sdc # 查看分区 fdisk /dev/sdc # 创建分区 :n ...
- 10: VMware中扩展根分区
1.1 添加一块硬盘 1.先给VMware添加一块60G硬盘 2.必须重启虚拟机才能识别到新加磁盘 fdisk -l # 查看刚刚添加的硬盘 3.查看当前磁盘使用情况 df -hl ...
- CentOS 挂载(U盘NTFS格式,新硬盘,增加交换分区,扩展根分区等)
1.挂载fat或者fat32分区的U盘 如果是用VM安装的linux,在vm里挂载U盘有两个前提: 第一,主机里的service要启动: 第二,U盘是连接到虚拟机,而不是主机,需要确认这点: 2.使用 ...
- 在线扩展根分区 red hat 4.8.3-9
跑程序的时候发现报错,提示空间不足,仔细查看后发现是根分区已满 27G的空间只有20k剩余 考虑从/data分区压缩一点空间到/分区 切换到root用户 执行下面的命令 1. umount /data ...
- centos7扩展根分区
参考网站:http://www.360doc.com/content/18/0128/11/52410512_725728162.shtml VirtualBox中安装了CentOS 7,给同事用来做 ...
- LVM缩小根分区
逻辑卷不是根分区都可以在线扩容和缩小 根分区是可以在线扩容,但不可以在线缩小 Linux系统进入救援模式 依次选择: 欢迎界面 ---------- Rescue installed system C ...
- linux下扩展root分区
1 查看当前磁盘情况 fdisk -l /dev/sda1 2048 6143 2048 83 Linux /dev/sda2 * 6144 1054719 524288 83 Linux /dev/ ...
- RHEL7虚拟机中不重启的情况下加新硬盘及扩展根分区容量
在VMware中添加一块新的5G硬盘 显示当前分区 # fdisk -l 通常在你在虚拟机中添加一块新硬盘时,你可能会看到新硬盘没有自动加载.这是因为连接到硬盘的SCSI总线需要重新扫描来使得新硬盘可 ...
随机推荐
- Asp.Net SignalR 使用记录
工作上遇到一个推送消息的功能的实现.本着面向百度编程的思想.网上百度了一大堆.主要的实现方式是原生的WebSocket,和SignalR,再次写一个关于Asp.Net SignalR 的demo 这里 ...
- docfx 简单使用方法、自动生成目录的工具
[摘要] 这是我编写的一个 Docfx 文档自动生成工具,只要写好 Markdown 文档,使用此工具可为目录.文件快速生成配置,然后直接使用 docfx 运行即可. https://github.c ...
- python with语句与contextlib
参考链接:https://www.ibm.com/developerworks/cn/opensource/os-cn-pythonwith/ with语句用于异常处理,适用于存在资源访问的场合,无论 ...
- React入门(二)
组件的生命周期 概念:在组件创建.到加载到页面运行.以及组件被销毁的过程中伴随的事件.组件的生命周期是指在组件的特定时期触发的事件. 组件的生命周期分为三个部分: 组件创建阶段:只执行一次 compo ...
- CTF必备技能丨Linux Pwn入门教程——ROP技术(上)
Linux Pwn入门教程系列分享如约而至,本套课程是作者依据i春秋Pwn入门课程中的技术分类,并结合近几年赛事中出现的题目和文章整理出一份相对完整的Linux Pwn教程. 教程仅针对i386/am ...
- python基础-面向对象编程之反射
面向对象编程之反射 反射 定义:通过字符串对对象的属性和方法进行操作. 反射有4个方法,都是python内置的,分别是: hasattr(obj,name:str) 通过"字符串" ...
- emacs cedet
用emacs写c或者c++代码用的插件的配置.功能是能够代码补齐. (require 'package) (package-initialize) (add-to-list'package-archi ...
- AssetBundleMaster_ReadMe_CN
在开始使用之前, 建议先导入到一个空的工程里, 通过ReadMe的一步步引导使你对整个框架以及文件结构进行熟悉, 之后再考虑导入到现有工程中使用, 完整看完教程大概需要2个小时左右. 先看看文件夹结构 ...
- Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n ...
- 莫烦TensorFlow_06 plot可视化
import tensorflow as tf import numpy as np import matplotlib.pyplot as plt def add_layer(inputs, in_ ...