Linux 磁盘挂载

磁盘挂载

查看现有磁盘大小

df  -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/rhel-root 48G 5.7G 43G 12% /

devtmpfs 7.8G 0 7.8G 0% /dev

tmpfs 7.8G 0 7.8G 0% /dev/shm

tmpfs 7.8G 457M 7.4G 6% /run

tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup

/dev/vda1 1014M 163M 852M 17% /boot

/dev/mapper/rhel-home 24G 3.7G 20G 16% /home

tmpfs 1.6G 0 1.6G 0% /run/user/0

tmpfs 1.6G 0 1.6G 0% /run/user/1000

查找未挂载的磁盘信息

fdisk -l

Disk /dev/vda: 85.9 GB, 85899345920 bytes, 167772160 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: 0x000c4a3e

Device Boot Start End Blocks Id System

/dev/vda1 * 2048 2099199 1048576 83 Linux

/dev/vda2 2099200 167772159 82836480 8e Linux LVM

Disk /dev/vdb: 322.1 GB, 322122547200 bytes, 629145600 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/rhel-root: 51.3 GB, 51308920832 bytes, 100212736 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/rhel-swap: 8455 MB, 8455716864 bytes, 16515072 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/rhel-home: 25.1 GB, 25052577792 bytes, 48930816 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

查看磁盘的格式

dh -T

Filesystem Type 1K-blocks Used Available Use% Mounted on

/dev/mapper/rhel-root xfs 50081904 6030584 44051320 13% /

devtmpfs devtmpfs 8120984 0 8120984 0% /dev

tmpfs tmpfs 8133020 0 8133020 0% /dev/shm

tmpfs tmpfs 8133020 467772 7665248 6% /run

tmpfs tmpfs 8133020 0 8133020 0% /sys/fs/cgroup

/dev/vda1 xfs 1038336 166248 872088 17% /boot

/dev/mapper/rhel-home xfs 24453464 3940144 20513320 17% /home

tmpfs tmpfs 1626604 0 1626604 0% /run/user/0

tmpfs tmpfs 1626604 0 1626604 0% /run/user/1000

tmpfs tmpfs 1626604 0 1626604 0% /run/user/1001

格式化未挂载的磁盘并制定格式

mkfs -t xfs /dev/vdb   #此次使用的是而xfs格式 

meta-data=/dev/vdb isize=512 agcount=4, agsize=19660800 blks

​ = sectsz=512 attr=2, projid32bit=1

​ = crc=1 finobt=0, sparse=0

data = bsize=4096 blocks=78643200, imaxpct=25

​ = sunit=0 swidth=0 blks

naming =version 2 bsize=4096 ascii-ci=0 ftype=1

log =internal log bsize=4096 blocks=38400, version=2

​ = sectsz=512 sunit=0 blks, lazy-count=1

realtime =none extsz=4096 blocks=0, rtextents=0

将磁盘挂载到创建的目录上

mkdir /home/test  #创建test文件做为磁盘挂载点
mount /dev/xvdb /home/test  

/dev/xvdb:磁盘目录

/home/test:挂载点

实现自动挂载

通过磁盘路径实现自动挂载

vi /etc/fstab

/dev/mapper/centos-root / xfs defaults 0 0
UUID=d622a455-5eef-4e4c-94b6-563feee85995 /boot xfs defaults 0 0
/dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0

通过磁盘路径实现挂载

/dev/xvdb /home/text xfs defaults 0 0

通过uuid实现自动挂载

查看磁盘UUID
blkid /dev/sda3

dev/sda3: UUID="e7adfeb9-8749-48cd-90cd-61de56c9af74" TYPE="xfs"

vi /etc/fstab

/dev/mapper/centos-root / xfs defaults 0 0
UUID=d622a455-5eef-4e4c-94b6-563feee85995 /boot xfs defaults 0 0
/dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0

通过磁盘路径实现挂载

/dev/xvdb /home/text xfs defaults 0 0

通过uuid挂载

UUID=e7adfeb9-8749-48cd-90cd-61de56c9af74 /home/test xfs defaults 0 0

退出文件后测试

卸载磁盘

umount  /dev/sda3

重新加载

mount -a #执行后正常情况下 磁盘会自动挂载上去。

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/rhel-root 48G 5.9G 42G 13% /

devtmpfs 7.8G 0 7.8G 0% /dev

tmpfs 7.8G 0 7.8G 0% /dev/shm

tmpfs 7.8G 457M 7.4G 6% /run

tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup

/dev/vda1 1014M 163M 852M 17% /boot

/dev/mapper/rhel-home 24G 3.8G 20G 17% /home

tmpfs 1.6G 0 1.6G 0% /run/user/0

tmpfs 1.6G 0 1.6G 0% /run/user/1000

tmpfs 1.6G 0 1.6G 0% /run/user/1001

/dev/vdb 300G 33M 300G 1% /home/jyhpt

posted @ 2021-06-10 17:44  十一YS  阅读(177)  评论(0编辑  收藏  举报