差異處
這裏顯示兩個版本的差異處。
兩邊的前次修訂版 前次修改 下次修改 | 前次修改 | ||
tech:lvm_conecpt [2018/06/24 16:04] – Jonathan Tsai | tech:lvm_conecpt [2018/06/24 18:51] (目前版本) – [參考網址] Jonathan Tsai | ||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== LVM (Logical Volume Management) 概念與基本語法 ====== | ||
+ | |||
+ | <ditaa round noedgesep> | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | | System | | System | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | Logical| | ||
+ | | Volume | | Volume | | ||
+ | | ||
+ | | ||
+ | | | | ||
+ | +-+ +-+ | ||
+ | | | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | | ||
+ | +----------+----------+ | ||
+ | | | | | ||
+ | | ||
+ | | ||
+ | | Volume | | Volume | | Volume | | ||
+ | | ||
+ | | ||
+ | |||
+ | </ | ||
+ | |||
+ | * Physical Volume (PV) : 就是實體區, | ||
+ | * Volume Group (VG) : 就是整合實體區(PV)與邏輯區(LV), | ||
+ | * Logical Volume(LV) : 就是邏輯區, | ||
+ | |||
+ | * 使用 LVM 的好處是讓檔案系統可以更有彈性的來調整, | ||
+ | * 例如原有硬碟(或分割)大小空間滿了, | ||
+ | - 將加上的 10G 空間, 使用 parted 指令建立新的分割區 參考指令 print , mkpart primary , set < | ||
+ | (parted) print | ||
+ | Model: QEMU QEMU HARDDISK (scsi) | ||
+ | 磁碟 / | ||
+ | 磁區大小 (邏輯/ | ||
+ | 分割區:msdos | ||
+ | |||
+ | 編號 | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | [root@pve-svn ~]# fdisk -l /dev/sda | ||
+ | |||
+ | Disk /dev/sda: 21.5 GB, 21474836480 bytes | ||
+ | 64 heads, 32 sectors/ | ||
+ | Units = cylinders of 2048 * 512 = 1048576 bytes | ||
+ | Sector size (logical/ | ||
+ | I/O size (minimum/ | ||
+ | Disk identifier: 0x000a3b61 | ||
+ | |||
+ | | ||
+ | / | ||
+ | Partition 1 does not end on cylinder boundary. | ||
+ | / | ||
+ | Partition 2 does not end on cylinder boundary. | ||
+ | / | ||
+ | Partition 3 does not end on cylinder boundary. | ||
+ | </ | ||
+ | - 用 pvcreate 命令將新產生的分割區 /dev/sda3 建立為 PV ++執行語法|< | ||
+ | pvcreate /dev/sda3 | ||
+ | |||
+ | [root@pve-svn ~]# pvdisplay | ||
+ | --- Physical volume --- | ||
+ | PV Name / | ||
+ | VG Name | ||
+ | PV Size 9.51 GiB / not usable 3.00 MiB | ||
+ | Allocatable | ||
+ | PE Size 4.00 MiB | ||
+ | Total PE 2434 | ||
+ | Free PE 0 | ||
+ | Allocated PE 2434 | ||
+ | PV UUID | ||
+ | |||
+ | "/ | ||
+ | --- NEW Physical volume --- | ||
+ | PV Name / | ||
+ | VG Name | ||
+ | PV Size 10.00 GiB | ||
+ | Allocatable | ||
+ | PE Size 0 | ||
+ | Total PE 0 | ||
+ | Free PE 0 | ||
+ | Allocated PE 0 | ||
+ | PV UUID | ||
+ | |||
+ | [root@pve-svn ~]# pvscan | ||
+ | PV / | ||
+ | PV / | ||
+ | Total: 2 [19.51 GiB] / in use: 1 [9.51 GiB] / in no VG: 1 [10.00 GiB] | ||
+ | |||
+ | [root@pve-svn ~]# pvs | ||
+ | PV | ||
+ | / | ||
+ | / | ||
+ | |||
+ | </ | ||
+ | - 將剛產生的 PV /dev/sda3 以 vgextend 命令來加入現有的 VG - VolGroup ++執行語法|< | ||
+ | [root@pve-svn ~]# vgdisplay | ||
+ | --- Volume group --- | ||
+ | VG Name | ||
+ | System ID | ||
+ | Format | ||
+ | Metadata Areas 1 | ||
+ | Metadata Sequence No 3 | ||
+ | VG Access | ||
+ | VG Status | ||
+ | MAX LV 0 | ||
+ | Cur LV 2 | ||
+ | Open LV 2 | ||
+ | Max PV 0 | ||
+ | Cur PV 1 | ||
+ | Act PV 1 | ||
+ | VG Size 9.51 GiB | ||
+ | PE Size 4.00 MiB | ||
+ | Total PE 2434 | ||
+ | Alloc PE / Size 2434 / 9.51 GiB | ||
+ | Free PE / Size 0 / 0 | ||
+ | VG UUID | ||
+ | |||
+ | [root@pve-svn ~]# vgextend VolGroup /dev/sda3 | ||
+ | Volume group " | ||
+ | |||
+ | [root@pve-svn ~]# vgdisplay | ||
+ | --- Volume group --- | ||
+ | VG Name | ||
+ | System ID | ||
+ | Format | ||
+ | Metadata Areas 2 | ||
+ | Metadata Sequence No 5 | ||
+ | VG Access | ||
+ | VG Status | ||
+ | MAX LV 0 | ||
+ | Cur LV 2 | ||
+ | Open LV 2 | ||
+ | Max PV 0 | ||
+ | Cur PV 2 | ||
+ | Act PV 2 | ||
+ | VG Size 19.50 GiB | ||
+ | PE Size 4.00 MiB | ||
+ | Total PE 4993 | ||
+ | Alloc PE / Size 2434 / 9.51 GiB | ||
+ | Free PE / Size 2559 / 10.00 GiB | ||
+ | VG UUID | ||
+ | |||
+ | [root@pve-svn ~]# vgs | ||
+ | VG #PV #LV #SN Attr | ||
+ | VolGroup | ||
+ | |||
+ | </ | ||
+ | - 使用 lvextend | ||
+ | [root@pve-svn ~]# lvdisplay | ||
+ | --- Logical volume --- | ||
+ | LV Path / | ||
+ | LV Name lv_root | ||
+ | VG Name VolGroup | ||
+ | LV UUID JbZGhn-aEuR-sohP-RSGc-FF09-hk9V-Qi5dXL | ||
+ | LV Write Access | ||
+ | LV Creation host, time localhost.localdomain, | ||
+ | LV Status | ||
+ | # open 1 | ||
+ | LV Size 7.54 GiB | ||
+ | Current LE 1930 | ||
+ | Segments | ||
+ | Allocation | ||
+ | Read ahead sectors | ||
+ | - currently set to 256 | ||
+ | Block device | ||
+ | |||
+ | --- Logical volume --- | ||
+ | LV Path / | ||
+ | LV Name lv_swap | ||
+ | VG Name VolGroup | ||
+ | LV UUID 5SRhkK-6vuF-SAe8-g7P1-FhJp-E0YM-rrBcvj | ||
+ | LV Write Access | ||
+ | LV Creation host, time localhost.localdomain, | ||
+ | LV Status | ||
+ | # open 1 | ||
+ | LV Size 1.97 GiB | ||
+ | Current LE 504 | ||
+ | Segments | ||
+ | Allocation | ||
+ | Read ahead sectors | ||
+ | - currently set to 256 | ||
+ | Block device | ||
+ | |||
+ | [root@pve-svn ~]# lvextend --size +10G / | ||
+ | Insufficient free space: 2560 extents needed, but only 2559 available | ||
+ | [root@pve-svn ~]# lvextend -l +2560 / | ||
+ | Insufficient free space: 2560 extents needed, but only 2559 available | ||
+ | [root@pve-svn ~]# lvextend -l +2559 / | ||
+ | Size of logical volume VolGroup/ | ||
+ | Logical volume lv_root successfully resized. | ||
+ | |||
+ | [root@pve-svn ~]# lvresize -l +100%FREE / | ||
+ | |||
+ | |||
+ | [root@pve-svn ~]# vgs -o +lv_size, | ||
+ | VG #PV #LV #SN Attr | ||
+ | VolGroup | ||
+ | VolGroup | ||
+ | |||
+ | [root@pve-svn ~]# lvs | ||
+ | LV VG | ||
+ | lv_root VolGroup -wi-ao---- 17.54g | ||
+ | lv_swap VolGroup -wi-ao---- | ||
+ | |||
+ | </ | ||
+ | - 透過 resize2fs 讓 LV 增加的空間實際生效 ++執行語法|< | ||
+ | [root@pve-svn ~]# df -h | ||
+ | Filesystem | ||
+ | / | ||
+ | 7.3G 1.8G 5.2G 26% / | ||
+ | tmpfs | ||
+ | / | ||
+ | |||
+ | [root@pve-svn ~]# resize2fs / | ||
+ | resize2fs 1.41.12 (17-May-2010) | ||
+ | Filesystem at / | ||
+ | old desc_blocks = 1, new_desc_blocks = 2 | ||
+ | Performing an on-line resize of / | ||
+ | The filesystem on / | ||
+ | |||
+ | [root@pve-svn ~]# df -h | ||
+ | Filesystem | ||
+ | / | ||
+ | | ||
+ | tmpfs | ||
+ | / | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== 參考網址 ===== | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | * https:// | ||
+ | |||
+ | {{tag> | ||