1. 程式人生 > 其它 >Linux 磁碟掛載

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