1、fdisk -l命令:
1)添加磁盘之前,先用fdisk -l查看磁盘的基本信息
[root@localhost ~]# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0004cfc7
Device Boot Start End Blocks Id System
/dev/sda1 * 1 39 307200 83 Linux
Partition 1 does not end on cylinder boundary.(注:sda1的end和sda2的start,sda2的end和sda3的start都重复了,终端提 示: Partition 1 does not end on cylinder boundary。这句话的意思是说:分区 1 没有在柱面上结束)
/dev/sda2 39 549 4096000 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 549 5222 37538816 83 Linux
2)系统增加磁盘后,通过fdisk可以查看到新添加的磁盘信息
示例是在虚拟机运行的,关闭系统,在虚拟机的设置里,增加了一块20G的磁盘
[root@localhost oracle]# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0004cfc7
Device Boot Start End Blocks Id System
/dev/sda1 * 1 39 307200 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 39 549 4096000 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 549 5222 37538816 83 Linux
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x782437c8
Device Boot Start End Blocks Id System
/dev/sdb1 1 654 5253223+ 83 Linux
红色部分为新添加的磁盘信息
说明:Linux系统的分区格式使用的是xyzN的格式,xy表示的是硬盘类型,如上面的执行结果,sd表示是SCSI硬盘,z表示的是硬盘序号,第一块硬盘是a,第二块硬盘是b,所以要查询Linux系统上有几块硬盘,只要注意这一点即可。N表示的是分区号。
3)这个时候磁盘还不能挂载到系统,需要对新添加的磁盘进行分区
[root@localhost oracle]# fdisk /dev/sdb
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n(新建)
Command action
e extended
p primary partition (1-4)
p(主分区)
Partition number (1-4): 2(编号为2,在linux里最多只能建立四个主分区,所以通常至少建一个扩展分区,编号1-4为主分区的编号,逻辑分区的编号从5开始。如果只有一个主分区1,则2,3,4号空缺,直接从5号开始及1,5)
First cylinder (655-2610, default 655):
Using default value 655
Last cylinder, +cylinders or +size{K,M,G} (655-2610, default 2610): +5G(用+表示分5G大小的磁盘空间)
Command (m for help): w(w表示保存)
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
4)分区结束后,再次通过fdisk -l查询,结果如下:
[root@localhost oracle]# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0004cfc7
Device Boot Start End Blocks Id System
/dev/sda1 * 1 39 307200 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 39 549 4096000 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 549 5222 37538816 83 Linux
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x782437c8
Device Boot Start End Blocks Id System
/dev/sdb1 1 654 5253223+ 83 Linux
/dev/sdb2 655 1308 5253255 83 Linux(磁盘划分成功)
5)挂载之前需要对分区进行格式化,这里格式成ext4
[root@localhost oracle]# mkfs -t ext4 /dev/sdb2
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
328656 inodes, 1313313 blocks
65665 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1346371584
41 block groups
32768 blocks per group, 32768 fragments per group
8016 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost oracle]#
6)创建挂载点
[root@localhost oracle]# mkdir data
[root@localhost oracle]#
7)通过mount挂载
[root@localhost oracle]# mount /dev/sdb1 /data
[root@localhost oracle]#
注意:挂载点必须是一个目录,如果挂载之前,目录内有文件,则挂载后文件不可见
8)配置开机自启动
Vi /etc/fstab最后一行添加
/dev/sdb1 /data ext4 defaults 0 0
如果以上未能明白,这边推荐一个其他人写的文章:
https://blog.youkuaiyun.com/yangzhengquan19/article/details/83788277