查看磁盘空间情况,发现挂载的磁盘还在
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 16G 627M 16G 4% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/mapper/centos-root 46G 13G 33G 28% /
/dev/vda1 1014M 171M 844M 17% /boot
tmpfs 3.2G 0 3.2G 0% /run/user/0
/dev/mapper/VG_DATA-lv_data 100G 1M 99G 100% /data
但是卸载不掉,显示繁忙。
[root@localhost ~]# umount /data/
umount: /data: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
找到这个挂载目录的进程
查看挂载目录进程
[root@localhost ~]# lsof /data
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bash 36825 root cwd DIR 253,2 6 67 /data/3306
杀掉进程,再卸载
[root@localhost ~]# kill -9 36825
[root@localhost ~]# umount /data
在查看磁盘空间情况,发下已经卸载掉了
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 16G 627M 16G 4% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/mapper/centos-root 46G 37G 8.3G 82% /
/dev/vda1 1014M 171M 844M 17% /boot
tmpfs 3.2G 0 3.2G 0% /run/user/0
创建物理卷报错
[root@localhost ~]# pvcreate /dev/vdb
Can't open /dev/vdb1 exclusively. Mounted filesystem?
Can't open /dev/vdb1 exclusively. Mounted filesystem?
删除逻辑卷,发现报错
[root@localhost ~]# dmsetup remove VG_DATA-lv_data
device-mapper: remove ioctl on VG_DATA-lv_data failed: Device or resource busy
Command failed.
查看逻辑卷
[root@localhost ~]# ll /dev/mapper/
total 0
lrwxrwxrwx 1 root root 7 May 22 15:41 centos-root -> ../dm-0
lrwxrwxrwx 1 root root 7 May 22 09:54 centos-swap -> ../dm-1
crw------- 1 root root 10, 236 Dec 14 15:52 control
lrwxrwxrwx 1 root root 7 May 22 09:54 VG_DATA-lv_data -> ../dm-2
删除逻辑卷
[root@localhost ~]# dmsetup remove VG_DATA-lv_data
查看空闲磁盘
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
fd0 2:0 1 4K 0 disk
sr0 11:0 1 1024M 0 rom
vda 252:0 0 50G 0 disk
├─vda1 252:1 0 1G 0 part /boot
└─vda2 252:2 0 49G 0 part
├─centos-root 253:0 0 45.1G 0 lvm /
└─centos-swap 253:1 0 3.9G 0 lvm [SWAP]
vdb 252:16 0 800G 0 disk
---------------------------------------------------------------
做磁盘分区
[root@localhost ~]# fdisk /dev/vdb
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): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): ##默认
Using default response p
Partition number (1-4, default 1): ##默认
First sector (2048-1677721599, default 2048): ##默认
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1677721599, default 1677721599): +500G ##选择需要的空间
Partition 1 of type Linux and of size 500 GiB is set
Command (m for help): t ##将分区做lvm
Selected partition 1
Hex code (type L to list all codes): l ##查看分区的样式
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
Hex code (type L to list all codes): 8e ##选择lvm
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p ##查看分区详情
Disk /dev/vdb: 859.0 GB, 858993459200 bytes, 1677721600 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: 0xd4336d8f
Device Boot Start End Blocks Id System
/dev/vdb1 2048 1048578047 524288000 8e Linux LVM
Command (m for help): w ##保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
-------------------------------------------------------------------
将规划好的分区上报系统
[root@localhost ~]# partprobe
创建物理组
[root@localhost ~]# pvcreate /dev/vdb1
WARNING: xfs signature detected on /dev/vdb1 at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/vdb1.
Physical volume "/dev/vdb1" successfully created.
-------------------------------------------------------------
创建逻辑卷
[root@localhost ~]# vgcreate VG_DATA /dev/vdb1
Volume group "VG_DATA" successfully created
-------------------------------------------------------------
创建卷组
[root@localhost ~]# lvcreate -n lv_data -L 100G VG_DATA
Logical volume "lv_data" created.
------------------------------------------------------------
格式化逻辑卷
[root@localhost ~]# mkfs -t xfs /dev/mapper/VG_DATA-lv_data
meta-data=/dev/mapper/VG_DATA-lv_data isize=512 agcount=4, agsize=6553600 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=26214400, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=12800, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
--------------------------------------------------------------------
把逻辑卷加如开机启动挂载
[root@localhost ~]# vi /etc/fstab
创建挂载点,挂载逻辑卷到/data
[root@localhost ~]# mkdir -pv /data
[root@localhost ~]# mount -a
--------------------------------------------------------------------
查看是否挂载成功
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 16G 627M 16G 4% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/mapper/centos-root 46G 37G 8.2G 82% /
/dev/vda1 1014M 171M 844M 17% /boot
tmpfs 3.2G 0 3.2G 0% /run/user/0
/dev/mapper/VG_DATA-lv_data 100G 33M 100G 1% /data