1、創建一個2G的文件系統,塊大小爲2048byte,預留1%可用空間,文件系統 ext4,卷標爲TEST,要求此分區開機後自動掛載至/test目錄,且默認有acl掛載選項
#此次分區將在sdb這次磁盤進行
[root@client_1 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 10G 0 disk
sr0 11:0 1 4.4G 0 rom
sr1 11:1 1 4.4G 0 rom /mnt/cd
#對/dev/sdb進行分區
[root@client_1 ~]# 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 0x1758fbbb.
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): 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-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +2G
Partition 1 of type Linux and of size 2 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
#查看分區,sdb已經分出了一個2G的磁盤
[root@client_1 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 10G 0 disk
└─sdb1 8:17 0 2G 0 part
sr0 11:0 1 4.4G 0 rom
sr1 11:1 1 4.4G 0 rom /mnt/cd
下面對2G分區,創建ext4文件系統,並指定塊大小爲2048byte,預留1%可用空間,卷標爲TEST
[root@client_1 ~]# mkfs.ext4 -b 2048 -m 1 -L TEST /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=TEST
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 1048576 blocks
10485 blocks (1.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=269484032
64 block groups
16384 blocks per group, 16384 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
查看sdb1的分區信息
[root@client_1 ~]# blkid | grep sdb1
/dev/sdb1: LABEL="TEST" UUID="929155aa-17d4-4f22-a3a5-f0d0e453fd5d" TYPE="ext4"
掛載sdb1至/test目錄下,並開啓acl權限
[root@client_1 ~]# mkdir /test
[root@client_1 ~]#echo "UUID=929155aa-17d4-4f22-a3a5-f0d0e453fd5d /test ext4 acl 0 0" >> /etc/fstab
[root@client_1 ~]# mount -a
[root@client_1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 470M 0 470M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 8.3M 478M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 4.1G 13G 24% /
/dev/sda1 1014M 171M 844M 17% /boot
tmpfs 98M 12K 98M 1% /run/user/42
tmpfs 98M 0 98M 0% /run/user/0
/dev/sr1 4.4G 4.4G 0 100% /mnt/cd
/dev/sdb1 2.0G 9.1M 1.9G 1% /test
2、創建一個至少有兩個PV組成的大小爲20G的名爲testvg的VG;要求PE大小 爲16MB, 而後在卷組中創建大小爲5G的邏輯卷testlv;掛載至/users目錄
此次操作,將使用sdc和sdd兩塊磁盤
[root@client_1 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 10G 0 disk
└─sdb1 8:17 0 2G 0 part /test
sdc 8:32 0 10G 0 disk
sdd 8:48 0 10G 0 disk
sr0 11:0 1 4.4G 0 rom
sr1 11:1 1 4.4G 0 rom /mnt/cd
創建物理卷
[root@client_1 ~]# pvcreate /dev/sd{c,d}
Physical volume "/dev/sdc" successfully created.
Physical volume "/dev/sdd" successfully created.
查看物理卷信息
[root@client_1 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <19.00g 0
/dev/sdc lvm2 --- 10.00g 10.00g
/dev/sdd lvm2 --- 10.00g 10.00g
創建名爲testvg,PE爲16MB的卷組
[root@client_1 ~]# vgcreate -s 16M testvg /dev/sd{c,d}
Volume group "testvg" successfully created
查看卷組信息
[root@client_1 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- <19.00g 0
testvg 2 0 0 wz--n- <19.97g <19.97g
創建5G邏輯卷testlv
[root@client_1 ~]# lvcreate -n testlv -L 5G testvg
Logical volume "testlv" created.
查看邏輯卷信息
[root@client_1 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/testvg/testlv
LV Name testlv
VG Name testvg
LV UUID q36vfS-CJzP-lu1g-FuKD-k29S-PVUW-bWhCG2
LV Write Access read/write
LV Creation host, time client_1, 2020-03-29 22:29:30 +0800
LV Status available
# open 0
LV Size 5.00 GiB
Current LE 320
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
...
對於邏輯卷testlv 創建文件系統
[root@client_1 ~]# mkfs.xfs /dev/testvg/testlv
meta-data=/dev/testvg/testlv isize=512 agcount=4, agsize=327680 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=1310720, 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
掛載至/users目錄
[root@client_1 ~]# mount /dev/testvg/testlv /users
[root@client_1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
...
/dev/mapper/testvg-testlv 5.0G 33M 5.0G 1% /users