查看新磁盘

sudo fdisk -l
VirtualBox 添加一块新硬盘
VirtualBox 添加一块新硬盘VirtualBox 添加一块新硬盘

磁盘分区

sudo fdisk /dev/sdb
n->p->1->enter->enter->w
n 添加一个分区
p 主分区
1 分区号
两个回车是开始和结束的磁盘大小
w 写入磁盘
VirtualBox 添加一块新硬盘

[[email protected] ~]$ sudo fdisk /dev/sdb
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 0x2473e16c.

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): 1
First sector (2048-10485759, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759):
Using default value 10485759
Partition 1 of type Linux and of size 5 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[[email protected] ~]$

格式化分区

[[email protected] vagrant]# mkfs -t ext4 /dev/sdb1
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
327680 inodes, 1310464 blocks
65523 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 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

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

[[email protected] vagrant]#

开机启动自动挂载

[[email protected] /]# mkdir /mnt_data
[[email protected] /]# mount /dev/sdb1 /mnt_data

[[email protected] ~]$ df -T
Filesystem     Type     1K-blocks      Used Available Use% Mounted on
/dev/sda1      ext4      41152736   3642892  35396360  10% /
/dev/sdb1      ext4       5028480     20472   4729532   1% /mnt_data

[[email protected] vagrant]# vim /etc/fstab
/dev/sdb1 /mnt_data ext4 defaults 0 0

/etc/fstab 详解

自动挂载文件,根目录是必须挂载的,而且一定要优先于其他挂载点挂载。
第一列,Device 磁盘设备文件或者该设备的Label或者UUID
查看分区的label和uuid
dumpe2fs -h /dev/sdb1

[[email protected] vagrant]# dumpe2fs -h /dev/sdb1
dumpe2fs 1.42.9 (28-Dec-2013)
Filesystem volume name:   <none>
Last mounted on:          /mnt_data
Filesystem UUID:          2363fb1d-d1f4-473f-b2d8-25f8362f7cfb

blkid

[[email protected] vagrant]# blkid
/dev/sdb1: UUID="2363fb1d-d1f4-473f-b2d8-25f8362f7cfb" TYPE="ext4"
/dev/sda1: UUID="b5b20816-947c-4616-b15a-abaae4afe31b" TYPE="ext4"

使用设备名称/dev/sdb1 来挂载分区时是被固定死的,当磁盘插槽顺序发生变化,就会出现名称不对应的问题。
使用lable 挂载不用担心插槽顺序的问题。
每个分区被格式化以后都会有一个uuid 作为唯一标识,使用uuid 挂载可以避免这种问题。

第二列,Mount point 设备的挂载点,就是你要挂载在哪个目录下。

第三列,filesystem 磁盘文件系统的格式,包括ext2、ext3、ext4等

第四列,parameters 文件系统的参数
VirtualBox 添加一块新硬盘

第五列,能否被dump备份命令作用:dump是一个用来作为备份的命令。通常这个参数的值为0或者1
VirtualBox 添加一块新硬盘

第六列,是否检验扇区,开机的过程中,系统默认会以fsck检验我们系统是否为完整(clean)
VirtualBox 添加一块新硬盘

问题:
centos mkfs.ext4: No such file or directory

[[email protected] ~]$ sudo mkfs -t ext4 /dev/sdb1
mkfs.ext4: No such file or directory
[[email protected] ~]$ sudo partprobe
[[email protected] ~]$ sudo mkfs -t ext4 /dev/sdb1
mkfs.ext4: No such file or directory
[[email protected] vagrant]# mkfs.ext4 /dev/sdb1
bash: mkfs.ext4: command not found

参考:https://bbs.csdn.net/topics/391832321

执行一下 mkfs.ext4 /dev/sdb5
如果提示-bash: mkfs.ext4: command not found 
那就说明ext4模块未加载,
可以执行lsmod | grep ext4
查询一下,然后进入 /lib/modules/2.6.18-194.el5/kernel/fs/ext4/ 去查看ext4.ko是否存在
存在的话,用insmod ext4尝试安装 备注:根据内核版本不同 ,调整2.6.18-194.el5名称
然后安装e4fsprogs 
最后重新格式化

参考:http://blog.51cto.com/newyue/807195

解决:

[[email protected] vagrant]# rpm -qa | grep e4fsprogs
[[email protected] vagrant]# uname -r
3.10.0-862.14.4.el7.x86_64
[[email protected] vagrant]# ls /lib/modules/3.10.0-862.14.4.el7.x86_64/kernel/fs/ext4/
ext4.ko.xz
[[email protected] vagrant]# lsmod | grep ext4
ext4                  571716  1
mbcache                14958  1 ext4
jbd2                  103046  1 ext4
[[email protected] vagrant]# yum install e4fsprogs
[[email protected] vagrant]# rpm -qa | grep e2fsprogs
e2fsprogs-1.42.9-13.el7.x86_64
e2fsprogs-libs-1.42.9-13.el7.x86_64

参考:

https://blog.csdn.net/lilovfly/article/details/52878142
https://www.cnblogs.com/juandx/p/5618162.html
https://150643.com/466.html
https://www.cnblogs.com/qiyebao/p/4484047.html

相关文章: