0x01 概述

在Linux下如何加载一个分区,需要几个过程。

0x02 操作过程

查看分区

|[root@lua.ren~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 2.2G 36G 6% /
devtmpfs 63G 0 63G 0% /dev
tmpfs 63G 0 63G 0% /dev/shm
tmpfs 63G 17M 63G 1% /run
tmpfs 63G 0 63G 0% /sys/fs/cgroup
tmpfs 13G 0 13G 0% /run/user/60422|

查看所有磁盘

|[root@lua.ren ~]# 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: 0x000a2636

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 83886046 41941999+ 83 Linux

Disk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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@lua.ren ~]# mkfs.ext4 /dev/vdb
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
32768000 inodes, 131071744 blocks
6553587 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2279604224
4000 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done|

写/etc/fstab, 服务器重启可以自动挂载

  • 创建挂载目录

|[root@lua.ren ~]# mkdir /data

  • 查询分区UUID

|[root@lua.ren ~]# blkid
/dev/sr0: UUID=“2020-06-23-11-46-23-00” LABEL=“cidata” TYPE=“iso9660”
/dev/vda1: UUID=“a5ed5a70-ec40-4fcf-b436-9dab87463f08” TYPE=“ext4”
/dev/vdb: UUID=“e3cce3c2-3d28-4397-b94e-b744e5ce6b93” TYPE=“ext4”|

  • 分区UUID(数据以实际的查询结果为准)

    UUID=”e3cce3c2-3d28-4397-b94e-b744e5ce6b93”

  • 写fstab

[root@lua.ren ~]# vim /etc/fstab

UUID=a5ed5a70-ec40-4fcf-b436-9dab87463f08 / ext4 defaults 1 1
UUID=e3cce3c2-3d28-4397-b94e-b744e5ce6b93 /data ext4 defaults 1 1

  • 挂载目录

[root@lua.ren ~]# mount -a
[root@lua.ren ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 2.2G 36G 6% /
devtmpfs 63G 0 63G 0% /dev
tmpfs 63G 0 63G 0% /dev/shm
tmpfs 63G 17M 63G 1% /run
tmpfs 63G 0 63G 0% /sys/fs/cgroup
tmpfs 13G 0 13G 0% /run/user/60422
/dev/vdb 493G 73M 467G 1% /data

0x03 总结

/etc/fstab的配置CenOS与Ubuntu的配置有一些差异,需要特别注意。

  • Ubuntu的//etc/fstab文件

/dev/disk/by-uuid/fa3d8567-f154-4802-baae-af75e1d85c18 / ext4 defaults 0 0
/swap.img none swap sw 0 0
/dev/disk/by-uuid/dde4e123-7c68-42eb-9dab-0c9e94c352bb /data0 ext4 defaults 0 0