linux lvm方式挂载硬盘和查看磁盘信息常用命令

  1. 查看服务器磁盘的挂载情况

fdisk -l

[root@yuanlnet ~]# fdisk -l
Disk /dev/vda: 100 GiB, 107374182400 bytes, 209715200 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
Disklabel type: dos
Disk identifier: 0x8736ef18

Device     Boot   Start       End   Sectors  Size Id Type
/dev/vda1  *       2048   1026047   1024000  500M 83 Linux
/dev/vda2       1026048 209715166 208689119 99.5G 83 Linux


Disk /dev/vdb: 64 MiB, 67108864 bytes, 131072 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
Disklabel type: dos
Disk identifier: 0x00000000


Disk /dev/vdc: 200 GiB, 214748364800 bytes, 419430400 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
[root@yuanlnet ~]# 

  1. 分区操作

1、pv
pvcreate /dev/vdc
[root@yuanlnet ~]# pvcreate /dev/vdc
  Physical volume "/dev/vdc" successfully created.
2、vg
vgcreate vg_data /dev/vdc
[root@yuanlnet ~]# vgcreate vg_data /dev/vdc
  Volume group "vg_data" successfully created
3、lv
lvcreate -l 100%VG -n lv_data vg_data
[root@yuanlnet ~]# lvcreate -l 100%VG -n lv_data vg_data
  Logical volume "lv_data" created.
4、mkfs(格式化)
mkfs.xfs /dev/vg_data/lv_data
[root@yuanlnet ~]# mkfs.xfs /dev/vg_data/lv_data
meta-data=/dev/vg_data/lv_data   isize=512    agcount=4, agsize=13106944 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1    bigtime=0 inobtcount=0
data     =                       bsize=4096   blocks=52427776, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=25599, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@yuanlnet ~]# 

  1. 创建目录

mkdir /data
[root@yuanlnet ~]# mkdir /data

  1. 磁盘开机自动挂载

cat /etc/fstab
[root@yuanlnet ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Wed Jul 13 07:59:36 2022
#
# 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.
#
UUID=75274ed7-7d2b-410c-b121-9f8cd51fd16c /                       ext4    defaults        1 1
UUID=8ef34cc7-30a0-46ac-8523-c0c8a8e19545 /boot                   ext4    defaults        1 2

vim /etc/fstab
添加 
/dev/mapper/vg_data-lv_data /data xfs defaults  0 0

# 
# /etc/fstab
# Created by anaconda on Wed Jul 13 07:59:36 2022
#
# 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.
#
UUID=75274ed7-7d2b-410c-b121-9f8cd51fd16c /ext4    defaults1 1
UUID=8ef34cc7-30a0-46ac-8523-c0c8a8e19545 /bootext4    defaults1 2
/dev/mapper/vg_data-lv_data /data xfs defaults  0 0

  1. mount

mount -a
[root@yuanlnet ~]# mount -a

  1. 删除逻辑区

umount lv_data

rm /dev/mapper/vg_data-lv_data


  1. reboot


  1. 验证

[root@yuanlnet ~]# fdisk -l
Disk /dev/vda: 100 GiB, 107374182400 bytes, 209715200 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
Disklabel type: dos
Disk identifier: 0x8736ef18

Device     Boot   Start       End   Sectors  Size Id Type
/dev/vda1  *       2048   1026047   1024000  500M 83 Linux
/dev/vda2       1026048 209715166 208689119 99.5G 83 Linux


Disk /dev/vdb: 64 MiB, 67108864 bytes, 131072 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
Disklabel type: dos
Disk identifier: 0x00000000


Disk /dev/vdc: 200 GiB, 214748364800 bytes, 419430400 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/vg_data-lv_data: 200 GiB, 214744170496 bytes, 419422208 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
[root@yuanlnet ~]# df -Th
Filesystem                  Type      Size  Used Avail Use% Mounted on
devtmpfs                    devtmpfs   32G     0   32G   0% /dev
tmpfs                       tmpfs      32G     0   32G   0% /dev/shm
tmpfs                       tmpfs      32G  8.7M   32G   1% /run
tmpfs                       tmpfs      32G     0   32G   0% /sys/fs/cgroup
/dev/vda2                   ext4       98G  3.7G   91G   4% /
/dev/vda1                   ext4      477M  134M  314M  30% /boot
/dev/mapper/vg_data-lv_data xfs       200G  1.5G  199G   1% /data
tmpfs                       tmpfs     6.3G     0  6.3G   0% /run/user/0
[root@yuanlnet ~]# 

常用命令

lsblk 
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0   2.7T  0 disk
├─sda1   8:1    0   1.3M  0 part
├─sda2   8:2    0   400M  0 part /boot
├─sda3   8:3    0 390.6G  0 part /
├─sda4   8:4    0  97.7G  0 part /home
├─sda5   8:5    0   7.8G  0 part [SWAP]
└─sda6   8:6    0   2.2T  0 part /data012345678910

NAME : 这是块设备名。
MAJ:MIN : 本栏显示主要和次要设备号。
RM : 本栏显示设备是否可移动设备。注意,在本例中设备sdb和sr0的RM值等于1,这说明他们是可移动设备。
SIZE : 本栏列出设备的容量大小信息。例如298.1G表明该设备大小为298.1GB,而1K表明该设备大小为1KB。
RO : 该项表明设备是否为只读。在本案例中,所有设备的RO值为0,表明他们不是只读的。
TYPE :本栏显示块设备是否是磁盘或磁盘上的一个分区。在本例中,sda和sdb是磁盘,而sr0是只读存储(rom)。
MOUNTPOINT : 本栏指出设备挂载的挂载点

-------------------------------------------------------------------------------------------
-d ∶仅列出磁盘本身,并不会列出该磁盘的分区数据

-f ∶同时列出该磁盘内的文件系统名称

-i∶使用 ASCII的线段输出,不要使用复杂的编码(再某些环境下很有用)

-m ∶同时输出该装置在 /dev 底下的权限数据(rwx 的数据)

-p ∶列出该装置的完整文件名!而不是仅列出最后的名字而已。

-t ∶列出该磁盘装置的详细数据,包括磁盘队列机制、预读写的数据量大小
df
显示磁盘的使用情况
 
  -a, --all                 包括假的,重复的,无法访问的文件系统
  -B, --block-size=SIZE     用 SIZE 描述文件的大小;
                            比如:'-BM' 用 1,048,576 bytes 为单位描述文件大小;
                            SIZE 的格式在下边查看
      --direct              显示文件的信息而不是挂载点
      --total               在最后一行打印总和数据
  -h, --human-readable      显示可读的单位(例如:1K 234M 2G)
  -H, --si                  类似, 但是使用 1000 的次方而不是 1024
  -i, --inodes                显示inode 信息而非块使用量
  -k                        即--block-size=1K
  -l, --local                只显示本机的文件系统
      --no-sync                取得使用量数据前不进行同步动作(默认)
      --output[=FIELD_LIST] 使用 FIELD_LIST 定义的输出格式
                            如果未定义 FIELD_LIST,打印所有的数据
  -P, --portability         使用 POSIX 输出格式
      --sync                在得到有用的信息之前触发同步
  -t, --type=TYPE           只列出类型为 TYPE 的文件系统
  -T, --print-type          打印文件系统类型
  -x, --exclude-type=TYPE   只列出类型不为 TYPE 的文件系统
  -v                        (被忽略)
      --help                显示此帮助信息并退出
      --version                显示版本信息并退出

df -h # 查看整个磁盘的空间使用情况
du -sh /home/user/mydata/* # 查询某个路径下所有数据大小
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值