Linux——磁碟以及邏輯卷的介紹
一:磁碟的介紹
1:磁碟的分割槽:
磁碟分割槽的型別:
主分割槽
擴充套件分割槽
邏輯分割槽
其中主分割槽加擴充套件分割槽最多有4個,擴充套件分割槽不能存資料,擴充套件分割槽只能有一個對一個磁碟來說;但是有一個
缺陷:只能存資料,不能安裝系統,即便是安裝了,也不能啟動。
特殊:把一個磁碟可以直接做成一個擴充套件分割槽,在擴充套件分割槽上,建立邏輯分割槽,
2:格式化:
分割槽完成之後,格式化(建立檔案系統)
Linux上的檔案系統(單機檔案系統)
ext3,ext4,xfs(centos7上有)
3:掛載(凡是塊裝置,想要使用必須掛載),掛載到一個目錄上,這個目錄叫做掛載點;
例項:
首先新增一塊硬碟
檢視是否存在這塊硬碟:
[root@node03 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk ├─sda1 8:1 0 500M 0 part /boot └─sda2 8:2 0 19.5G 0 part ├─centos-root 253:0 0 17.5G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 8G 0 disk sr0 11:0 1 4G 0 rom [root@node03 ~]#
開始分割槽:
磁碟存放在/dev/下 [root@node03 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk ├─sda1 8:1 0 500M 0 part /boot └─sda2 8:2 0 19.5G 0 part ├─centos-root 253:0 0 17.5G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 8G 0 disk sr0 11:0 1 4G 0 rom [root@node03 ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x9e93954e. Command (m for help): Command (m for help): m Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition g create a new empty GPT partition table G create an IRIX (SGI) partition table l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) 其中常用的指令: n:add新增一個分割槽 d:delete刪除 w:儲存退出 q:退出不儲存 t:修改分割槽的id p:顯示分割槽的結果 Partition type: p primary (0 primary, 0 extended, 4 free) 代表主分割槽 e extended 代表擴充套件分割槽 建立500M的分割槽:+500M
建立檔案系統:
mkfs -t 檔案系統 磁碟分割槽名稱
或者
mkfs.檔案系統 磁碟分割槽名稱
[root@node03 ~]# mkfs.
mkfs.btrfs mkfs.cramfs mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.minix mkfs.xfs
例項2:
主分割槽1 ,為500M,掛載到 /bj
主分割槽2,為500M,掛載到/sh
邏輯分割槽5:為500M,掛載到/tj
邏輯分割槽6:為500M,掛載到/wh
建立ext4的檔案系統;
1.建立分割槽
[root@node03 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x52e91368.
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help):
建立主分割槽1
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-16777215, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-16777215, default 16777215): +500M
Partition 1 of type Linux and of size 500 MiB is set
建立主分割槽2
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (1026048-16777215, default 1026048):
Using default value 1026048
Last sector, +sectors or +size{K,M,G} (1026048-16777215, default 16777215): +500M
Partition 2 of type Linux and of size 500 MiB is set
建立擴充套件分割槽,把剩餘的空間都給,擴充套件分割槽
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): e
Partition number (3,4, default 3):
First sector (2050048-16777215, default 2050048):
Using default value 2050048
Last sector, +sectors or +size{K,M,G} (2050048-16777215, default 16777215):
Using default value 16777215
Partition 3 of type Extended and of size 7 GiB is set
建立邏輯分割槽:5
Command (m for help): n
Partition type:
p primary (2 primary, 1 extended, 1 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (2052096-16777215, default 2052096):
Using default value 2052096
Last sector, +sectors or +size{K,M,G} (2052096-16777215, default 16777215): +500M
Partition 5 of type Linux and of size 500 MiB is set
建立邏輯分割槽6
Command (m for help): n
Partition type:
p primary (2 primary, 1 extended, 1 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 6
First sector (3078144-16777215, default 3078144):
Using default value 3078144
Last sector, +sectors or +size{K,M,G} (3078144-16777215, default 16777215): +500M
Partition 6 of type Linux and of size 500 MiB is set
最後輸入:w代表儲存退出;
檢視創建出來的分割槽:
[root@node03 ~]# lsblk|grep sdb
sdb 8:16 0 8G 0 disk
├─sdb1 8:17 0 500M 0 part
├─sdb2 8:18 0 500M 0 part
├─sdb3 8:19 0 1K 0 part
├─sdb5 8:21 0 500M 0 part
└─sdb6 8:22 0 500M 0 part
分割槽創建出來,想要這個分割槽能正常使用,確保核心能識別到;
[root@node03 ~]# cat /proc/partitions
major minor #blocks name
8 16 8388608 sdb
8 17 512000 sdb1
8 18 512000 sdb2
8 19 1 sdb3
8 21 512000 sdb5
8 22 512000 sdb6
8 0 20971520 sda
8 1 512000 sda1
8 2 20458496 sda2
11 0 4228096 sr0
253 0 18317312 dm-0
253 1 2097152 dm-1
為了避免不生效
partprobe /dev/sdb 磁碟名稱
建立檔案系統:
mkfs -t ext4 /dev/sdb1
mkfs -t ext4 /dev/sdb2
mkfs -t ext4 /dev/sdb5
mkfs -t ext4 /dev/sdb6
建立掛載點
mkdir /{bj,sh,tj,wh}
掛載:(實現開機自動掛載)
[root@node03 ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sat Nov 28 23:28:09 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=77d39fde-4252-4586-a797-0cf0566a3e5c /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
/dev/sdb1 /bj ext4 defaults 0 0
/dev/sdb2 /tj ext4 defaults 0 0
/dev/sdb5 /wh ext4 defaults 0 0
/dev/sdb6 /sh ext4 defaults 0 0
讓系統重新讀取以下/etc/fstab mount -a
[root@node03 ~]# mount -a
檢視:
[root@node03 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 18G 930M 17G 6% /
devtmpfs devtmpfs 479M 0 479M 0% /dev
tmpfs tmpfs 489M 0 489M 0% /dev/shm
tmpfs tmpfs 489M 6.7M 483M 2% /run
tmpfs tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 xfs 497M 125M 373M 25% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0
/dev/sdb1 ext4 477M 2.3M 445M 1% /bj
/dev/sdb2 ext4 477M 2.3M 445M 1% /tj
/dev/sdb5 ext4 477M 2.3M 445M 1% /wh
/dev/sdb6 ext4 477M 2.3M 445M 1% /sh
取消掛載:
[root@node03 ~]# umount /dev/sdb6
[root@node03 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 18G 930M 17G 6% /
devtmpfs devtmpfs 479M 0 479M 0% /dev
tmpfs tmpfs 489M 0 489M 0% /dev/shm
tmpfs tmpfs 489M 6.7M 483M 2% /run
tmpfs tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 xfs 497M 125M 373M 25% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0
/dev/sdb1 ext4 477M 2.3M 445M 1% /bj
/dev/sdb2 ext4 477M 2.3M 445M 1% /tj
/dev/sdb5 ext4 477M 2.3M 445M 1% /wh
檢視某一個裝置的id(檢視uuid的目的是,在掛載時可以用uuid)
[root@node03 ~]# blkid /dev/sdb6
/dev/sdb6: UUID="a0e776f0-e638-4efd-b2dd-2d95f7cc2c72" TYPE="ext4"
二:邏輯卷的介紹
優勢:在常規使用磁碟時它有一個缺陷,比如我伺服器上有500G的磁碟,我要對其經行分割槽,格式化掛載,在磁碟中存放資料,當我的資料量大於磁碟的容量時,怎麼辦?
可以把這個磁碟擴容成一個較大容量,使用lvm方式管理磁碟;
lvm管理磁碟的過程:
它利用物理磁碟或分割槽虛擬出一個邏輯磁碟出來,將來儲存資料在這個虛擬的磁碟上;
1:首先把物理磁碟轉換成lvm管理的最基本的單位,pv(物理卷),物理卷的名字和磁碟的名字相同
2:拿一個或多個pv組成一個虛擬的磁碟池,這個磁碟池叫做VG(卷組),卷組叫什麼名自己起;
3:在卷組的基礎上建立邏輯卷(LV)
假設現在建立了一個lv,規劃的時候沒有規劃好,隨著資料越來越多,磁碟空間不夠大,可以擴充套件;而在擴充套件的時候原有的資料不會發生改變;
組成lv的底層裝置必須是裸裝置,裸裝置代表:沒有檔案系統。
工作流程:
磁碟/分割槽——》PV——》VG——》LV——》格式化——》掛載使用
建立PV:
pvcreate 磁碟/分割槽
檢視PV:
pvscan
建立VG
vgcreate 卷組名稱 物理卷名稱
檢視VG
vgscan 或vgdispaly 【卷組名稱】
LV的建立:
lvcreate -L 容量 -n 邏輯卷名稱 卷組名稱
檢視LV
lvscan
當用lvscan檢視時,有塊裝置檔案來標識它結構如下:
/dev/卷組名稱/邏輯卷名稱
例項1:
建立邏輯卷 /dev/data/webdata,大小為2G,為其建立ext4檔案系統,並將其掛載到/web/htdocs目錄
分析:
其中:data為卷組名,webdata為邏輯卷名
1:首先建立pv
pvcreate 硬碟名稱
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 19.5G 0 part
├─centos-root 253:0 0 17.5G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 10G 0 disk
sr0 11:0 1 4G 0 rom
[root@localhost ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created
檢視pv
[root@localhost ~]# pvscan
PV /dev/sda2 VG centos lvm2 [19.51 GiB / 40.00 MiB free]
PV /dev/sdb lvm2 [10.00 GiB]
Total: 2 [29.51 GiB] / in use: 1 [19.51 GiB] / in no VG: 1 [10.00 GiB]
2:建立vg
vgcreate 卷組名稱 物理卷名稱
[root@localhost ~]# vgcreate data /dev/sdb
Volume group "data" successfully created
檢視:
[root@localhost ~]# vgdisplay data
--- Volume group ---
VG Name data
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 10.00 GiB
PE Size 4.00 MiB
Total PE 2559
Alloc PE / Size 0 / 0
Free PE / Size 2559 / 10.00 GiB
VG UUID BHCNFG-9j0i-gFSx-qVAi-DIPj-Nbfv-U0LAMH
3:建立lv
lvcreate -L 大小 -n 邏輯卷名稱 卷組名稱
[root@localhost ~]# lvcreate -L 2G -n webdata data
Logical volume "webdata" created.
[root@localhost ~]# lvscan
ACTIVE '/dev/data/webdata' [2.00 GiB] inherit
ACTIVE '/dev/centos/swap' [2.00 GiB] inherit
ACTIVE '/dev/centos/root' [17.47 GiB] inherit
4:格式化(建立檔案系統)
mkfs.ext4 邏輯卷所對應的軟連線
[root@localhost ~]# mkfs.ext4 /dev/data/webdata
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
5:掛載
建立掛載點目錄:
mkdir -pv /web/htdocs
[root@localhost ~]# mkdir -pv /web/htdocs
mkdir: created directory ‘/web’
mkdir: created directory ‘/web/htdocs’
自動掛載:
編輯/etc/fstab
[root@localhost ~]# echo "/dev/data/webdata /web/htdocs ext4 defaults 0 0" >>/etc/fstab
[root@localhost ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Dec 24 17:02:01 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=c8c10022-ef8a-4f97-b5d2-a4899084f396 /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
/dev/data/webdata /web/htdocs ext4 defaults 0 0
mount -a (其目的是讓系統重新讀取以下/etc/fstab裡面的檔案)
6:驗證是否掛載成功:
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 18G 856M 17G 5% /
devtmpfs devtmpfs 479M 0 479M 0% /dev
tmpfs tmpfs 489M 0 489M 0% /dev/shm
tmpfs tmpfs 489M 6.7M 483M 2% /run
tmpfs tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 xfs 497M 125M 373M 25% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/data-webdata ext4 2.0G 6.0M 1.8G 1% /web/htdocs
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 19.5G 0 part
├─centos-root 253:0 0 17.5G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 10G 0 disk
└─data-webdata 253:2 0 2G 0 lvm /web/htdocs
sr0 11:0 1 4G 0 rom
例項2:擴充套件邏輯卷
擴充套件邏輯卷,首先擴充套件邏輯卷的物理邊界,延長的這部分空間預設存不了資料,因為擴大的這部分沒有檔案系統。
步驟:
1:擴充套件物理空間邊界
2:擴充套件檔案系統
需求:擴充套件邏輯卷/dev/data/webdata到4G
其中LV是基於VG創建出來的,首先檢視VG,確保VG的剩餘空間夠不夠,
1:首先檢視卷組的剩餘空間夠不夠;
1:檢視是那個卷組
[root@localhost ~]# lvscan
ACTIVE '/dev/data/webdata' [2.00 GiB] inherit
ACTIVE '/dev/centos/swap' [2.00 GiB] inherit
ACTIVE '/dev/centos/root' [17.47 GiB] inherit
2:檢視卷組的容量是否夠用
[root@localhost ~]# vgdisplay data
--- Volume group ---
VG Name data
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
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 10.00 GiB
PE Size 4.00 MiB
Total PE 2559
Alloc PE / Size 512 / 2.00 GiB
Free PE / Size 2047 / 8.00 GiB
VG UUID BHCNFG-9j0i-gFSx-qVAi-DIPj-Nbfv-U0LAMH
其中VG總大小:VG Size 10.00 GiB
剩餘的大小為:Free PE / Size 2047 / 8.00 GiB
也就是說確保了卷組的剩餘空間是足夠的;
如果不夠先擴展卷組,然後再擴充套件邏輯卷
2:擴充套件邏輯卷的物理空間
用到的命令是:lvextend,現在是2G再加2G,就到4G了;
[root@localhost ~]# lvextend -L +2G /dev/data/webdata
Size of logical volume data/webdata changed from 2.00 GiB (512 extents) to 4.00 GiB (1024 extents).
Logical volume webdata successfully resized.
檢視大小:
[root@localhost ~]# lvscan
ACTIVE '/dev/data/webdata' [4.00 GiB] inherit
ACTIVE '/dev/centos/swap' [2.00 GiB] inherit
ACTIVE '/dev/centos/root' [17.47 GiB] inherit
這個是它物理邊界的大小,已經擴充套件到了4G
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 18G 856M 17G 5% /
devtmpfs devtmpfs 479M 0 479M 0% /dev
tmpfs tmpfs 489M 0 489M 0% /dev/shm
tmpfs tmpfs 489M 6.7M 483M 2% /run
tmpfs tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 xfs 497M 125M 373M 25% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/data-webdata ext4 2.0G 6.0M 1.8G 1% /web/htdocs
它的檔案系統還是2G,因此需要擴充套件檔案系統;
3:擴充套件檔案系統
resize2fs 邏輯卷名稱
注意:
1:resize2fs只適用於ext3/ext4這樣的檔案系統
2:如果是xfs檔案系統,那麼用:xfs_growfs
/dev/mapper/data-webdata ext4 2.0G 6.0M 1.8G 1% /web/htdocs
[root@localhost ~]# resize2fs /dev/data/webdata
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/data/webdata is mounted on /web/htdocs; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/data/webdata is now 1048576 blocks long.
檢視大小
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 18G 856M 17G 5% /
devtmpfs devtmpfs 479M 0 479M 0% /dev
tmpfs tmpfs 489M 0 489M 0% /dev/shm
tmpfs tmpfs 489M 6.7M 483M 2% /run
tmpfs tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 xfs 497M 125M 373M 25% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/data-webdata ext4 3.9G 8.0M 3.7G 1% /web/htdocs
例項3:擴充套件邏輯捲到10G
首先檢視lv的大小:
[root@localhost ~]# lvscan
ACTIVE '/dev/data/webdata' [4.00 GiB] inherit
ACTIVE '/dev/centos/swap' [2.00 GiB] inherit
ACTIVE '/dev/centos/root' [17.47 GiB] inherit
為4G,還需要16G
檢視vg
[root@localhost ~]# vgdisplay data
--- Volume group ---
VG Name data
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
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 10.00 GiB
PE Size 4.00 MiB
Total PE 2559
Alloc PE / Size 1024 / 4.00 GiB
Free PE / Size 1535 / 6.00 GiB
VG UUID BHCNFG-9j0i-gFSx-qVAi-DIPj-Nbfv-U0LAMH
現在卷組的剩餘空間不夠;所以需要擴展卷組
現在卷組的剩餘空間不夠;所以需要擴展卷組
即再加一塊盤,轉化成pv物理卷,然後把物理卷卷加到卷組裡面來
轉換成物理卷
[root@localhost ~]# pvcreate /dev/sdc
Physical volume "/dev/sdc" successfully created
[root@localhost ~]# pvscan
PV /dev/sda2 VG centos lvm2 [19.51 GiB / 40.00 MiB free]
PV /dev/sdb VG data lvm2 [10.00 GiB / 6.00 GiB free]
PV /dev/sdc lvm2 [15.00 GiB]
Total: 3 [44.50 GiB] / in use: 2 [29.50 GiB] / in no VG: 1 [15.00 GiB]
擴展卷組:
vgextend 卷組名 物理卷名
[root@localhost ~]# vgextend data /dev/sdc
Volume group "data" successfully extended
檢視vg的大小:
[root@localhost ~]# vgdisplay data
--- Volume group ---
VG Name data
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 24.99 GiB
PE Size 4.00 MiB
Total PE 6398
Alloc PE / Size 1024 / 4.00 GiB
Free PE / Size 5374 / 20.99 GiB
VG UUID BHCNFG-9j0i-gFSx-qVAi-DIPj-Nbfv-U0LAMH
即卷組總大小: VG Size 24.99 GiB
剩餘大小 : Free PE / Size 5374 / 20.99 GiB
擴充套件lv
[root@localhost ~]# lvextend -L +16G -n /dev/data/webdata
Size of logical volume data/webdata changed from 4.00 GiB (1024 extents) to 20.00 GiB (5120 extents).
Logical volume webdata successfully resized.
檢視lv的大小:
[root@localhost ~]# lvscan
ACTIVE '/dev/data/webdata' [20.00 GiB] inherit
ACTIVE '/dev/centos/swap' [2.00 GiB] inherit
ACTIVE '/dev/centos/root' [17.47 GiB] inherit
擴充套件檔案系統:
[root@localhost ~]# resize2fs /dev/data/webdata
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/data/webdata is mounted on /web/htdocs; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 3
The filesystem on /dev/data/webdata is now 5242880 blocks long.
檢視:
[root@localhost ~]# lvscan
ACTIVE '/dev/data/webdata' [20.00 GiB] inherit
ACTIVE '/dev/centos/swap' [2.00 GiB] inherit
ACTIVE '/dev/centos/root' [17.47 GiB] inherit
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 18G 856M 17G 5% /
devtmpfs devtmpfs 479M 0 479M 0% /dev
tmpfs tmpfs 489M 0 489M 0% /dev/shm
tmpfs tmpfs 489M 6.7M 483M 2% /run
tmpfs tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 xfs 497M 125M 373M 25% /boot
/dev/mapper/data-webdata ext4 20G 11M 19G 1% /web/htdocs
tmpfs tmpfs 98M 0 98M 0% /run/user/0