LVM是 Logical Volume Manager(邏輯卷管理)的簡寫,它是Linux環境下對磁盤分區進行管理的一種機制,它由Heinz Mauelshagen在Linux 2.4內核上實現。
Linux用戶安裝Linux操作系統時遇到的一個常見的難以決定的問題就是如何正確地評估各分區大小,以分配合適的硬盤空間。普通的磁盤分區管理方式在邏輯分區劃分好之后就無法改變其大小,當一個邏輯分區存放不下某個文件時,這個文件因為受上層文件系統的限制,也不能跨越多個分區來存放,所以也不能同時放到別的磁盤上。而遇到出現某個分區空間耗盡時,解決的方法通常是使用符號鏈接,或者使用調整分區大小的工具,但這只是暫時解決辦法,沒有從根本上解決問題。隨著Linux的邏輯卷管理功能的出現,這些問題都迎刃而解,用戶在無需停機的情況下可以方便地調整各個分區大小。
fdisk : 列出幫助信息
fdisk -l : 列出所有分區
fdisk -l /dev/sda1 >>>指定分區列出
fdisk -s :給出分區大小
fdisk -s /dev/sda1 >>> 指定分區給出
fdisk [分區名稱] :更改分區
a toggle a bootable flag 切換可引導標志
b edit bsd disklabel 編輯bsd磁盤標簽
c toggle the dos compatibility flag 切換dos兼容性標志
d delete a partition 刪除分區
g create a new empty GPT partition table 創建一個新的空GPT分區表
G create an IRIX (SGI) partition table 創建IRIX(SGI)分區表
l list known partition types 列出已知分區類型
m print this menu 打印此菜單
n add a new partition 添加新分區
o create a new empty DOS partition table 創建一個新的空DOS分區表
p print the partition table 打印分區表
q quit without saving changes 退出而不保存更改
s create a new empty Sun disklabel 創建新的空Sun disklabel
t change a partitions system id 更改分區的系統id
u change display/entry units 更改顯示/輸入單位
v verify the partition table 驗證分區表
w write table to disk and exit 將表寫入磁盤并退出
x extra functionality (experts only) 額外功能(僅限專家)
mkfs:格式化分區
mkfs -t ext3 /dev/sda2 >>>>>>>將磁盤格式化為ext3格式
rpm -qa | grep lvm
yum -y install lvm
▼▼▼
pvcreate /dev/sdb1
[root@localhost ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.
pvs /dev/sdb1 查看所有pv(pvs后不跟分區默認輸出所有)
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <59.51g 4.00m
/dev/sdb1 lvm2 --- <30.00g <30.00g
查看pv的詳細信息:
▼▼▼
pvdispaly /dev/sdb1
[root@localhost ~]# pvdisplay /dev/sdb1
"/dev/sdb1" is a new physical volume of "<30.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size <30.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID J5dh1L-SFZf-EqcL-Jyet-E22j-UELn-nscaG7
[root@localhost ~]#
刪除pv:(pv不能直接刪除需要先pvmove移除所有數據后,pvremove刪除pv)
pvmove /dev/sdb1
pvremove /dev/sdb1
▼▼▼
vgcreate [卷組名] [磁盤分區]
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <59.51g 4.00m
/dev/sdb1 lvm2 --- <30.00g <30.00g
[root@localhost ~]# vgcreate vg0 /dev/sdb1
Volume group "vg0" successfully created
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 3 0 wz--n- <59.51g 4.00m
vg0 1 0 0 wz--n- <30.00g <30.00g
[root@localhost ~]#
查看vg詳細信息:
▼▼▼
[root@localhost ~]# vgdisplay vg0
--- Volume group ---
VG Name vg0
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size <30.00 GiB
PE Size 4.00 MiB
Total PE 7679
Alloc PE / Size 0 / 0
Free PE / Size 7679 / <30.00 GiB
VG UUID 3LYUBp-hY5d-z5gb-XWmC-6mFw-ZyY3-y36Ijm
注:lv是基于vg的,而vg是基于pv的所以此處在創建lv時首先需要查看vg大小能不能容下你要創建的lv,不能則需要擴展。
lvcreate L<指定lv大小 [lv容量] -n<指定邏輯卷名稱 [lv名稱] [卷組名]
▼▼▼
lvcreate -L 10G -n lv0 vg0
[root@localhost ~]# lvcreate -L 10G -n lv0 vg0
Logical volume "lv0" created.
[root@localhost ~]#
[root@localhost ~]# lvs vg0
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv0 vg0 -wi-a----- 10.00g
▼▼▼
mkfs.xfs /dev/sdb1
[root@localhost vg0]# mkfs.xfs /dev/vg0/lv0
meta-data=/dev/vg0/lv0 isize=512 agcount=4, agsize=655360 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=2621440, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost vg0]#
掛載lv:
▼▼▼
[root@localhost vg0]# mount /dev/vg0/lv0 /oracle_pv
[root@localhost vg0]# ls -l
總用量 0
lrwxrwxrwx. 1 root root 7 1月 8 16:32 lv0 -> ../dm-2
[root@localhost vg0]# df -h
文件系統 容量 已用 可用 已用% 掛載點
devtmpfs 2.2G 0 2.2G 0% /dev
tmpfs 2.2G 0 2.2G 0% /dev/shm
tmpfs 2.2G 13M 2.2G 1% /run
tmpfs 2.2G 0 2.2G 0% /sys/fs/cgroup
/dev/mapper/centos-root 45G 4.6G 41G 11% /
/dev/sda1 497M 303M 194M 61% /boot
/dev/mapper/centos-home 10G 41M 10G 1% /home
tmpfs 444M 12K 444M 1% /run/user/42
tmpfs 444M 0 444M 0% /run/user/0
/dev/mapper/vg0-lv0 10G 33M 10G 1% /oracle_pv
[root@localhost vg0]#
格式化為xfs:
▼▼▼
umount /oracle_log
mkfs.xfs -f /dev/vg0/lv0 -------f為強制執行
mount /dev/vg0/lv0 /oracle_pv
vgextend vg0 /dev/sdb1
vgreduce [卷組名] [物理卷]
pvmove /dev/sdb1
vgreduce /dev/sdb1
pvremove /dev/sdb1
▼▼▼
[root@localhost vg0]# umount /oracle_pv
[root@localhost vg0]# df -h
文件系統 容量 已用 可用 已用% 掛載點
devtmpfs 2.2G 0 2.2G 0% /dev
tmpfs 2.2G 0 2.2G 0% /dev/shm
tmpfs 2.2G 13M 2.2G 1% /run
tmpfs 2.2G 0 2.2G 0% /sys/fs/cgroup
/dev/mapper/centos-root 45G 4.6G 41G 11% /
/dev/sda1 497M 303M 194M 61% /boot
/dev/mapper/centos-home 10G 41M 10G 1% /home
tmpfs 444M 12K 444M 1% /run/user/42
tmpfs 444M 0 444M 0% /run/user/0
[root@localhost vg0]# e2fsck -f /dev/vg0/lv0
e2fsck 1.42.9 (28-Dec-2013)
第一步: 檢查inode,塊,和大小
第二步: 檢查目錄結構
第三步: 檢查目錄連接性
第四步: Checking reference counts
第五步: 檢查簇概要信息
▼▼▼
[root@localhost vg0]# resize2fs /dev/vg0/lv0 5G
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg0/lv0 to 1310720 (4k) blocks.
The filesystem on /dev/vg0/lv0 is now 1310720 blocks long.
[root@localhost vg0]#
[root@localhost vg0]#
[root@localhost vg0]#
▼▼▼
[root@localhost vg0]# mount /dev/vg0/lv0 /oracle_pv
[root@localhost vg0]# df -h
文件系統 容量 已用 可用 已用% 掛載點
devtmpfs 2.2G 0 2.2G 0% /dev
tmpfs 2.2G 0 2.2G 0% /dev/shm
tmpfs 2.2G 13M 2.2G 1% /run
tmpfs 2.2G 0 2.2G 0% /sys/fs/cgroup
/dev/mapper/centos-root 45G 4.6G 41G 11% /
/dev/sda1 497M 303M 194M 61% /boot
/dev/mapper/centos-home 10G 41M 10G 1% /home
tmpfs 444M 12K 444M 1% /run/user/42
tmpfs 444M 0 444M 0% /run/user/0
/dev/mapper/vg0-lv0 4.8G 33M 4.5G 1% /oracle_pv
[root@localhost vg0]#
▼▼▼
[root@localhost vg0]# lvreduce -L 5G /dev/vg0/lv0
WARNING: Reducing active and open logical volume to 5.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg0/lv0? [y/n]: y
Size of logical volume vg0/lv0 changed from 10.00 GiB (2560 extents) to 5.00 GiB (1280 extents).
Logical volume vg0/lv0 successfully resized.
[root@localhost vg0]#
拉伸文件系統:
ext4格式用:resize2fs
xfs格式用:xfs_growfs
▼▼▼
[root@localhost yum.repos.d]#
[root@localhost yum.repos.d]#
[root@localhost yum.repos.d]#
[root@localhost yum.repos.d]#
[root@localhost yum.repos.d]# df -hT
文件系統 類型 容量 已用 可用 已用% 掛載點
/dev/mapper/centos-root xfs 24G 4.5G 20G 19% /
devtmpfs devtmpfs 903M 0 903M 0% /dev
tmpfs tmpfs 920M 0 920M 0% /dev/shm
tmpfs tmpfs 920M 9.3M 911M 2% /run
tmpfs tmpfs 920M 0 920M 0% /sys/fs/cgroup
/dev/sda1 xfs 497M 163M 335M 33% /boot
tmpfs tmpfs 184M 12K 184M 1% /run/user/42
tmpfs tmpfs 184M 0 184M 0% /run/user/0
[root@localhost yum.repos.d]#
[root@localhost yum.repos.d]#
▼▼▼
[root@localhost /]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 3 0 wz--n- <59.51g 4.00m
vg0 1 2 0 wz--n- <30.00g <15.00g
[root@localhost /]# lvextend -L 10G /dev/vg0/lv0
Size of logical volume vg0/lv0 changed from 5.00 GiB (1280 extents) to 10.00 GiB (2560 extents).
Logical volume vg0/lv0 successfully resized.
[root@localhost /]#
[root@localhost /]# df -h
文件系統 容量 已用 可用 已用% 掛載點
devtmpfs 2.2G 0 2.2G 0% /dev
tmpfs 2.2G 0 2.2G 0% /dev/shm
tmpfs 2.2G 13M 2.2G 1% /run
tmpfs 2.2G 0 2.2G 0% /sys/fs/cgroup
/dev/mapper/centos-root 45G 4.6G 41G 11% /
/dev/sda1 497M 303M 194M 61% /boot
/dev/mapper/centos-home 10G 41M 10G 1% /home
tmpfs 444M 12K 444M 1% /run/user/42
tmpfs 444M 0 444M 0% /run/user/0
/dev/mapper/vg0-lv0 4.8G 33M 4.5G 1% /oracle_pv
/dev/mapper/vg0-lv1 9.8G 37M 9.2G 1% /oracle_pv1
▼▼▼
[root@localhost /]# resize2fs /dev/vg0/lv0
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vg0/lv0 is mounted on /oracle_pv; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 2
The filesystem on /dev/vg0/lv0 is now 2621440 blocks long.
[root@localhost /]#
[root@localhost /]# df -h
文件系統 容量 已用 可用 已用% 掛載點
devtmpfs 2.2G 0 2.2G 0% /dev
tmpfs 2.2G 0 2.2G 0% /dev/shm
tmpfs 2.2G 13M 2.2G 1% /run
tmpfs 2.2G 0 2.2G 0% /sys/fs/cgroup
/dev/mapper/centos-root 45G 4.6G 41G 11% /
/dev/sda1 497M 303M 194M 61% /boot
/dev/mapper/centos-home 10G 41M 10G 1% /home
tmpfs 444M 12K 444M 1% /run/user/42
tmpfs 444M 0 444M 0% /run/user/0
/dev/mapper/vg0-lv0 9.8G 36M 9.3G 1% /oracle_pv
/dev/mapper/vg0-lv1 9.8G 37M 9.2G 1% /oracle_pv1
▼▼▼
[root@test ~]# 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 0xf5002802.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content wont be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. Its strongly recommended to
switch off the mode (command c) and change display units to
sectors (command u).
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652):
Using default value 652
Command (m for help): t #修改分區格式
Selected partition 1
Hex code (type L to list codes): L #查看分區格式列表
Hex code (type L to list codes): 8e #類型修改為8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sdb: 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: 0xf5002802
Device Boot Start End Blocks Id System
/dev/sdb1 1 652 5237158+ 8e Linux LVM
Command (m for help): w #保存
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
mkfs -t ext4 /dev/sdb1
pvcreate /dev/sdb1
lvextend -L 9G /dev/vg_test/lv_root #擴展LV 9G為總大小 如果是增加4G 可寫為 +4G
▼▼▼
esize2fs /dev/vg_test/lv_root
df -h
vgdisplay
lvdisplay
resize2fs /dev/vg_test/lv_root #resizes
df -h
▼▼▼
vi /etc/fstab
/dev/phelsysvg/lvphelsys01 /phel/phelsys_u01 ext3 defaults 1 2
/dev/phelsysvg/lvphelrdo01 /phel/phelrdo_u01 ext3 defaults 1 2
/dev/phelsysvg/lvpheludo01 /phel/pheludo_u01 ext3 defaults 1 2
/dev/phelsysvg/lvphelaud01 /db_audit_file_dest ext3 defaults 1 2
/dev/phelsysvg/lvpheltmp01 /phel/pheltemp_u01 ext3 defaults 1 2
/dev/phelsysvg/lvphelarc01 /oraarchivelog ext3 defaults 1 2
更多精彩干貨分享
點擊下方名片關注
IT那活兒
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/129930.html
閱讀 1346·2023-01-11 13:20
閱讀 1684·2023-01-11 13:20
閱讀 1132·2023-01-11 13:20
閱讀 1858·2023-01-11 13:20
閱讀 4100·2023-01-11 13:20
閱讀 2704·2023-01-11 13:20
閱讀 1385·2023-01-11 13:20
閱讀 3597·2023-01-11 13:20