1. 程式人生 > 其它 >linux目錄結構知識

linux目錄結構知識

1、新加的硬碟

2、建立物理卷

可以先分割槽,這裡不分割槽直接建立

[root@centos_8 ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created.
[root@centos_8 ~]# pvs
  PV         VG Fmt  Attr PSize  PFree 
  /dev/sdb      lvm2 ---  30.00g 30.00g
[root@centos_8 ~]# pvdisplay 
  "/dev/sdb" is a new physical volume of "30.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb
  VG Name               
  PV Size               30.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               FueQYl-RVG4-ch3n-778X-3eJH-Y8EN-oqgPwV
   

3、建立卷組

[root@centos_8 ~]# vgcreate vg0 /dev/sdb   #給卷組取名為vg0
  Volume group "vg0" successfully created
[root@centos_8 ~]# vgs
  VG  #PV #LV #SN Attr   VSize   VFree  
  vg0   1   0   0 wz--n- <30.00g <30.00g
[root@centos_8 ~]# vgdisplay 
  --- 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  #總共有7679個pe
  Alloc PE / Size       0 / 0   
  Free  PE / Size       7679 / <30.00 GiB
  VG UUID               365Wfi-TJjO-wcdV-u2N7-eC70-GbFE-7BA1EN

4、建立邏輯卷

[root@centos_8 ~]# lvcreate -L 10G -n xzcdc vg0
  Logical volume "xzcdc" created.
[root@centos_8 ~]# lvs
  LV    VG  Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  xzcdc vg0 -wi-a----- 10.00g                                                    
[root@centos_8 ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/vg0/xzcdc
  LV Name                xzcdc
  VG Name                vg0
  LV UUID                45Mkh7-w7Pu-bdbw-a4mU-kEch-BG2J-IEUjCH
  LV Write Access        read/write
  LV Creation host, time centos_8, 2021-12-15 18:53:51 +0800
  LV Status              available
  # open                 0
  LV Size                10.00 GiB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
#從卷組裡面分配了10G個,還剩下20G


#可以格式化為ext系列或者是xfs系列,這裡為xfs系列
[root@centos_8 ~]# mkfs.xfs /dev/vg0/xzcdc
meta-data=/dev/vg0/xzcdc         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



#臨時掛載,如果要永久掛載,就寫進配置檔案,vim /etc/fstab
[root@centos_8 ~]# blkid
/dev/sda1: UUID="c460341d-392d-4193-9c17-96c43ae6cb05" TYPE="xfs" 
/dev/sda2: UUID="a85d2def-fb6f-40f1-8756-3a01b08eef94" TYPE="xfs" 
/dev/sda3: UUID="9ea797d7-3515-45d3-a5ee-e3a4fa62fbdb" TYPE="xfs" 
/dev/sda5: UUID="ae83937a-7b78-4357-820c-e092d9c0ca2e" TYPE="swap" 
/dev/sr0: UUID="2018-05-07-12-53-47-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" 
/dev/sdb: UUID="FueQYl-RVG4-ch3n-778X-3eJH-Y8EN-oqgPwV" TYPE="LVM2_member" 
/dev/mapper/vg0-xzcdc: UUID="d19b9403-10ed-442f-b24f-4b0876554b14" TYPE="xfs" 

[root@centos_8 ~]# mkdir /mnt/xzcdc
[root@centos_8 ~]# mount /dev/vg0/xzcdc /mnt/xzcdc/
[root@centos_8 ~]# df
Filesystem            1K-blocks    Used Available Use% Mounted on
/dev/sda2              20961280 3635556  17325724  18% /
devtmpfs                 805608       0    805608   0% /dev
tmpfs                    821536       0    821536   0% /dev/shm
tmpfs                    821536   10436    811100   2% /run
tmpfs                    821536       0    821536   0% /sys/fs/cgroup
/dev/sda3               5232640   32948   5199692   1% /data
/dev/sda1              15718400  158004  15560396   2% /boot
tmpfs                    164308      12    164296   1% /run/user/42
tmpfs                    164308       0    164308   0% /run/user/0
/dev/mapper/vg0-xzcdc  10475520   32944  10442576   1% /mnt/xzcdc

5、現在邏輯卷有10G了,擴容到13G,

#給邏輯卷擴容的前提,卷組裡面必要有多餘的空間,
[root@centos_8 ~]# lvextend -L +3G /dev/vg0/xzcdc 
  Size of logical volume vg0/xzcdc changed from 10.00 GiB (2560 extents) to 13.00 GiB (3328 extents).
  Logical volume vg0/xzcdc successfully resized.

 [root@centos_8 ~]# lvs
  LV    VG  Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  xzcdc vg0 -wi-ao---- 13.00g  
  
 #注意事項,擴充套件過後記憶體沒有上去,因為沒有格式化系統。
 # 如果是ext系列:resize2fs /dev/vg0/xzcdc
 #如果是xfs系列:xfs_growfs /dev/vg0/ xzcdc
#相容ext和xfs系列:lvextend -r -l +2000 /dev/vg0/xzcdc

6、新增一塊硬碟,新增到已有邏輯捲進行擴容

1、檢視新增加了硬碟
[root@centos_8 ~]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0  100G  0 disk 
├─sda1        8:1    0   15G  0 part /boot
├─sda2        8:2    0   20G  0 part /
├─sda3        8:3    0    5G  0 part /data
├─sda4        8:4    0    1K  0 part 
└─sda5        8:5    0   20G  0 part [SWAP]
sdb           8:16   0   30G  0 disk 
└─vg0-xzcdc 253:0    0   13G  0 lvm  
sdc           8:32   0   20G  0 disk 
sr0          11:0    1  8.8G  0 rom  
2、建立pv
[root@centos_8 ~]# pvcreate /dev/sdc
  Physical volume "/dev/sdc" successfully created.
[root@centos_8 ~]# pvs
  PV         VG  Fmt  Attr PSize   PFree  
  /dev/sdb   vg0 lvm2 a--  <30.00g <17.00g
  /dev/sdc       lvm2 ---   20.00g  20.00g
3、把新建立的pv加入到vg中
[root@centos_8 ~]# vgextend vg0 /dev/sdc
  Volume group "vg0" successfully extended
[root@centos_8 ~]# vgs
  VG  #PV #LV #SN Attr   VSize  VFree 
  vg0   2   1   0 wz--n- 49.99g 36.99g
#現在整個vg0就變大了,由兩個pv組成
4、把新增的分割槽擴容至邏輯卷
root@centos_8 ~]# lvextend -L +20G /dev/vg0/xzcdc 
  Size of logical volume vg0/xzcdc changed from 13.00 GiB (3328 extents) to 33.00 GiB (8448 extents).
  Logical volume vg0/xzcdc successfully resized.
[root@centos_8 ~]# lvs
  LV    VG  Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  xzcdc vg0 -wi-a----- 33.00g                                                    
[root@centos_8 ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/vg0/xzcdc
  LV Name                xzcdc
  VG Name                vg0
  LV UUID                45Mkh7-w7Pu-bdbw-a4mU-kEch-BG2J-IEUjCH
  LV Write Access        read/write
  LV Creation host, time centos_8, 2021-12-15 18:53:51 +0800
  LV Status              available
  # open                 0
  LV Size                33.00 GiB
  Current LE             8448
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
[root@centos_8 ~]# vgs
  VG  #PV #LV #SN Attr   VSize  VFree 
  vg0   2   1   0 wz--n- 49.99g 16.99g

#整個lv擁有33G空間,而vg還剩下16.99G


7、刪除lv,pv,vg

1、刪除lv
[root@centos_8 ~]# lvremove /dev/vg0/xzcdc 
Do you really want to remove active logical volume vg0/xzcdc? [y/n]: y
  Logical volume "xzcdc" successfully removed
[root@centos_8 ~]# lvs
#刪除lv是可以直接刪除的,但是刪除vg和pv的話,必須要先刪除vg在刪除pv
[root@centos_8 ~]# vgremove vg0
  Volume group "vg0" successfully removed
[root@centos_8 ~]# vgs
[root@centos_8 ~]# pvremove /dev/sdb
  Labels on physical volume "/dev/sdb" successfully wiped.
[root@centos_8 ~]# pvremove /dev/sdc
  Labels on physical volume "/dev/sdc" successfully wiped.
[root@centos_8 ~]# pvs