linux 磁碟分割槽掛載-LVM-物理卷PV,卷組VG,邏輯卷LV
題外話:如果是資料磁碟,建議都使用LVM 這樣避免出現空間不足,進行遷移。 部分雲伺服器就可以不考慮這個問題。
1.磁碟分割槽
具體詳見:linux 磁碟分割槽掛載-fdisk
fdisk -l 檢視磁碟分割槽情況
2.建立物理卷PV
pvcreate 裝置名稱
[root@localhost Desktop]# pvcreate /dev/sdb3
Physical volume "/dev/sdb3" successfully created
pvdisplay 產看詳細物理卷資訊
root@localhost Desktop]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name rhel
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4994
Free PE 0
Allocated PE 4994
PV UUID aK2Fc8-CdE3-fNm5-HvD4-OYNf-efGB-EZGjiQ
--- Physical volume ---
PV Name /dev/sdb1
VG Name vgnew
PV Size 200.00 MiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 49
Free PE 40
Allocated PE 9
PV UUID ukTCyL-09v8-Bs6C-tDYs-JpNQ-vrG3-2iRUDG
--- Physical volume ---
PV Name /dev/sdb2
VG Name vgnew
PV Size 120.00 MiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 29
Free PE 29
Allocated PE 0
PV UUID fVstso-ytGO-Y7Qw-ndkJ-E1Pt-aR65-aViPdz
"/dev/sdb3" is a new physical volume of "20.00 MiB"
--- NEW Physical volume ---
PV Name /dev/sdb3
VG Name
PV Size 20.00 MiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 1Tyiu2-xzt0-3Kw6-9Gmg-5CSl-1mHT-kIq5k2
pvscan/pvs 檢視物理卷資訊
[root@localhost Desktop]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 rhel lvm2 a-- 19.51g 0
/dev/sdb1 vgnew lvm2 a-- 196.00m 160.00m
/dev/sdb2 vgnew lvm2 a-- 116.00m 116.00m
/dev/sdb3 lvm2 a-- 20.00m 20.00m
可以看到裝置sdb3 沒有VG ,沒有卷組,下面來建立卷組
3.建立卷組 vgcreate
[root@localhost Desktop]#
vgcreate vg001 /dev/sdb3
Volume group "vg001" successfully created
[root@localhost Desktop]# vgs
VG #PV #LV #SN Attr VSize VFree
rhel 1 2 0 wz--n- 19.51g 0
vg001 1 0 0 wz--n- 16.00m 16.00m
vgnew 2 1 0 wz--n- 312.00m 276.00m
vgcreat -s xxM 指定PE值大小,預設為4M 。
4.建立邏輯卷 lvcreate
[root@localhost Desktop]#
lvcreate -n lv001 -L 4M vg001
Logical volume "lv001" created
[root@localhost Desktop]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
root rhel -wi-ao---- 17.51g
swap rhel -wi-ao---- 2.00g
lv001 vg001 -wi-a----- 4.00m
newlv vgnew -wi-ao---- 36.00mmk
lvcreate -n 邏輯卷名 -L xxM 邏輯卷大小 卷組
5.掛載邏輯卷,只有掛載之後才能使用邏輯卷
掛載之前先要對邏輯券進行格式化,這裡先格式化成為ext4格式
[root@localhost Desktop]# mkfs.ext4 /dev/vg001/lv001
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
1024 inodes, 4096 blocks
204 blocks (4.98%) reserved for the super user
First data block=1
Maximum filesystem blocks=4194304
1 block group
8192 blocks per group, 8192 fragments per group
1024 inodes per group
Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done
[root@localhost Desktop]# mkdir /mkd //新建資料夾
[root@localhost /]# mount /dev/vg001/lv001 /mkd //掛載
mkfs.xfs -f /dev/vg001/lv001
[root@localhost /]# df -h //產看掛載資訊
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 3.3G 15G 19% /
devtmpfs 905M 0 905M 0% /dev
tmpfs 914M 144K 914M 1% /dev/shm
tmpfs 914M 8.9M 905M 1% /run
tmpfs 914M 0 914M 0% /sys/fs/cgroup
/dev/mapper/vgnew-newlv 11M 204K 9.6M 3% /media
/dev/sda1 497M 119M 379M 24% /boot
/dev/sr0 3.5G 3.5G 0 100% /run/media/new/RHEL-7.0 Server.x86_64
/dev/mapper/vg001-lv001 2.9M 45K 2.6M 2% /mkd
[root@localhost /]# vim /etc/fstab //編輯/etc/fstab 檔案設定開機自動掛載
6.擴充套件邏輯卷
[root@localhost /]# vgdisplay vg001 ----檢視邏輯卷所在的卷組資訊
--- Volume group ---
VG Name vg001
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 16.00 MiB
PE Size 4.00 MiB
Total PE 4
Alloc PE / Size 1 / 4.00 MiB
Free PE / Size 3 / 12.00 MiB
VG UUID 0IGKxv-NQRG-PNue-UbR3-1O7S-yW4K-f10I3E
卷組還有剩餘 12M 可以直接擴充套件
首先在 /mkd資料夾下建立一個簡單的檔案,測試檔案會不會丟失,建立檔案省略。。。。
[root@localhost mkd]# ll
total 14
drwx------. 2 root root 12288 May 30 02:26 lost+found
-rw-r--r--. 1 root root 8 May 30 03:15 test.txt
[root@localhost mkd]#
lvextend -l +1 /dev/vg001/lv001
---擴充套件加1個PE大小的值
Extending logical volume lv001 to 8.00 MiB
Logical volume lv001 successfully resized
[root@localhost mkd]#
df -h
--檢視邏輯卷 ,可以看到該邏輯卷並沒有增加,
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 3.3G 15G 19% /
devtmpfs 905M 0 905M 0% /dev
tmpfs 914M 144K 914M 1% /dev/shm
tmpfs 914M 9.0M 905M 1% /run
tmpfs 914M 0 914M 0% /sys/fs/cgroup
/dev/mapper/vgnew-newlv 11M 204K 9.6M 3% /media
/dev/sda1 497M 119M 379M 24% /boot
/dev/sr0 3.5G 3.5G 0 100% /run/media/new/RHEL-7.0 Server.x86_64
/dev/mapper/vg001-lv001 2.9M 47K 2.6M 2% /mkd
[root@localhost mkd]#
resize2fs /dev/vg001/lv001 ---使邏輯卷擴充套件生效
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vg001/lv001 is mounted on /mkd; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/vg001/lv001 is now 8192 blocks long.
[root@localhost mkd]# df -h ---重新檢視邏輯卷大小,成功擴充套件
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 3.3G 15G 19% /
devtmpfs 905M 0 905M 0% /dev
tmpfs 914M 144K 914M 1% /dev/shm
tmpfs 914M 9.0M 905M 1% /run
tmpfs 914M 0 914M 0% /sys/fs/cgroup
/dev/mapper/vgnew-newlv 11M 204K 9.6M 3% /media
/dev/sda1 497M 119M 379M 24% /boot
/dev/sr0 3.5G 3.5G 0 100% /run/media/new/RHEL-7.0 Server.x86_64
/dev/mapper/vg001-lv001 6.9M 47K 6.6M 1% /mkd
檔案無損壞
7.邏輯捲縮減
首先需要解除安裝掛載點
[root@localhost /]# umount /mkd --解除安裝掛載點
[root@localhost /]# resize2fs /dev/vg001/lv001 4M --調整檔案系統大小
resize2fs 1.42.9 (28-Dec-2013)
Please run 'e2fsck -f /dev/vg001/lv001' first.
[root@localhost /]# e2fsck -f /dev/vg001/lv001 --先執行這個
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg001/lv001: 12/1024 files (8.3% non-contiguous), 1204/8192 blocks
[root@localhost /]# resize2fs /dev/vg001/lv001 4M --重新調整檔案系統大小
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg001/lv001 to 4096 (1k) blocks.
The filesystem on /dev/vg001/lv001 is now 4096 blocks long.
[root@localhost /]# e2fsck -f /dev/vg001/lv001 --重新檢查檔案系統
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg001/lv001: 12/1024 files (8.3% non-contiguous), 1204/4096 blocks
[root@localhost /]# lvreduce -l -1 /dev/vg001/lv001 --縮減一個邏輯卷為1個PE值大小
WARNING: Reducing active logical volume to 4.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv001? [y/n]: y
Reducing logical volume lv001 to 4.00 MiB
Logical volume lv001 successfully resized
8.刪除邏輯卷 lvremove
[root@localhost /]# lvremove /dev/vg001/lv001
Do you really want to remove active logical volume lv001? [y/n]: y
Logical volume "lv001" successfully removed
9.刪除卷組,縮減卷組
vgreduce 若一個卷組包含多個PV,縮減是刪除PV得到的
vgremove 刪除一個卷組
10.刪除物理卷
pvremove
遊戲是我的全部圖景,我將演繹所有的遊戲角色,我是每個活著角色的傳奇。 --清
沐
嫻
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29494175/viewspace-2913762/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- linux 磁碟自動化分割槽掛載-LVM-物理卷PV,卷組VG,邏輯卷LV-shellLinuxLVM
- Linux硬碟掛載與磁碟分割槽基礎(二)(物理卷、卷組、邏輯卷)Linux硬碟
- Linux下的磁碟分割槽和邏輯卷Linux
- 如何新建邏輯卷及磁碟掛載,邏輯卷擴容
- linux系統掛載邏輯卷和擴充套件邏輯卷組Linux套件
- linux系統下分割槽邏輯卷擴容Linux
- Linux—磁碟配額,管理LVM邏輯卷LinuxLVM
- 如何在 Linux 分割槽或邏輯卷中建立檔案系統Linux
- linux之LVM邏輯卷LinuxLVM
- ENGINEER01 - 分割槽規劃和使用,LVM邏輯卷LVM
- Linux作業系統中分割槽格式轉換LVM格式及多磁碟建立PV、VG、LVLinux作業系統LVM
- Linux下LVM邏輯卷管理LinuxLVM
- Centos 分割卷組CentOS
- lvm 擴充邏輯卷空間(linux的磁碟擴容)LVMLinux
- centos7 新增磁碟到/(根目錄下),擴充套件VG卷和lvCentOS套件
- LVM 邏輯卷管理LVM
- linux 磁碟分割槽掛載-fdiskLinux
- Linux 磁碟分割槽和掛載Linux
- linux 新增磁碟 分割槽掛載Linux
- LVM_邏輯卷管理LVM
- 在Linux中,如何使用LVM管理邏輯卷?LinuxLVM
- Linux LVM Logical Volume Management 邏輯卷的管理LinuxLVM
- 介紹如何從LVM的卷組中刪除物理卷LVM
- LVM邏輯卷線上動態擴容磁碟空間LVM
- Linux-使用者管理與建立邏輯卷Linux
- Linux磁碟分割槽及自動掛載Linux
- lvm收縮邏輯卷空間LVM
- SAN儲存卷擴容後對應客戶端磁碟和掛載磁碟的分割槽如何正確顯示新增容量客戶端
- Centos8中遷移邏輯卷CentOS
- Linux磁碟分割槽、掛載、檢視檔案大小Linux
- Docker-nginx資料卷掛載DockerNginx
- docker 資料卷掛載總結Docker
- 什麼是LVM邏輯卷管理?0基礎學Linux運維LVMLinux運維
- Linux作業系統邏輯盤卷管理LVM建立步驟(轉)Linux作業系統LVM
- Centos8中建立LVM精簡邏輯卷CentOSLVM
- 物理套卷練習記錄
- Liunx 磁碟分割槽與檔案掛載
- 手把手教學----LVM邏輯卷管理與磁碟配額實操全流程LVM