1、dfisk -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 tempmount
[root@localhost oracle]#
7)通过mount挂载
[root@localhost oracle]# mount /dev/sdb2 tempmount
[root@localhost oracle]#
注意:挂载点必须是一个目录,如果挂载之前,目录内有文件,则挂载后文件不可见
挂载之前
挂载之后
挂载之后,文件夹内的原有文件看不见了,但是没有消失,unmount之后才能看见。
unmount 用法,
unmount /dev/sdb2 tempmount
unmount /dev/sdb2
unmount tempmount(这个是挂载点的相对路径,要看当前所在的目录)
2、df命令
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 36949700 16250660 18822100 47% /
tmpfs 953376 228 953148 1% /dev/shm
/dev/sda1 297485 37226 244899 14% /boot
在这里大家会发现,df查询出来的磁盘信息没有sda2,这是因为sda2是swap分区,df命令不能查看swap分区
注:linux swap分区是linux交换分区:
1.如果linux系统物理内存不够用了,系统会用swap分区;
2.如果物理内存不够用了,系统会把物理内存里的访问频率低的内存对象移动到swap里,再在物理内存里产生新的连接指向swap里的那个对象;
附:fdisk和mkfs,mkswap命令的参数解释
Fdisk命令详解:
m:获取帮助
n:新建分区
p:显示分区表
d:删除分区
b:设置卷标
w:写入分区表
t:改变分区文件系统类型
v:检验分区
l:显示fdisk所支持的文件系统代码
q:退出
文件系统的建立:
mkfs参数分区
-t文件系统类型指定建立的文件系统类型
注:mkfs –t ext3 =mkfs.ext3
-c建立文件系统之前检查有无坏道
-l文件名:从文件中读取坏道的情况
-v显示详细情况
mkswap 分区在分区上建立交换分区
例:在hdb7上建立交换分区命令如下:
mkswap/etc/hdb7
文件系统详解https://www.cnblogs.com/alantu2018/p/8461749.html