磁盘分区删除、创建及逻辑卷挂载
磁盘分区查看
使用lsblk命令查看当前磁盘分区情况
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 447.1G 0 disk
└─sda1 8:1 0 447.1G 0 part
sdb 8:16 0 4.4T 0 disk
├─sdb1 8:17 0 50G 0 part /boot/efi
├─sdb2 8:18 0 1G 0 part /boot
├─sdb3 8:19 0 4.2T 0 part
│ ├─lv-root 253:0 0 200G 0 lvm /
│ ├─lv-swap 253:1 0 20G 0 lvm [SWAP]
│ ├─lv-data 253:2 0 2.4T 0 lvm /data
│ ├─lv-audit 253:3 0 20G 0 lvm /var/audit
│ ├─lv-home 253:4 0 300G 0 lvm /home
│ ├─lv-var 253:5 0 1.2T 0 lvm /var
│ ├─lv-log 253:6 0 50G 0 lvm /var/log
│ └─lv-tmp 253:7 0 20G 0 lvm /tmp
└─sdb4 8:20 0 1007K 0 part
sr0 11:0 1 1024M 0 rom
可以查看到该节点上存在两个物理磁盘sda及sdb。
其中sda分区(part),分为sda1;sdb分区,分为sdb1,sdb2,sdb3,sdb4。
注:sd1-sd4其序号都是分配给主/扩展分区(即primary/extended分区),这边没有逻辑分区,逻辑分区序号从sdb5开始,且主、扩展分区最多为4个
在sdb3下划分LVM(Logical Volume Manager,逻辑卷管理器),通过划分LVM实现对跨磁盘卷组的使用
删除磁盘分区
通过fdisk方式删除磁盘分区
[root@localhost ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.37.4).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): m # 帮助
Help:
DOS (MBR)
a toggle a bootable flag
b edit nested BSD disklabel
c toggle the dos compatibility flag
Generic
d delete a partition
F list free unpartitioned space
l list known partition types
n add a new partition
p print the partition table
t change a partition type
v verify the partition table
i print information about a partition
Misc
m print this menu
u change display/entry units
x extra functionality (experts only)
Script
I load disk layout from sfdisk script file
O dump disk layout to sfdisk script file
Save & Exit
w write table to disk and exit
q quit without saving changes
Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty DOS partition table
s create a new empty Sun partition table
Command (m for help): d # 删除分区
Selected partition 1
Partition 1 has been deleted.
Command (m for help): w # 将修改写入磁盘
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 447.1G 0 disk
sdb 8:16 0 4.4T 0 disk
├─sdb1 8:17 0 50G 0 part /boot/efi
├─sdb2 8:18 0 1G 0 part /boot
├─sdb3 8:19 0 4.2T 0 part
│ ├─lv-root 253:0 0 200G 0 lvm /
│ ├─lv-swap 253:1 0 20G 0 lvm [SWAP]
│ ├─lv-data 253:2 0 2.4T 0 lvm /data
│ ├─lv-audit 253:3 0 20G 0 lvm /var/audit
│ ├─lv-home 253:4 0 300G 0 lvm /home
│ ├─lv-var 253:5 0 1.2T 0 lvm /var
│ ├─lv-log 253:6 0 50G 0 lvm /var/log
│ └─lv-tmp 253:7 0 20G 0 lvm /tmp
└─sdb4 8:20 0 1007K 0 part
sr0 11:0 1 1024M 0 rom
若完全格式化磁盘,也可以使用mkfs命令
mkfs.ext4 /dev/sdb # 将磁盘格式化为ext4文件系统
mkfs.xfs /dev/sdb # 将磁盘格式化为xfs文件系统
创建分区
通过fdisk方式创建分区
[root@localhost ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.37.4).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n # 创建新分区
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): # 创建primary分区
Using default response p.
Partition number (1-4, default 1): # 分区序号为sda1
First sector (2048-937637551, default 2048): # start开始于哪个字节
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-937637551, default 937637551): # end终止于哪个字节
Created a new partition 1 of type 'Linux' and of size 447.1 GiB.
Command (m for help): w # 确认修改,写入磁盘
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# lsblk # 发现创建完成sda1新分区
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 447.1G 0 disk
└─sda1 8:1 0 447.1G 0 part
sdb 8:16 0 4.4T 0 disk
├─sdb1 8:17 0 50G 0 part /boot/efi
├─sdb2 8:18 0 1G 0 part /boot
├─sdb3 8:19 0 4.2T 0 part
│ ├─lv-root 253:0 0 200G 0 lvm /
│ ├─lv-swap 253:1 0 20G 0 lvm [SWAP]
│ ├─lv-data 253:2 0 2.4T 0 lvm /data
│ ├─lv-audit 253:3 0 20G 0 lvm /var/audit
│ ├─lv-home 253:4 0 300G 0 lvm /home
│ ├─lv-var 253:5 0 1.2T 0 lvm /var
│ ├─lv-log 253:6 0 50G 0 lvm /var/log
│ └─lv-tmp 253:7 0 20G 0 lvm /tmp
└─sdb4 8:20 0 1007K 0 part
sr0 11:0 1 1024M 0 rom
也可以通过parted方式创建分区(未实践)
[root@director13 html]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p # 创建分区
Model: TOSHIBA AL14SEB090N (scsi)
Disk /dev/sdb: 900GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
(parted) mkpart primary xfs 0% 100% # 创建xfs分区
(parted) p
Model: TOSHIBA AL14SEB090N (scsi)
Disk /dev/sdb: 900GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 900GB 900GB primary
(parted) quit # 退出
Information: You may need to update /etc/fstab.
创建逻辑卷
按照物理卷->卷组->LVM逻辑卷组的方式创建逻辑卷
[root@localhost ~]# pvcreate /dev/sda1 # 将物理硬盘分区初始化为物理卷
Device /dev/sdb3 has updated name (devices file /dev/sda3)
Physical volume "/dev/sda1" successfully created.
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# vgcreate ocp-data /dev/sda1 # 创建LVM卷组
Volume group "ocp-data" successfully created
[root@localhost ~]#
[root@localhost ~]# lvcreate -n ocp-vol -l 100%FREE ocp-data #创建LVM的逻辑卷组
Logical volume "ocp-vol" created.
[root@localhost ~]# lvs # 查看逻辑卷组情况
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
audit lv -wi-ao---- 20.00g
data lv -wi-ao---- 2.40t
home lv -wi-ao---- 300.00g
log lv -wi-ao---- 50.00g
root lv -wi-ao---- 200.00g
swap lv -wi-ao---- 20.00g
tmp lv -wi-ao---- 20.00g
var lv -wi-ao---- 1.17t
ocp-vol ocp-data -wi-a----- <447.10g
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# mkfs.xfs /dev/mapper/ocp--data-ocp--vol # 格式化文件系统为xfs
meta-data=/dev/mapper/ocp--data-ocp--vol isize=512 agcount=16, agsize=7325248 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=1 inobtcount=1
data = bsize=4096 blocks=117203968, imaxpct=25
= sunit=64 swidth=64 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=57228, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
挂载逻辑卷
创建目录,将创建的逻辑卷挂载在目录下,达到该目录使用sda磁盘的效果
[root@localhost ~]# mkdir -p /ocp-data # 创建目录
[root@localhost ~]# mount /dev/mapper/ocp--data-ocp--vol /ocp-data/ #将逻辑卷挂载在目录下
[root@localhost ~]# mount # 查看挂载情况
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=4096k,nr_inodes=1048576,mode=755,inode64)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel,inode64)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,size=211246912k,nr_inodes=819200,mode=755,inode64)
cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime,seclabel,nsdelegate,memory_recursiveprot)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime,seclabel)
efivarfs on /sys/firmware/efi/efivars type efivarfs (rw,nosuid,nodev,noexec,relatime)
none on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)
/dev/mapper/lv-root on / type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,sunit=512,swidth=1024,noquota)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,nosuid,noexec,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=31,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=104953)
mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime,seclabel)
debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime,seclabel)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel,pagesize=2M)
tracefs on /sys/kernel/tracing type tracefs (rw,nosuid,nodev,noexec,relatime,seclabel)
fusectl on /sys/fs/fuse/connections type fusectl (rw,nosuid,nodev,noexec,relatime)
configfs on /sys/kernel/config type configfs (rw,nosuid,nodev,noexec,relatime)
/dev/sdb2 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,sunit=512,swidth=1024,noquota)
/dev/sdb1 on /boot/efi type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=ascii,shortname=winnt,errors=remount-ro)
/dev/mapper/lv-data on /data type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,sunit=512,swidth=1024,noquota)
/dev/mapper/lv-home on /home type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,sunit=512,swidth=1024,noquota)
/dev/mapper/lv-tmp on /tmp type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,sunit=512,swidth=1024,noquota)
/dev/mapper/lv-var on /var type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,sunit=512,swidth=1024,noquota)
/dev/mapper/lv-audit on /var/audit type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,sunit=512,swidth=1024,noquota)
/dev/mapper/lv-log on /var/log type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,sunit=512,swidth=1024,noquota)
tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=105623452k,nr_inodes=26405863,mode=700,uid=1000,gid=1000,inode64)
gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=105623452k,nr_inodes=26405863,mode=700,inode64)
/dev/mapper/ocp--data-ocp--vol on /ocp-data type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,sunit=512,swidth=512,noquota) # 查看到新建的逻辑卷已成功挂载
[root@localhost ~]#
[root@localhost ~]# echo "/dev/mapper/ocp--data-ocp--vol /ocp-data xfs defaults 0 0" >> /etc/fstab
[root@localhost ~]#
[root@localhost ~]# cat /etc/fstab #修改/etc/fstab文件,将创建的逻辑卷加到配置文件中,实现自动挂载,可以通过vim编辑或者通过echo方式写入
#
# /etc/fstab
# Created by anaconda on Thu May 4 14:00:36 2023
#
# 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.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/lv-root / xfs defaults 0 0
UUID=3259e917-7aff-47cc-8c63-bec392a2ba3e /boot xfs defaults 0 0
UUID=A7EA-C3B0 /boot/efi vfat umask=0077,shortname=winnt 0 2
/dev/mapper/lv-data /data xfs defaults 0 0
/dev/mapper/lv-home /home xfs defaults 0 0
/dev/mapper/lv-tmp /tmp xfs defaults 0 0
/dev/mapper/lv-var /var xfs defaults 0 0
/dev/mapper/lv-audit /var/audit xfs defaults 0 0
/dev/mapper/lv-log /var/log xfs defaults 0 0
/dev/mapper/lv-swap none swap defaults 0 0
/dev/mapper/ocp--data-ocp--vol /ocp-data xfs defaults 0 0
验证是否实现自动挂载
[root@localhost ~]# umount /ocp-data # 卸除挂载
[root@localhost ~]# mount
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=4096k,nr_inodes=1048576,mode=755,inode64)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel,inode64)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,size=211246912k,nr_inodes=819200,mode=755,inode64)
cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime,seclabel,nsdelegate,memory_recursiveprot)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime,seclabel)
efivarfs on /sys/firmware/efi/efivars type efivarfs (rw,nosuid,nodev,noexec,relatime)
none on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)
/dev/mapper/lv-root on / type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,sunit=512,swidth=1024,noquota)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,nosuid,noexec,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=31,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=104953)
mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime,seclabel)
debugfs on /sys/kernel/debug type debugfs (rw,nosuid,nodev,noexec,relatime,seclabel)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel,pagesize=2M)
tracefs on /sys/kernel/tracing type tracefs (rw,nosuid,nodev,noexec,relatime,seclabel)
fusectl on /sys/fs/fuse/connections type fusectl (rw,nosuid,nodev,noexec,relatime)
configfs on /sys/kernel/config type configfs (rw,nosuid,nodev,noexec,relatime)
/dev/sdb2 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,sunit=512,swidth=1024,noquota)
/dev/sdb1 on /boot/efi type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=ascii,shortname=winnt,errors=remount-ro)
/dev/mapper/lv-data on /data type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,sunit=512,swidth=1024,noquota)
/dev/mapper/lv-home on /home type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,sunit=512,swidth=1024,noquota)
/dev/mapper/lv-tmp on /tmp type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,sunit=512,swidth=1024,noquota)
/dev/mapper/lv-var on /var type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,sunit=512,swidth=1024,noquota)
/dev/mapper/lv-audit on /var/audit type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,sunit=512,swidth=1024,noquota)
/dev/mapper/lv-log on /var/log type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,sunit=512,swidth=1024,noquota)
tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=105623452k,nr_inodes=26405863,mode=700,uid=1000,gid=1000,inode64)
gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=105623452k,nr_inodes=26405863,mode=700,inode64)
/dev/mapper/ocp--data-ocp--vol on /ocp-data type xfs (rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,sunit=512,swidth=512,noquota)
删除LVM
按照取消挂载->取消逻辑卷->取消卷组->取消物理卷的顺序删除LVM
[root@localhost image]# umount /ocp-data # 取消挂载
[root@localhost image]# lvdisplay # 查看逻辑卷挂载情况
--- Logical volume ---
LV Path /dev/lv/data
LV Name data
VG Name lv
LV UUID rWYey7-syZC-biXR-fB3F-cYuh-IaLt-mrU93C
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2023-05-04 22:00:22 +0800
LV Status available
# open 1
LV Size 2.40 TiB
Current LE 629146
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 2048
Block device 253:2
--- Logical volume ---
LV Path /dev/lv/audit
LV Name audit
VG Name lv
LV UUID UiZVHd-HNeC-PF1Y-C5Dv-lgDS-kRZY-HjgGwO
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2023-05-04 22:00:23 +0800
LV Status available
# open 1
LV Size 20.00 GiB
Current LE 5120
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 2048
Block device 253:3
--- Logical volume ---
LV Path /dev/lv/home
LV Name home
VG Name lv
LV UUID KwNi7Z-EkXe-VMfT-IN71-Xnrp-OSwd-WZ7NUS
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2023-05-04 22:00:26 +0800
LV Status available
# open 1
LV Size 300.00 GiB
Current LE 76800
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 2048
Block device 253:4
--- Logical volume ---
LV Path /dev/lv/root
LV Name root
VG Name lv
LV UUID 6Dax8e-NGiG-gOAX-Usb8-KgWx-RIcn-sDUHbW
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2023-05-04 22:00:26 +0800
LV Status available
# open 1
LV Size 200.00 GiB
Current LE 51200
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 2048
Block device 253:0
--- Logical volume ---
LV Path /dev/lv/var
LV Name var
VG Name lv
LV UUID HVhhqX-9gT6-0k8f-yPD5-QCEV-vNRK-38lohl
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2023-05-04 22:00:27 +0800
LV Status available
# open 1
LV Size 1.17 TiB
Current LE 307200
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 2048
Block device 253:5
--- Logical volume ---
LV Path /dev/lv/log
LV Name log
VG Name lv
LV UUID 0H4R1h-7r6G-jfhZ-Ar6a-xcE7-8gvU-865hzS
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2023-05-04 22:00:27 +0800
LV Status available
# open 1
LV Size 50.00 GiB
Current LE 12800
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 2048
Block device 253:6
--- Logical volume ---
LV Path /dev/lv/tmp
LV Name tmp
VG Name lv
LV UUID 8m3rFL-49rS-bBvE-uJ4a-DxHP-e3eM-nLqP0e
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2023-05-04 22:00:29 +0800
LV Status available
# open 1
LV Size 20.00 GiB
Current LE 5120
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 2048
Block device 253:7
--- Logical volume ---
LV Path /dev/lv/swap
LV Name swap
VG Name lv
LV UUID ua7iw9-iuJn-XoPU-yclc-nrxK-k4tl-ZxCklb
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2023-05-04 22:00:30 +0800
LV Status available
# open 2
LV Size 20.00 GiB
Current LE 5120
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 2048
Block device 253:1
--- Logical volume ---
LV Path /dev/ocp-data/ocp-vol # 找到要取消的lv
LV Name ocp-vol
VG Name ocp-data
LV UUID IGarxo-VcrR-D7HQ-c3gL-wXfg-I7uQ-vAed0b
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2023-05-05 20:38:45 +0800
LV Status available
# open 0
LV Size <447.10 GiB
Current LE 114457
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 1024
Block device 253:8
[root@localhost image]# lvremove /dev/ocp-data/ocp-vol # 取消lv(逻辑卷)
Do you really want to remove active logical volume ocp-data/ocp-vol? [y/n]: y # 确认
Logical volume "ocp-vol" successfully removed.
[root@localhost image]# vgremove /dev/ocp-data # 取消vg(卷组)
Volume group "ocp-data" successfully removed
[root@localhost image]# pvdisplay # 查看物理卷情况
--- Physical volume ---
PV Name /dev/sdb3
VG Name lv
PV Size <4.17 TiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 1092507
Free PE 1
Allocated PE 1092506
PV UUID 08e3Cn-telD-fIcu-vy0X-Pjm1-SfUq-xaRe8n
"/dev/sda1" is a new physical volume of "<447.10 GiB"
--- NEW Physical volume ---
PV Name /dev/sda1 # 找到要取消的物理卷
VG Name
PV Size <447.10 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID utBHGy-kjLt-J1r9-93Ku-gGrG-hpwD-3qIi5b
[root@localhost image]# pvremove /dev/sda1 # 取消物理卷
Labels on physical volume "/dev/sda1" successfully wiped.
[root@localhost image]#
直接挂载分区
如果不需要LVM,可以直接将分区挂载在目录下
[root@localhost ocp-data]# lsblk # 查看磁盘分区情况
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 447.1G 0 disk
└─sda1 8:1 0 447.1G 0 part
sdb 8:16 0 4.4T 0 disk
├─sdb1 8:17 0 50G 0 part /boot/efi
├─sdb2 8:18 0 1G 0 part /boot
├─sdb3 8:19 0 4.2T 0 part
│ ├─lv-root 253:0 0 200G 0 lvm /
│ ├─lv-swap 253:1 0 20G 0 lvm [SWAP]
│ ├─lv-data 253:2 0 2.4T 0 lvm /data
│ ├─lv-audit 253:3 0 20G 0 lvm /var/audit
│ ├─lv-home 253:4 0 300G 0 lvm /home
│ ├─lv-var 253:5 0 1.2T 0 lvm /var
│ ├─lv-log 253:6 0 50G 0 lvm /var/log
│ └─lv-tmp 253:7 0 20G 0 lvm /tmp
└─sdb4 8:20 0 1007K 0 part
sr0 11:0 1 1024M 0 rom
[root@localhost ocp-data]#
[root@localhost ocp-data]# mkfs.xfs -f /dev/sda1 # 将需要挂载的分区格式化成xfs格式
warning: device is not properly aligned /dev/sda1
meta-data=/dev/sda1 isize=512 agcount=16, agsize=7325312 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=1 inobtcount=1
data = bsize=4096 blocks=117204686, imaxpct=25
= sunit=64 swidth=64 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=57280, version=2
= sectsz=512 sunit=64 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ocp-data]#
[root@localhost ocp-data]# blkid # 查看磁盘分区uuid及文件系统
/dev/mapper/lv-swap: UUID="cf3747e7-15c6-4d75-b2f4-44d885b9a273" TYPE="swap"
/dev/sdb2: UUID="3259e917-7aff-47cc-8c63-bec392a2ba3e" TYPE="xfs" PARTUUID="55a5068d-dad0-489e-b0de-c4b9c14211e0"
/dev/sdb3: UUID="08e3Cn-telD-fIcu-vy0X-Pjm1-SfUq-xaRe8n" TYPE="LVM2_member" PARTUUID="a63e6de6-f993-45ce-aaa6-ef5d2497ee39"
/dev/sdb1: UUID="A7EA-C3B0" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="33e41fd0-4ef9-4409-b92f-6d0f509e6da2"
/dev/mapper/lv-log: UUID="c577f16f-496d-4533-bbee-ed3d1e8b42d9" TYPE="xfs"
/dev/mapper/lv-home: UUID="84c270d6-d88d-4fcf-9c44-b1832f8f43b9" TYPE="xfs"
/dev/mapper/lv-data: UUID="369fdebc-6bc1-4f41-b57e-cf358b6a33da" TYPE="xfs"
/dev/mapper/lv-root: UUID="f0be0598-9eb1-4590-af92-e98675adb32f" TYPE="xfs"
/dev/mapper/lv-tmp: UUID="19b78fd0-16e2-4d95-82c2-f99d8d8ab2af" TYPE="xfs"
/dev/mapper/lv-var: UUID="9a5d95a3-b1e9-4611-9e78-7a9946a77084" TYPE="xfs"
/dev/mapper/lv-audit: UUID="6a367c81-1920-4d72-91a8-c900ff15fed4" TYPE="xfs"
/dev/sdb4: PARTLABEL="primary" PARTUUID="99ebd92d-8f9b-4c6b-bdad-388e4d15099b"
/dev/sda1: UUID="6fbdb134-3b0b-4ce9-817a-58c7e0b65b0f" TYPE="xfs" PARTUUID="4a5b4eae-01" # 发现sda1已被格式化为xfs
[root@localhost ocp-data]# mount /dev/sda1 /ocp-data/ # 挂载磁盘分区到目录ocp-data下
[root@localhost ocp-data]# df -h # 查看挂载情况
Filesystem Size Used Avail Use% Mounted on
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 504G 0 504G 0% /dev/shm
tmpfs 202G 21M 202G 1% /run
/dev/mapper/lv-root 200G 5.2G 195G 3% /
/dev/sdb2 1018M 246M 772M 25% /boot
/dev/sdb1 50G 7.3M 50G 1% /boot/efi
/dev/mapper/lv-data 2.4T 18G 2.4T 1% /data
/dev/mapper/lv-home 300G 3.0G 297G 1% /home
/dev/mapper/lv-tmp 20G 177M 20G 1% /tmp
/dev/mapper/lv-var 1.2T 8.6G 1.2T 1% /var
/dev/mapper/lv-audit 20G 176M 20G 1% /var/audit
/dev/mapper/lv-log 50G 408M 50G 1% /var/log
tmpfs 101G 104K 101G 1% /run/user/1000
tmpfs 101G 36K 101G 1% /run/user/0
/dev/sda1 447G 3.2G 444G 1% /ocp-data # 发现已成功挂载
[root@localhost ocp-data]# umount /dev/sda1 # 取消挂载
[root@localhost ~]# vi /etc/fstab # 修改fstab实现自动挂载
#
# /etc/fstab
# Created by anaconda on Thu May 4 14:00:36 2023
#
# 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.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/lv-root / xfs defaults 0 0
UUID=3259e917-7aff-47cc-8c63-bec392a2ba3e /boot xfs defaults 0 0
UUID=A7EA-C3B0 /boot/efi vfat umask=0077,shortname=winnt 0 2
/dev/mapper/lv-data /data xfs defaults 0 0
/dev/mapper/lv-home /home xfs defaults 0 0
/dev/mapper/lv-tmp /tmp xfs defaults 0 0
/dev/mapper/lv-var /var xfs defaults 0 0
/dev/mapper/lv-audit /var/audit xfs defaults 0 0
/dev/mapper/lv-log /var/log xfs defaults 0 0
/dev/mapper/lv-swap none swap defaults 0 0
UUID=6fbdb134-3b0b-4ce9-817a-58c7e0b65b0f /ocp-data xfs defaults 0 0 # 使用uuid进行挂载,放置盘符漂移更改
[root@localhost ocp-data]# df -h # 查看目录挂载情况,还未成功挂载
Filesystem Size Used Avail Use% Mounted on
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 504G 0 504G 0% /dev/shm
tmpfs 202G 21M 202G 1% /run
/dev/mapper/lv-root 200G 5.2G 195G 3% /
/dev/sdb2 1018M 246M 772M 25% /boot
/dev/sdb1 50G 7.3M 50G 1% /boot/efi
/dev/mapper/lv-data 2.4T 18G 2.4T 1% /data
/dev/mapper/lv-home 300G 3.0G 297G 1% /home
/dev/mapper/lv-tmp 20G 177M 20G 1% /tmp
/dev/mapper/lv-var 1.2T 8.6G 1.2T 1% /var
/dev/mapper/lv-audit 20G 176M 20G 1% /var/audit
/dev/mapper/lv-log 50G 408M 50G 1% /var/log
tmpfs 101G 104K 101G 1% /run/user/1000
tmpfs 101G 36K 101G 1% /run/user/0
[root@localhost ocp-data]# mount -a # 更新自动挂载
[root@localhost ocp-data]# df -h # 查看目录挂载
Filesystem Size Used Avail Use% Mounted on
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 504G 0 504G 0% /dev/shm
tmpfs 202G 21M 202G 1% /run
/dev/mapper/lv-root 200G 5.2G 195G 3% /
/dev/sdb2 1018M 246M 772M 25% /boot
/dev/sdb1 50G 7.3M 50G 1% /boot/efi
/dev/mapper/lv-data 2.4T 18G 2.4T 1% /data
/dev/mapper/lv-home 300G 3.0G 297G 1% /home
/dev/mapper/lv-tmp 20G 177M 20G 1% /tmp
/dev/mapper/lv-var 1.2T 8.6G 1.2T 1% /var
/dev/mapper/lv-audit 20G 176M 20G 1% /var/audit
/dev/mapper/lv-log 50G 408M 50G 1% /var/log
tmpfs 101G 104K 101G 1% /run/user/1000
tmpfs 101G 36K 101G 1% /run/user/0
/dev/sda1 447G 3.2G 444G 1% /ocp-data # 发现成功挂载
[root@localhost ocp-data]# reboot # 重启系统
[root@localhost ocp-data]# lsblk # 重启系统后也可成功挂载
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 447.1G 0 disk
└─sda1 8:1 0 447.1G 0 part
sdb 8:16 0 4.4T 0 disk
├─sdb1 8:17 0 50G 0 part /boot/efi
├─sdb2 8:18 0 1G 0 part /boot
├─sdb3 8:19 0 4.2T 0 part
│ ├─lv-root 253:0 0 200G 0 lvm /
│ ├─lv-swap 253:1 0 20G 0 lvm [SWAP]
│ ├─lv-data 253:2 0 2.4T 0 lvm /data
│ ├─lv-audit 253:3 0 20G 0 lvm /var/audit
│ ├─lv-home 253:4 0 300G 0 lvm /home
│ ├─lv-var 253:5 0 1.2T 0 lvm /var
│ ├─lv-log 253:6 0 50G 0 lvm /var/log
│ └─lv-tmp 253:7 0 20G 0 lvm /tmp
└─sdb4 8:20 0 1007K 0 part
sr0 11:0 1 1024M 0 rom
[root@localhost ocp-data]#
标签:LV,01,type,dev,lv,rw,挂载,磁盘分区,data
From: https://www.cnblogs.com/qian-hao/p/17375309.html