Linux LVM邏輯卷配置 增加硬碟擴容的例子

來源:互聯網
上載者:User

Centos LVM是Linux環境中對磁碟分割進行管理的一種機制,是建立在硬碟和分區之上、檔案系統之下的一個邏輯層,可提高磁碟分割管理的靈活性。RHEL5預設安裝的分區格式就是LVM邏輯卷的格式,需要注意的是/boot分區不能基於LVM建立,必須獨立出來。

建立邏輯卷PV

pvcreate /dev/sda1 /dev/sdb1 (sda1 sdb1 的hex code : 8e    也就是LVM)   pvs    pvdisplay

建立組VG

vgcreate 組名 /dev/sda1 /dev/sdb1 vgs vgdisplay

建立邏輯卷LV

lvcreate -L 5000M -n  邏輯卷名 組名 lvs   lvdisplay

mkfs.ext4 && mount

LVM 增加硬碟擴容

將sdc1 的hex code : 8e    也就是Linux LVM

vgextend 組名 /dev/sdc1

lvextend -L +10.25G /dev/組名/邏輯卷名

resize2fs  /dev/組名/邏輯卷名

例子

1.查看硬碟分區情況
#fdisk -l
註:假設新增一個硬碟的裝置檔案名稱為/dev/sdb
2.開始分區
#fdisk /dev/sdb
3.查看指令協助資訊
Command (m for help): m
4.查看已有分區表
Command (m for help): p
Disk /dev/sdb: 500.0 GB, 500097376256 bytes
255 heads, 63 sectors/track, 60800 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 60800 488375968 7 HPFS/NTFS
註:可以看出此硬碟已經有一個分區,且所有的柱面都已指派
5.刪除原有分區
Command (m for help): d
6.再次查看分區表
Command (m for help): p
Disk /dev/sdb: 500.0 GB, 500097376256 bytes
255 heads, 63 sectors/track, 60800 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
7.新增分區
Command (m for help): n
Command action
e extended
p primary partition (1-4)
8.選擇分區類型(主要磁碟分割、擴充分區)、第幾個分區
p
1
9.設定分區的柱面範圍,這裡開始與結束都預設,直接斷行符號
10.查看分區表
Command (m for help): p
Disk /dev/sdb: 500.0 GB, 500097376256 bytes
255 heads, 63 sectors/track, 60800 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 60800 488375968+ 83 Linux
11.更改分區的類型
Command (m for help): t
Selected partition 1
Hex code (type L to list codes):L
註:如果有多個分區,會出現提示選擇分區
1
0  Empty           1e  Hidden W95 FAT1 80  Old Minix       bf  Solaris     
2
 1  FAT12           24  NEC DOS         81  Minix / old Lin c1  DRDOS/sec (FAT-
3
 2  XENIX root      39  Plan 9          82  Linux swap / So c4  DRDOS/sec (FAT-
4
 3  XENIX usr       3c  PartitionMagic  83  Linux           c6  DRDOS/sec (FAT-
5
 4  FAT16 <32M      40  Venix 80286     84  OS/2 hidden C:  c7  Syrinx      
6
 5  Extended        41  PPC PReP Boot   85  Linux extended  da  Non-FS data 
7
 6  FAT16           42  SFS             86  NTFS volume set db  CP/M / CTOS / .
8
 7  HPFS/NTFS       4d  QNX4.x          87  NTFS volume set de  Dell Utility
9
 8  AIX             4e  QNX4.x 2nd part 88  Linux plaintext df  BootIt      
10
 9  AIX bootable    4f  QNX4.x 3rd part 8e  Linux LVM       e1  DOS access  
11
 a  OS/2 Boot Manag 50  OnTrack DM      93  Amoeba          e3  DOS R/O     
12
 b  W95 FAT32       51  OnTrack DM6 Aux 94  Amoeba BBT      e4  SpeedStor   
13
 c  W95 FAT32 (LBA) 52  CP/M            9f  BSD/OS          eb  BeOS fs     
14
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi ee  EFI GPT     
15
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a5  FreeBSD         ef  EFI (FAT-12/16/
16
10  OPUS            55  EZ-Drive        a6  OpenBSD         f0  Linux/PA-RISC b
17
11  Hidden FAT12    56  Golden Bow      a7  NeXTSTEP        f1  SpeedStor   
18
12  Compaq diagnost 5c  Priam Edisk     a8  Darwin UFS      f4  SpeedStor   
19
14  Hidden FAT16 <3 61  SpeedStor       a9  NetBSD          f2  DOS secondary
20
16  Hidden FAT16    63  GNU HURD or Sys ab  Darwin boot     fb  VMware VMFS 
21
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE
22
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
23
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep     
24
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT     
12.將磁碟格式設定為linux LVM
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)
13.再次查看分區表
Command (m for help): p
Disk /dev/sdb: 500.0 GB, 500097376256 bytes
255 heads, 63 sectors/track, 60800 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 60800 488375968+ 8e Linux LVM
14.儲存,退出fdisk
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
如果出錯,使用partprobe指令重載分區表
15.查看硬碟分區情況
#fdisk -l
Disk /dev/sdb: 500.0 GB, 500097376256 bytes
255 heads, 63 sectors/track, 60800 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 60800 488375968+ 8e Linux LVM
16.查看系統中已有的物理卷
#pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup00
PV Size 297.99 GB / not usable 20.87 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 9535
Free PE 0
Allocated PE 9535
PV UUID oa2rNU-Tz2c-N1W0-AKcV-9UnE-ctdp-38dFQd
17.建立物理卷
#pvcreate /dev/sdb1
Writing physical volume data to disk "/dev/sdb1"
Physical volume "/dev/sdb1" successfully created
18.將新物理卷加入到卷組中
#vgextend VolGroup00 /dev/sdb1
Volume group "VolGroup00" successfully extended
19.將新的空間加到原有邏輯卷中去
#lvextend -L+500G /dev/VolGroup00/LogVol00
20.啟用擴容的LVM分區
#resize2fs -p /dev/VolGroup00/LogVol00
21.如果不擴容,可以增加邏輯卷
#lvcreate -L 200G -n lvol0 VolGroup00
Logical volume "lvol0" created
22.刪除邏輯卷
#lvremove /dev/mapper/VolGroup00-lvol0
23.查看已經存在的邏輯卷
#lvdisplay
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID ipf0Gk-3xXU-vN0I-cXbm-ZKLD-XUju-mDe02Z
LV Write Access read/write
LV Status available
# open 1
LV Size 48.81 GB
Current LE 1562
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol02
VG Name VolGroup00
LV UUID RybA0Q-5B8T-bOwA-SsPK-Prai-qsix-kCeWWI
LV Write Access read/write
LV Status available
# open 1
LV Size 49.91 GB
Current LE 1597
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol03
VG Name VolGroup00
LV UUID czznK0-VsUK-VAtj-Vbam-PDJS-1yZt-A6BPgK
LV Write Access read/write
LV Status available
# open 1
LV Size 195.31 GB
Current LE 6250
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol01
VG Name VolGroup00
LV UUID zvLpEL-Dj8Y-a0XG-4H7q-ZPaa-XUXY-0ln7qw
LV Write Access read/write
LV Status available
# open 1
LV Size 3.94 GB
Current LE 126
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:3
24.正式新增邏輯卷
#lvcreate -L 500G -n LogVol04 VolGroup00
25.格式化新增邏輯卷
#mkfs.ext3 /dev/mapper/VolGroup00-LogVol04
26.掛載邏輯卷
#mount /dev/mapper/VolGroup00-LogVol04 /data
27.編輯/etc/fstab將新增邏輯卷設定開機掛載,新增下面一行
/dev/VolGroup00/LogVol04 /data ext3 defaults 1 2
28.測試掛載
mount -a
29.查看並刪除物理卷
查看掛載情況
#df -h
/dev/mapper/VolGroup00-LogVol04
296G 245M 281G 1% /backup
卸載
#umount /backup
刪除邏輯卷
#lvremove /dev/mapper/VolGroup00-LogVol04
查看物理卷
#pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup00
PV Size 297.99 GB / not usable 20.87 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 9535
Free PE 0
Allocated PE 9535
PV UUID oa2rNU-Tz2c-N1W0-AKcV-9UnE-ctdp-38dFQd
--- Physical volume ---
PV Name /dev/sdb1
VG Name VolGroup00
PV Size 465.75 GB / not usable 1.66 MB
Allocatable yes
PE Size (KByte) 32768
Total PE 14904
Free PE 5304
Allocated PE 9600
PV UUID avEKz2-t5Ko-jsn0-Pvuh-h8DJ-GV0o-ZQfBOL
將物理卷從卷組中移除
#vgreduce VolGroup00 /dev/sdb1
刪除物理卷
#pvremove /dev/sdb1
這樣就可以重新進行格式化磁碟

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.