linux 磁碟分割槽掛載-LVM-物理卷PV,卷組VG,邏輯卷LV

yy418408247發表於2022-09-07
題外話:如果是資料磁碟,建議都使用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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章