避免一头雾水,请先看完说明,再看最下面的挂载教程
START–>查看要挂载的是哪块硬盘–>将硬盘分区–>格式化分区–>设置开机自启(即永久挂载)–>执行挂载命令–>END
$ df -h
查看某个文件夹/文件大小可以用这个命令du -sh /usr
$ fdisk -l
当前系统一共存在三块磁盘:sda,sdb,sdc;其中sda已经有两个分区sda1和sda2。也可以使用lsblk
命令查看具体的磁盘分区情况
我们以挂载未分区的vdb到/data目录为例子
$ fdisk -l
Disk /dev/vdb: 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
$ fdisk /dev/vdb
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): m
Help:
DOS (MBR)
a toggle a bootable flag
b edit nested BSD disklabel
c toggle the dos compatibility flag
Generic
d delete a partition
F list free unpartitioned space
l list known partition types
n add a new partition
p print the partition table
t change a partition type
v verify the partition table
i print information about a partition
Misc
m print this menu
u change display/entry units
x extra functionality (experts only)
Script
I load disk layout from sfdisk script file
O dump disk layout to sfdisk script file
Save & Exit
w write table to disk and exit
q quit without saving changes
Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty DOS partition table
s create a new empty Sun partition table
Command (m for help): g
Created a new GPT disklabel (GUID: 3B765FDC-74EB-E34E-ADF3-34A6F616C8B6).
The old dos signature will be removed by a write command.
Command (m for help): p
Disk /dev/sda: 500 GiB, 536870912000 bytes, 1048576000 sectors
Disk model: QEMU HARDDISK
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: gpt
Disk identifier: 046CA995-F20A-184D-BA13-D7C144240C87
Command (m for help): n
Partition number (1-128, default 1): 1
First sector (2048-1048575966, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-1048575966, default 1048575966):
Created a new partition 1 of type 'Linux filesystem' and of size 500 GiB.
Partition #1 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: yes
The signature will be removed by a write command.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
$ fdisk -l
Disk /dev/vdb: 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
Disklabel type: gpt
Disk identifier: 1A0C9D01-9A82-402F-B078-73CA4431DFB9
# Start End Sectors Size Type
1 2048 419430366 419428319 200G Linux filesystem
$ mkfs.ext4 /dev/vdb1
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 52428539 4k blocks and 13107200 inodes
Filesystem UUID: a7cf4158-cc23-49bf-81eb-d19882299d67
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
$ ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 Dec 14 14:10 5bb40f03-8000-4453-9218-a3cd77897ca0 -> ../../vda1
lrwxrwxrwx 1 root root 10 Dec 14 14:43 a7cf4158-cc23-49bf-81eb-d19882299d67 -> ../../vdb1
$ vi /etc/fstab
UUID=a7cf4158-cc23-49bf-81eb-d19882299d67 /data ext4 defaults 0 0
上面是将vdb1挂载到/data目录,如果无此目录,请新建此目录
$ mount -a
$ df -h
今天服务器磁盘缩减,卸载磁盘,挂载新磁盘。mount -a不报错,却没有成功挂载上
journalctl -S "2023-03-28 15:00:00"
原来是systemd还记录着vdb1挂载到/data,需要重载一些配置
# 重载配置
systemctl daemon-reload
# 挂载
mount -a
# 查看是否挂载好了
df -h