磁盘挂载操作手册V1.3

it2024-11-12  5

Linux 磁盘挂载操作手册 V1.3


一. 查看磁盘状态

使用lsblk命令,发现存在空磁盘vdb

[root@tyzyk-gl-001 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 1024M 0 rom vda 252:0 0 40G 0 disk ├─vda1 252:1 0 1G 0 part /boot └─vda2 252:2 0 39G 0 part ├─centos-root 253:0 0 35.1G 0 lvm / └─centos-swap 253:1 0 3.9G 0 lvm [SWAP] vdb 252:16 0 1000G 0 disk

使用df命令,发现磁盘无挂载

[root@tyzyk-gl-001 /]# df -HT Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 8.3G 0 8.3G 0% /dev tmpfs tmpfs 8.4G 0 8.4G 0% /dev/shm tmpfs tmpfs 8.4G 816M 7.6G 10% /run tmpfs tmpfs 8.4G 0 8.4G 0% /sys/fs/cgroup /dev/mapper/centos-root xfs 38G 15G 24G 38% / /dev/vda1 xfs 1.1G 247M 817M 24% /boot tmpfs tmpfs 1.7G 54k 1.7G 1% /run/user/0

确认空磁盘后,进行分区操作


二. 使用fdisk命令创建分区

使用fdisk命令进行分区,选择需要创建分区的磁盘/dev/vdb

fdisk /dev/vdb

依次输入

n

选择新建分区

p

选择新建主分区

回车

选择默认分区序号

回车

选择默认起始扇区

回车

选择默认大小(可设置分区大小,eg: +100G)

w

确认无误,写入分区表

[root@tyzyk-gl-001 /]# 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. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0xc479a7c4. 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-2097151999, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-2097151999, default 2097151999): Using default value 2097151999 Partition 1 of type Linux and of size 1000 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.

以上操作无误,分区创建完成

使用lsblk和fdisk -l命令确认分区完成

[root@tyzyk-gl-001 /]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 1024M 0 rom vda 252:0 0 40G 0 disk ├─vda1 252:1 0 1G 0 part /boot └─vda2 252:2 0 39G 0 part ├─centos-root 253:0 0 35.1G 0 lvm / └─centos-swap 253:1 0 3.9G 0 lvm [SWAP] vdb 252:16 0 1000G 0 disk └─vdb1 252:17 0 1000G 0 part [root@tyzyk-gl-001 /]# fdisk -l Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x000a31d1 Device Boot Start End Blocks Id System /dev/vda1 * 2048 2099199 1048576 83 Linux /dev/vda2 2099200 83886079 40893440 8e Linux LVM Disk /dev/vdb: 1073.7 GB, 1073741824000 bytes, 2097152000 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: 0xc479a7c4 Device Boot Start End Blocks Id System /dev/vdb1 2048 2097151999 1048574976 83 Linux Disk /dev/mapper/centos-root: 37.7 GB, 37706792960 bytes, 73646080 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/centos-swap: 4160 MB, 4160749568 bytes, 8126464 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

三. 创建LVM逻辑卷

使用pvcreate命令创建物理卷

基本PV命令:

pvcreate 将物理分区新建为pv pvs/pvscan 查看系统里有pv的磁盘 pvdisplay 显示系统上面的pv状态 pvremove 删除pv

使用pvcreate新建pv

[root@tyzyk-gl-001 /]# pvcreate /dev/vdb1 Physical volume "/dev/vdb1" successfully created.

使用pvs查看新建的pv为/dev/vdb1

[root@tyzyk-gl-001 /]# pvs PV VG Fmt Attr PSize PFree /dev/vda2 centos lvm2 a-- <39.00g 4.00m /dev/vdb1 lvm2 --- <1000.00g <1000.00g 使用vgcreate命令创建卷组

有关vg的命令:

vgcreate [-s xM] vgName /dev/sd ……  新建vg,-s后面接pe的大小(可选),单位是M,G,可以放多块pv vgextend 扩展vg,就是增加pv vgs/vgscan 查看系统里有vg的磁盘 vgdisplay 显示系统上面的vg状态 vgremove 删除vg vgreduce 在vg里删除pv

使用vgcreate新建vg命名为database,并使用vgs查看状态

[root@tyzyk-gl-001 /]# vgcreate -s 4M database /dev/vdb1 Volume group "database" successfully created [root@tyzyk-gl-001 /]# vgs VG #PV #LV #SN Attr VSize VFree centos 1 2 0 wz--n- <39.00g 4.00m database 1 0 0 wz--n- <1000.00g <1000.00g 使用lvcreate命令创建逻辑卷

有关lv的命令:

lvcreate -l pe num /-L size -n lvname vgName  新建lv,-l指定pe的个数,-L指定容量,M,G lvextend 增加容量 lvs/lvscan 查看系统里有lv的磁盘 lvdisplay 显示系统上面的lv状态 lvremove 删除lv lvreduce 在lv里减少容量

使用vgdisplay查看vg状态和pe个数

[root@tyzyk-gl-001 /]# vgdisplay --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size <39.00 GiB PE Size 4.00 MiB Total PE 9983 Alloc PE / Size 9982 / 38.99 GiB Free PE / Size 1 / 4.00 MiB VG UUID Edprf7-OFtl-0nUD-esNi-Opox-7RUO-bHikhl --- Volume group --- VG Name database System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size <1000.00 GiB PE Size 4.00 MiB Total PE 255999 Alloc PE / Size 0 / 0 Free PE / Size 255999 / <1000.00 GiB VG UUID I3w1Af-p7OF-OEIf-g6zX-c3XK-pjc5-C9IzZn

使用lvcreate新建lv命名为database1,并使用lvs查看状态

[root@tyzyk-gl-001 /]# lvcreate -l 255999 -n database1 database Logical volume "database1" created. [root@tyzyk-gl-001 /]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- <35.12g swap centos -wi-ao---- <3.88g database1 database -wi-a----- <1000.00g

使用lvdisplay和lsblk查看lv状态,并确认LVM创建完成

[root@tyzyk-gl-001 /]# lvdisplay --- Logical volume --- LV Path /dev/database/database1 LV Name database1 VG Name database LV UUID B6DDG9-tKMo-C5uv-s7nm-8ygE-JvXS-GHGv4S LV Write Access read/write LV Creation host, time tyzyk-gl-001, 2020-10-21 11:22:56 +0800 LV Status available # open 0 LV Size <1000.00 GiB Current LE 255999 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:2 [root@tyzyk-gl-001 /]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 1024M 0 rom vda 252:0 0 40G 0 disk ├─vda1 252:1 0 1G 0 part /boot └─vda2 252:2 0 39G 0 part ├─centos-root 253:0 0 35.1G 0 lvm / └─centos-swap 253:1 0 3.9G 0 lvm [SWAP] vdb 252:16 0 1000G 0 disk └─vdb1 252:17 0 1000G 0 part └─database-database1 253:2 0 1000G 0 lvm

四. 创建文件系统并挂载使用

创建文件系统

使用lmkfs命令对逻辑卷创建文件系统

[root@tyzyk-gl-001 /]# mkfs.xfs /dev/database/database1 meta-data=/dev/database/database1 isize=512 agcount=4, agsize=65535744 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=262142976, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=127999, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 创建文件系统挂载点

使用mkdir命令创建挂载点为/data

[root@tyzyk-gl-001 /]# mkdir /data [root@tyzyk-gl-001 /]# ll total 32 lrwxrwxrwx. 1 root root 7 Mar 30 2020 bin -> usr/bin dr-xr-xr-x. 5 root root 4096 Apr 8 2020 boot drwxr-xr-x. 2 root root 6 Oct 21 11:32 data drwxr-xr-x. 22 root root 3340 Oct 21 11:22 dev drwxr-xr-x. 149 root root 12288 Jul 16 10:16 etc drwxr-xr-x. 3 root root 18 Apr 11 2018 home lrwxrwxrwx. 1 root root 7 Mar 30 2020 lib -> usr/lib lrwxrwxrwx. 1 root root 9 Mar 30 2020 lib64 -> usr/lib64 drwxr-xr-x. 2 root root 6 Apr 11 2018 media drwxr-xr-x. 2 root root 6 Apr 11 2018 mnt drwxr-xr-x. 3 root root 16 Apr 11 2018 opt dr-xr-xr-x. 260 root root 0 Mar 30 2020 proc dr-xr-x---. 24 root root 4096 Oct 21 08:49 root drwxr-xr-x. 40 root root 1220 Oct 21 06:31 run lrwxrwxrwx. 1 root root 8 Mar 30 2020 sbin -> usr/sbin drwxr-xr-x. 2 root root 6 Apr 11 2018 srv dr-xr-xr-x. 13 root root 0 Mar 30 2020 sys drwxrwxrwt. 14 root root 4096 Oct 21 11:32 tmp drwxr-xr-x. 13 root root 155 Mar 30 2020 usr drwxr-xr-x. 21 root root 4096 Apr 8 2020 var 挂载文件系统

使用lkbid命令查看文件系统UUID

[root@tyzyk-gl-001 /]# blkid /dev/mapper/centos-root: UUID="19501b5d-f7c1-4af7-ae4a-7e8deb3d758e" TYPE="xfs" /dev/vda2: UUID="3c6NzV-03W6-2Dzy-smlA-mQyl-P2HO-pzLpiQ" TYPE="LVM2_member" /dev/vda1: UUID="24d3c2c5-cf78-4747-ba52-1515575b6142" TYPE="xfs" /dev/mapper/centos-swap: UUID="b0230c7a-dc70-4ce2-bbcb-a2ece5b13596" TYPE="swap" /dev/vdb1: UUID="1VdYci-j9CT-H1Tx-CI8R-P138-dCZZ-djDatV" TYPE="LVM2_member" /dev/mapper/database-database1: UUID="0e8b8e85-a296-407c-b740-789368325523" TYPE="xfs"

将挂载信息写入fstab文件

[root@tyzyk-gl-001 ~]# vim /etc/fstab ------------------------------------------------------------------------------- # /etc/fstab # Created by anaconda on Sat Aug 31 16:55:24 2019 # # 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 # /dev/mapper/centos-root / xfs defaults 0 0 UUID=24d3c2c5-cf78-4747-ba52-1515575b6142 /boot xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0 UUID=0e8b8e85-a296-407c-b740-789368325523 /data xfs defaults 0 0 ------------------------------------------------------------------------------- :wq #保存并退出 ------------------------------------------------------------------------------- [root@tyzyk-gl-001 ~]#

使用mount -a命令重读fstab自动挂载,并使用df命令查看效果

[root@tyzyk-gl-001 ~]# mount -a [root@tyzyk-gl-001 ~]# df -HT Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 8.3G 0 8.3G 0% /dev tmpfs tmpfs 8.4G 0 8.4G 0% /dev/shm tmpfs tmpfs 8.4G 816M 7.6G 10% /run tmpfs tmpfs 8.4G 0 8.4G 0% /sys/fs/cgroup /dev/mapper/centos-root xfs 38G 15G 24G 38% / /dev/vda1 xfs 1.1G 247M 817M 24% /boot tmpfs tmpfs 1.7G 54k 1.7G 1% /run/user/0 /dev/mapper/database-database1 xfs 1.1T 34M 1.1T 1% /data [root@tyzyk-gl-001 ~]#

挂载完成,操作结束

最新回复(0)