【linux系列】(202212) 磁盘管理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
查看磁盘使用率
df -h
查看单个目录的挂载情况(目录属于哪个分区)
df -h /home

fdisk -l
lsblk
# 查看文件系统类型
lsblk -f

lvremove
vgremove
pvremove

# fdisk /dev/sdb
:d # 删除
:w # 保存
dos分区表 一个分区最大2T
gpt分区表 不限制

查看是不是ssd
# 使用lsblk命令进行判断,参数-d表示仅显示设备本身(不显示其上分区),参数-o表示仅显示特定的列。
# # 0是ssd 1是hdd
# lsblk -d -o name,rota
# grep ^ /sys/block/*/queue/rotational
1
2
3
4
5
6
7
8
[root@localhost ~]# lvremove /dev/mapper/vgqjc-lvqjc 
Do you really want to remove active logical volume vgqjc/lvqjc? [y/n]: y
Logical volume "lvqjc" successfully removed
[root@localhost ~]# vgremove /dev/mapper/vgqjc
Volume group "vgqjc" successfully removed
[root@localhost ~]# pvremove /dev/sdl
Labels on physical volume "/dev/sdl" successfully wiped.
[root@localhost ~]#
1
2
3
4
5
6
7
8
9
10
11
[root@zqzt-wx13f33-zbhx08w ~]# lsblk -d -o name,rota
NAME ROTA
sda 1
sdb 1
[root@zqzt-wx13f33-zbhx08w ~]#
[root@zqzt-wx13f33-zbhx08w ~]# grep ^ /sys/block/*/queue/rotational
/sys/block/dm-0/queue/rotational:1
/sys/block/dm-1/queue/rotational:1
/sys/block/sda/queue/rotational:1
/sys/block/sdb/queue/rotational:1

fdisk命令中device通常是/dev/hda/dev/hdb….(IDE接口类型的硬盘设备名)或/dev/sda/dev/sdb….(SCSI接口类型硬盘设备名),表示整个硬盘,如果硬盘被分区,则在设备名后追加一个数字表示此设备的第几个分区。如上例中的/dev/sda1/dev/sda2

疑问:
1.IDE接口类型的硬盘和SCSI接口类型硬盘有什么区别?
2./etc/mtab和/etc/fstab的区别?

1
2
3
4
5
6
7
8
lvdisplay
pvdisplay
vgdisplay

可以使用pvdisplay 或者pvscan查看创建的物理卷
使用vgdisplay 或者vgscan 查看卷组
使用lvscan 或者lvdisplay查看[逻辑卷](https://so.csdn.net/so/search?q=%E9%80%BB%E8%BE%91%E5%8D%B7&spm=1001.2101.3001.7020)
使用df -h查看是否创建成功

需求1:扩容某一个文件系统目录

当前情况

当前磁盘情况

image.png

查看你文件系统类型

1
lsblk -f

image.png

当前pv,vg,lv情况:
当前sdb下有sdb1分区
基于/dev/sdb1创建了pv

1
pvcreate  /dev/sdb1 --force

基于pv创建了vg(datavg为vg的名字)

1
vgcreate  datavg /dev/sdb1

基于datavg创建了lv(lv_data_xxx_data为lv的名字)

1
2
sudo lvcreate  -L 4T -n lv_data_xxx_data datavg
sudo mkfs.xfs  -f /dev/mapper/datavg-lv_data_xxx_data

挂载

1
sudo mount  /dev/mapper/datavg-lv_data_xxx_data /vdata/xxx/data

需求

想把sdc到sdm这些磁盘全部挂载到/vdata/tg-paas/data下,该如何实现?

实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
sudo parted  -s /dev/sdc mklabel gpt
sudo parted  -s /dev/sdc mkpart primary xfs 0 100%
sudo mkfs.xfs  -f /dev/sdc1

sudo pvcreate  /dev/sdc1 --force

sudo vgextend datavg /dev/sdc1

lvresize -L +9.1T /dev/mapper/datavg-lv_data_xxx_data

# 使用xfs_groupfs进行在线调整xfs格式的文件系统大小
# lsblk -f 查看文件系统类型
xfs_growfs /dev/mapper/datavg-lv_data_xxx_data

# 查看已经扩容成功
lsblk
df -h

需求2:给某个目录/var/www/html挂盘

挂载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
lsblk
df -h | head -n 20

mkdir -p /var/www/html


lvdisplay | sudo grep lv_pkg
sudo lvcreate -L 200G -n lv_pkg datavg
sudo mkfs.xfs -f /dev/mapper/datavg-lv_pkg
sudo mount | sudo grep "/dev/mapper/datavg-lv_pkg on /var/www/html"
sudo mount /dev/mapper/datavg-lv_pkg /var/www/html
sudo cat /etc/fstab | sudo grep "/dev/mapper/datavg-lv_pkg"
sudo cat /etc/mtab | sudo grep datavg-lv_pkg >> /etc/fstab
sudo cat /etc/fstab | sudo grep "/dev/mapper/datavg-lv_pkg"
sudo cat /etc/fstab

sudo df -h |grep html
df -h | grep var

解挂

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# df -h | grep var
/dev/mapper/rootvg-lv_var 60G 49G 12G 81% /var
/dev/mapper/datavg-lv_log_tg_paas 500G 3.6G 497G 1% /var/log/tg-paas
/dev/mapper/datavg-lv_log_pods 500G 3.8G 497G 1% /var/log/pods
/dev/mapper/datavg-lv_pkg 1.0T 7.2G 1017G 1% /var/www/html
# cd ~
# umount /dev/mapper/datavg-lv_pkg
# df -h | grep var
/dev/mapper/rootvg-lv_var 60G 49G 12G 81% /var
/dev/mapper/datavg-lv_log_tg_paas 500G 3.6G 497G 1% /var/log/tg-paas
/dev/mapper/datavg-lv_log_pods 500G 3.8G 497G 1% /var/log/pods

# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 446.1G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 444.6G 0 part
├─rootvg-lv_root 252:0 0 20G 0 lvm /
├─rootvg-lv_swap 252:1 0 16G 0 lvm
├─rootvg-lv_var 252:3 0 60G 0 lvm /var
├─rootvg-lv_home 252:6 0 20G 0 lvm /home
└─rootvg-lv_kerneldata_etcd 252:8 0 50G 0 lvm /kerneldata/etcd
sdb 8:16 0 4.9T 0 disk
└─sdb1 8:17 0 4.9T 0 part
├─datavg-lv_data 252:2 0 500G 0 lvm /vdata
├─datavg-lv_data_net 252:4 0 100G 0 lvm /vdata/net
├─datavg-lv_log_pods 252:5 0 500G 0 lvm /var/log/pods
├─datavg-lv_log_tg_paas 252:7 0 500G 0 lvm /var/log/tg-paas
└─datavg-lv_pkg 252:9 0 1T 0 lvm


# lvresize -L 200G /dev/mapper/datavg-lv_pkg
WARNING: Reducing active logical volume to 200.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce datavg/lv_pkg? [y/n]: y
Size of logical volume datavg/lv_pkg changed from 1.00 TiB (262144 extents) to 200.00 GiB (51200 extents).
Logical volume datavg/lv_pkg successfully resized.


# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 446.1G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 444.6G 0 part
├─rootvg-lv_root 252:0 0 20G 0 lvm /
├─rootvg-lv_swap 252:1 0 16G 0 lvm
├─rootvg-lv_var 252:3 0 60G 0 lvm /var
├─rootvg-lv_home 252:6 0 20G 0 lvm /home
└─rootvg-lv_kerneldata_etcd 252:8 0 50G 0 lvm /kerneldata/etcd
sdb 8:16 0 4.9T 0 disk
└─sdb1 8:17 0 4.9T 0 part
├─datavg-lv_data 252:2 0 500G 0 lvm /vdata
├─datavg-lv_data_net 252:4 0 100G 0 lvm /vdata/net
├─datavg-lv_log_pods 252:5 0 500G 0 lvm /var/log/pods
├─datavg-lv_log_tg_paas 252:7 0 500G 0 lvm /var/log/tg-paas
└─datavg-lv_pkg 252:9 0 200G 0 lvm


sudo mkfs.xfs -f /dev/mapper/datavg-lv_pkg
sudo mount | sudo grep "/dev/mapper/datavg-lv_pkg on /var/www/html"
sudo mount /dev/mapper/datavg-lv_pkg /var/www/html
sudo cat /etc/fstab | sudo grep "/dev/mapper/datavg-lv_pkg"

删除对应行


sudo cat /etc/mtab | sudo grep datavg-lv_pkg >> /etc/fstab
sudo cat /etc/fstab | sudo grep "/dev/mapper/datavg-lv_pkg"
sudo cat /etc/fstab


需求3:sdb下面分了三个区,想要变成1个

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@tgypt-wxd43-zbhx243w ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 893.8G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 892.3G 0 part
├─rootvg-lv_root 252:0 0 20G 0 lvm /
├─rootvg-lv_swap 252:1 0 16G 0 lvm [SWAP]
├─rootvg-lv_var 252:2 0 60G 0 lvm /var
├─rootvg-lv_home 252:3 0 20G 0 lvm /home
└─rootvg-lv_kerneldata_etcd 252:4 0 50G 0 lvm /kerneldata/etcd
sdb 8:16 0 29.1T 0 disk
├─sdb1 8:17 0 512M 0 part
├─sdb2 8:18 0 1G 0 part
└─sdb3 8:19 0 7.3T 0 part
sdc 8:32 0 29.1T 0 disk
nvme1n1 259:0 0 1.5T 0 disk
nvme0n1 259:1 0 1.5T 0 disk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
[root@tgypt-wxd43-zbhx243w ~]# ls /dev/sdb1
/dev/sdb1
[root@tgypt-wxd43-zbhx243w ~]#
[root@tgypt-wxd43-zbhx243w ~]#
[root@tgypt-wxd43-zbhx243w ~]# echo $?
0
[root@tgypt-wxd43-zbhx243w ~]# sudo ls -l /dev/mapper/ | sudo grep datavg
[root@tgypt-wxd43-zbhx243w ~]#
[root@tgypt-wxd43-zbhx243w ~]#
[root@tgypt-wxd43-zbhx243w ~]# echo $?
1
[root@tgypt-wxd43-zbhx243w ~]# sudo parted -s /dev/sdb mklabel gpt
[root@tgypt-wxd43-zbhx243w ~]#
[root@tgypt-wxd43-zbhx243w ~]#
[root@tgypt-wxd43-zbhx243w ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 893.8G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 892.3G 0 part
├─rootvg-lv_root 252:0 0 20G 0 lvm /
├─rootvg-lv_swap 252:1 0 16G 0 lvm [SWAP]
├─rootvg-lv_var 252:2 0 60G 0 lvm /var
├─rootvg-lv_home 252:3 0 20G 0 lvm /home
└─rootvg-lv_kerneldata_etcd 252:4 0 50G 0 lvm /kerneldata/etcd
sdb 8:16 0 29.1T 0 disk
sdc 8:32 0 29.1T 0 disk
nvme1n1 259:0 0 1.5T 0 disk
nvme0n1 259:1 0 1.5T 0 disk
[root@tgypt-wxd43-zbhx243w ~]#
[root@tgypt-wxd43-zbhx243w ~]#
[root@tgypt-wxd43-zbhx243w ~]# echo $?
0
[root@tgypt-wxd43-zbhx243w ~]# sudo parted -s /dev/sdb mkpart primary xfs 0 100%
Warning: The resulting partition is not properly aligned for best performance: 34s % 2048s != 0s
[root@tgypt-wxd43-zbhx243w ~]#
[root@tgypt-wxd43-zbhx243w ~]# sudo mkfs.xfs -f /dev/sdb1
warning: device is not properly aligned /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=32, agsize=244171712 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=7813494784, imaxpct=5
= sunit=64 swidth=256 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=521728, version=2
= sectsz=512 sunit=64 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@tgypt-wxd43-zbhx243w ~]#
[root@tgypt-wxd43-zbhx243w ~]#
[root@tgypt-wxd43-zbhx243w ~]#
[root@tgypt-wxd43-zbhx243w ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 893.8G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 892.3G 0 part
├─rootvg-lv_root 252:0 0 20G 0 lvm /
├─rootvg-lv_swap 252:1 0 16G 0 lvm [SWAP]
├─rootvg-lv_var 252:2 0 60G 0 lvm /var
├─rootvg-lv_home 252:3 0 20G 0 lvm /home
└─rootvg-lv_kerneldata_etcd 252:4 0 50G 0 lvm /kerneldata/etcd
sdb 8:16 0 29.1T 0 disk
└─sdb1 8:17 0 29.1T 0 part
sdc 8:32 0 29.1T 0 disk
nvme1n1 259:0 0 1.5T 0 disk
nvme0n1 259:1 0 1.5T 0 disk
[root@tgypt-wxd43-zbhx243w ~]#

需求4:

image.png

datavg-lv_data 从500G改为100G

参考

Linux 物理卷(PV)、逻辑卷(LV)、卷组(VG)管理


【linux系列】(202212) 磁盘管理
http://example.com/2022/12/28/linux/【linux系列】(202212) 磁盘管理/
作者
ningan123
发布于
2022年12月28日
许可协议