一、LVM方式
概念
- LVM:邏輯卷管理器,是建立在物理存儲設(shè)備上的一個抽象層,允許你生成邏輯存儲卷,與硬件相關(guān)的存儲設(shè)置被其隱藏,
你不用停止應(yīng)用或卸載文件系統(tǒng)來調(diào)整卷大小或遷移數(shù)據(jù),可以彈性管理你的分區(qū)。 - 物理卷:直接對應(yīng)實際硬盤分區(qū),也可以是整個硬盤或已創(chuàng)建的軟RAID,是LVM的基本存儲設(shè)備。
- 卷組:是由一個或多個物理卷所組成的存儲池,在卷組上能創(chuàng)建一個或多個邏輯卷。
- 邏輯卷:類似于非LVM系統(tǒng)中的硬盤分區(qū),它建立在卷組之上,是一個標(biāo)準(zhǔn)的塊設(shè)備,在邏輯卷上可以建立文件系統(tǒng)。
創(chuàng)建
- 創(chuàng)建一個物理卷:
pvcreate (硬盤分區(qū),如:/dev/sdb1)(把硬盤分區(qū)轉(zhuǎn)換成物理卷,其中/dev/sdb1就是硬盤的掛載位置)
通過命令pvdisplay可以查看系統(tǒng)中所有的物理卷信息。
剛創(chuàng)建的物理卷不屬于任何卷組,不能直接使用。
另外,如果直接在一整塊盤的基礎(chǔ)上創(chuàng)建LVM分區(qū),之后想對該分區(qū)進行擴容,則只能使用加盤然后創(chuàng)建pv的方式擴容,不能對這塊盤進行擴容(特指虛擬機)。
比如一塊sdb的盤有1G,在基礎(chǔ)上直接創(chuàng)建了pv,沒有使用fdisk進行分區(qū),則如果該硬盤被擴容為了2G,則后續(xù)操作很復(fù)雜,甚至有可能無法擴容(本人沒有嘗試,但是一開始操作的時候就失敗了)
所以下面直接在磁盤基礎(chǔ)上創(chuàng)建lvm的方式,擴容時只適合直接添加一塊硬盤,然后在新硬盤上創(chuàng)建pv,之后就可以擴容了。
[root@hadoop101 /]# pvcreate /dev/sdd
Physical volume "/dev/sdd" successfully created.
- 創(chuàng)建一個卷組:
vgcreate (卷組名,如:vg_test) (物理卷,如:/dev/sdb1)
(物理卷可以是已創(chuàng)建的,也可以是未創(chuàng)建的,當(dāng)物理未創(chuàng)建時,該命令可直接創(chuàng)建一個物理卷,并加入卷組中)
通過命令vgdisplay可以查看系統(tǒng)中所有的物理卷信息。
[root@hadoop101 /]# vgcreate vg2 /dev/sdd
Volume group "vg2" successfully created
- 在卷組中創(chuàng)建邏輯卷:
lvcreate -l (邏輯卷大小,如:3G) -n (邏輯卷名稱,如:lv_test) (卷組名稱,如:vg_test)
邏輯卷大小的位置一般會使用 +100%FREE 這樣邏輯卷的大小就直接是整塊硬盤的大小
通過命令lvdisplay可以查看系統(tǒng)中所有的邏輯卷信息。
[root@hadoop101 /]# lvcreate -l +100%free -n lv2 vg2
Logical volume "lv2" created.
- 在邏輯卷創(chuàng)建文件系統(tǒng):
注意在掛在前需要先格式化lv,否則無法掛載,至于格式化成何種文件系統(tǒng),就看自己的選擇了。
(原文用法) mke2fs -j (邏輯卷,如:/dev/vg_test/lv_test)
(我的用法) mkfs.ext4 (邏輯卷,如:/dev/vg_test/lv_test)(這里卷組與邏輯卷是文件夾的包含關(guān)系)
也可以創(chuàng)建成其他的文件系統(tǒng),請網(wǎng)上查找mkfs的用法。
[root@hadoop101 /]# mkfs.ext4 /dev/mapper/vg2-lv2
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
196608 inodes, 785408 blocks
39270 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=805306368
24 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
- 掛載邏輯卷:
mount (邏輯卷,如:/dev/vg_test/lv_test) (掛載目錄,如:/opt)
[root@hadoop101 /]# mount /dev/mapper/vg2-lv2 /data2
[root@hadoop101 /]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.4G 0 1.4G 0% /dev
tmpfs tmpfs 1.4G 0 1.4G 0% /dev/shm
tmpfs tmpfs 1.4G 9.5M 1.4G 1% /run
tmpfs tmpfs 1.4G 0 1.4G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 46G 18G 29G 38% /
/dev/sda1 xfs 1014M 149M 866M 15% /boot
tmpfs tmpfs 283M 0 283M 0% /run/user/0
/dev/mapper/vg1-lv1 xfs 1017M 159M 859M 16% /data
/dev/mapper/vg2-lv2 ext4 2.9G 9.0M 2.8G 1% /data2
移除
要想完全移除物理卷,則必須按照如下順序進行,先取消掛載,后刪除邏輯卷,而后刪除卷組,最后才能移除物理卷
不要像我一樣傻了吧唧到/dev里刪除硬盤對應(yīng)的文件,那會導(dǎo)致之后使用LVM時報錯
- 卸載邏輯卷 umount (掛載目錄,如:/opt)
- 刪除邏輯卷 lvremove (邏輯卷,如:/dev/vg_test/lv_test)
- 刪除卷組: vgremove (卷組,如:/dev/vg_test)
- 刪除物理卷:pvremove (物理卷,如:/dev/sdb1)
擴容
擴容分兩種情況,一種是添加了新硬盤,那么就直接給lv擴容,如下,操作比較簡單。
先依照新硬盤創(chuàng)建pv,然后查看vg信息,給vg擴容。
[root@hadoop101 ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.
[root@hadoop101 ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <49.00 GiB
PE Size 4.00 MiB
Total PE 12543
Alloc PE / Size 12542 / 48.99 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID 86d1CJ-r9mM-A7Pf-eDzq-mWE5-aEp3-AXPNSy
--- Volume group ---
VG Name vg2
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 0
Max PV 0
Cur PV 1
Act PV 1
VG Size <3.00 GiB
PE Size 4.00 MiB
Total PE 767
Alloc PE / Size 767 / <3.00 GiB
Free PE / Size 0 / 0
VG UUID wf6BjR-hpYi-Lg6F-ZUqU-JdrI-TaYu-eSAbGx
[root@hadoop101 ~]# vgextend vg2 /dev/sdb
Volume group "vg2" successfully extended
然后查看lv信息,確定要擴容的lv,然后查看vg信息,查看vg有多少剩余空間可以擴容
[root@hadoop101 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID XZYGOt-0nrU-AssR-4Fix-sGKA-bC7P-rhdmdS
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2021-10-28 09:24:50 +0800
LV Status available
# open 2
LV Size 3.00 GiB
Current LE 768
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID lqA3m1-drgv-DQ2q-jJsB-PdO8-Ge2P-SMwT8s
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2021-10-28 09:24:51 +0800
LV Status available
# open 1
LV Size 45.99 GiB
Current LE 11774
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Logical volume ---
LV Path /dev/vg2/lv2
LV Name lv2
VG Name vg2
LV UUID I3x28B-fLfN-L4Z7-t5am-Yzp6-nVyG-rvL7ew
LV Write Access read/write
LV Creation host, time hadoop101, 2022-05-18 15:03:00 +0800
LV Status available
# open 0
LV Size <3.00 GiB
Current LE 767
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
[root@hadoop101 ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <49.00 GiB
PE Size 4.00 MiB
Total PE 12543
Alloc PE / Size 12542 / 48.99 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID 86d1CJ-r9mM-A7Pf-eDzq-mWE5-aEp3-AXPNSy
--- Volume group ---
VG Name vg2
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 3.99 GiB
PE Size 4.00 MiB
Total PE 1022
Alloc PE / Size 767 / <3.00 GiB
Free PE / Size 255 / 1020.00 MiB
VG UUID wf6BjR-hpYi-Lg6F-ZUqU-JdrI-TaYu-eSAbGx
擴容,+255就是上面vg剩余的空間,就是倒數(shù)第二行free pe那里,后面跟上要擴容的lv。
[root@hadoop101 ~]# lvextend -l+255 /dev/mapper/vg2-lv2
Size of logical volume vg2/lv2 changed from <3.00 GiB (767 extents) to 3.99 GiB (1022 extents).
Logical volume vg2/lv2 successfully resized.
如果給硬盤擴容了,但并沒有添加新的磁盤,這種情況多用于虛擬機,此時需要給物理卷,邏輯卷和文件系統(tǒng)分別擴容
[root@ambari-2 ~]# fdisk -l
Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000ad721
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 83886079 40893440 8e Linux LVM
Disk /dev/mapper/centos-root: 39.7 GB, 39720058880 bytes, 77578240 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
可以看到我的磁盤容量要大于下面分區(qū)的容量,因為我剛給磁盤擴了容
下面就根據(jù)給那塊盤擴容,就給那塊盤重新分區(qū)
[root@ambari-2 ~]# fdisk /dev/sda
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.
Command (m for help): p(此處回車,p表示查看當(dāng)前的分區(qū)情況)
Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000ad721
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 83886079 40893440 8e Linux LVM
Command (m for help): n(此處回車,n表示創(chuàng)建一個分區(qū))
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p(此處回車,p表示創(chuàng)建一個主分區(qū))
Partition number (3,4, default 3): 3(此處回車,3表示分區(qū)編號)
First sector (83886080-125829119, default 83886080): (直接回車)
Using default value 83886080
Last sector, +sectors or +size{K,M,G} (83886080-125829119, default 125829119): (直接回車)
Using default value 125829119
Partition 3 of type Linux and of size 20 GiB is set
Command (m for help): t(此處回車,t表示修改分區(qū)類型)
Partition number (1-3, default 3): 3(此處回車,3表示要修改的分區(qū))
Hex code (type L to list all codes): 8e(此處回車,8e表示LVM分區(qū))
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p(此處回車,p表示查看分區(qū)情況)
Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000ad721
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 83886079 40893440 8e Linux LVM
/dev/sda3 83886080 125829119 20971520 8e Linux LVM
Command (m for help): w(此處回車,w表示寫入磁盤并退出)
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@ambari-2 ~]# reboot
這里我最后一步是重啟的,如果不想重啟,或者服務(wù)器是生產(chǎn)環(huán)境不能重啟,則可以執(zhí)行下面的命令讓其在不重啟的情況下識別新分區(qū)。
先檢查是否安裝了parted包。然后執(zhí)行命令,最后的警告可以忽略,不影響實際使用。
[root@ambari-1 /]# rpm -q parted
parted-3.1-31.el7.x86_64
[root@ambari-1 /]# partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
之后我們再格式化分區(qū)
[root@ambari-2 ~]# mkfs.xfs /dev/sda3
meta-data=/dev/sda3 isize=512 agcount=4, agsize=1310720 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=5242880, 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
在新分區(qū)的基礎(chǔ)上創(chuàng)建PV
[root@ambari-2 ~]# pvcreate /dev/sda3
WARNING: xfs signature detected on /dev/sda3 at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/sda3.
Physical volume "/dev/sda3" successfully created.
查看已有的卷組及其卷組下包含的PV
[root@ambari-2 ~]# vgdisplay -v
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <39.00 GiB
PE Size 4.00 MiB
Total PE 9983
Alloc PE / Size 9982 / 38.99 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID fPqYS7-T6UR-gpMq-UVgA-L0YC-oNZW-pswGb4
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID jr24hL-9S92-lDoQ-vouu-qN3N-7OPv-RdWTt0
LV Write Access read/write
LV Creation host, time ambari-2, 2021-07-01 21:52:45 -0400
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID YhoiNU-8hZ0-A58R-6kVj-LXJ5-2StC-kHe2la
LV Write Access read/write
LV Creation host, time ambari-2, 2021-07-01 21:52:45 -0400
LV Status available
# open 1
LV Size 36.99 GiB
Current LE 9470
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Physical volumes ---
PV Name /dev/sda2
PV UUID BDThgK-V36X-BE9c-zo7K-UPYb-Nc8H-OS9ew2
PV Status allocatable
Total PE / Free PE 9983 / 1
將剛才創(chuàng)建好的PV加入卷組
[root@ambari-2 ~]# vgextend centos /dev/sda3
Volume group "centos" successfully extended
再次查看卷組
[root@ambari-2 ~]# vgdisplay -v
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 58.99 GiB
PE Size 4.00 MiB
Total PE 15102
Alloc PE / Size 9982 / 38.99 GiB
Free PE / Size 5120 / 20.00 GiB
VG UUID fPqYS7-T6UR-gpMq-UVgA-L0YC-oNZW-pswGb4
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID jr24hL-9S92-lDoQ-vouu-qN3N-7OPv-RdWTt0
LV Write Access read/write
LV Creation host, time ambari-2, 2021-07-01 21:52:45 -0400
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID YhoiNU-8hZ0-A58R-6kVj-LXJ5-2StC-kHe2la
LV Write Access read/write
LV Creation host, time ambari-2, 2021-07-01 21:52:45 -0400
LV Status available
# open 1
LV Size 36.99 GiB
Current LE 9470
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Physical volumes ---
PV Name /dev/sda2
PV UUID BDThgK-V36X-BE9c-zo7K-UPYb-Nc8H-OS9ew2
PV Status allocatable
Total PE / Free PE 9983 / 1
PV Name /dev/sda3 (這就是我們剛才添加的PV)
PV UUID 4pxqcc-h2kU-RTVo-3V4q-r8Ql-36tj-vec8FE
PV Status allocatable
Total PE / Free PE 5119 / 5119 (記住這個數(shù)字,一會擴容要用)
給卷組擴容
[root@ambari-2 ~]# lvextend -l+5119 /dev/mapper/centos-root
Size of logical volume centos/root changed from 36.99 GiB (9470 extents) to <56.99 GiB (14589 extents).
Logical volume centos/root successfully resized.
給文件系統(tǒng)擴容,有必要提前查看文件系統(tǒng)類型,使用df -Th命令即可,我就不查看了。
[root@ambari-2 ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=2424320 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=9697280, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=4735, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 9697280 to 14939136
最后查看是否完成擴容
[root@ambari-2 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.4G 0 1.4G 0% /dev
tmpfs tmpfs 1.4G 0 1.4G 0% /dev/shm
tmpfs tmpfs 1.4G 9.4M 1.4G 1% /run
tmpfs tmpfs 1.4G 0 1.4G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 57G 2.0G 56G 4% /
/dev/sda1 xfs 1014M 149M 866M 15% /boot
tmpfs tmpfs 283M 0 283M 0% /run/user/0
非LVM方式
[root@localhost /]# fdisk -l
磁盤 /dev/sda:21.5 GB, 21474836480 字節(jié),41943040 個扇區(qū)
Units = 扇區(qū) of 1 * 512 = 512 bytes
扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)
磁盤標(biāo)簽類型:dos
磁盤標(biāo)識符:0x000c4468
設(shè)備 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
磁盤 /dev/sdb:5368 MB, 5368709120 字節(jié),10485760 個扇區(qū)
Units = 扇區(qū) of 1 * 512 = 512 bytes
扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)
磁盤 /dev/mapper/centos-root:18.2 GB, 18249416704 字節(jié),35643392 個扇區(qū)
Units = 扇區(qū) of 1 * 512 = 512 bytes
扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)
磁盤 /dev/mapper/centos-swap:2147 MB, 2147483648 字節(jié),4194304 個扇區(qū)
Units = 扇區(qū) of 1 * 512 = 512 bytes
扇區(qū)大小(邏輯/物理):512 字節(jié) / 512 字節(jié)
I/O 大小(最小/最佳):512 字節(jié) / 512 字節(jié)
[root@localhost /]# fdisk /dev/sdb
歡迎使用 fdisk (util-linux 2.23.2)。
更改將停留在內(nèi)存中,直到您決定將更改寫入磁盤。
使用寫入命令前請三思。
Device does not contain a recognized partition table
使用磁盤標(biāo)識符 0x24a3943e 創(chuàng)建新的 DOS 磁盤標(biāo)簽。
命令(輸入 m 獲取幫助):n(此處回車,n表示新建分區(qū))
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p(此處回車,p表示創(chuàng)建一個主分區(qū))
分區(qū)號 (1-4,默認 1):1(此處回車,1表示分區(qū)編號,只能分四個區(qū),且用且珍惜)
起始 扇區(qū) (2048-10485759,默認為 2048):(此處回車)
將使用默認值 2048
Last 扇區(qū), +扇區(qū) or +size{K,M,G} (2048-10485759,默認為 10485759):(此處回車)
將使用默認值 10485759
分區(qū) 1 已設(shè)置為 Linux 類型,大小設(shè)為 5 GiB
命令(輸入 m 獲取幫助):w(此處回車,w表示寫入磁盤,否則更改將不會保存)
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盤。
[root@localhost /]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=327616 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=1310464, 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
[root@localhost /]# mount /dev/sdb1 /test_disk
[root@localhost /]# df -Th
文件系統(tǒng) 類型 容量 已用 可用 已用% 掛載點
devtmpfs devtmpfs 475M 0 475M 0% /dev
tmpfs tmpfs 487M 0 487M 0% /dev/shm
tmpfs tmpfs 487M 7.7M 479M 2% /run
tmpfs tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 17G 1.7G 16G 10% /
/dev/sda1 xfs 1014M 167M 848M 17% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0
/dev/sdb1 xfs 5.0G 33M 5.0G 1% /test_disk
硬盤默認開機不掛載,所以要設(shè)置開機自動掛載
[root@localhost /]# blkid
/dev/sda1: UUID="32b78c3c-33f5-4940-a81d-5b2cddc57af1" TYPE="xfs"
/dev/sda2: UUID="lQiwfj-K8kC-xoaL-YuRr-A3iC-ypYM-fLPG8B" TYPE="LVM2_member"
/dev/sr0: UUID="2019-09-11-18-50-31-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/mapper/centos-root: UUID="1434974b-50dc-4525-ae93-8ee46e61289d" TYPE="xfs"
/dev/mapper/centos-swap: UUID="f2d23ee0-ca99-4633-be00-ae827c0ea754" TYPE="swap"
/dev/sdb1: UUID="d9a507cb-601f-4ffb-8e11-86ac6538032d" TYPE="xfs"
[root@localhost /]# sed -i '$a\UUID=d9a507cb-601f-4ffb-8e11-86ac6538032d /apps xfs defaults 0 2' /etc/fstab
參數(shù)解釋:
UUID——要掛載的磁盤的UUID
/apps——掛載目錄
xfs——文件系統(tǒng)
defaults——掛載時所要設(shè)定的參數(shù)(只讀,讀寫,啟用quota等),輸入defaults包括的參數(shù)有(rw、dev、exec、auto、nouser、async)
0——使用dump是否要記錄,0為不需要,1為需要
2——2是開機時檢查的順序,boot系統(tǒng)文件為1,其他文件系統(tǒng)都為2,如不要檢查就為0