4、磁盘管理

时间:2021-10-23
本文章向大家介绍4、磁盘管理,主要包括4、磁盘管理使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1、mke2fs mkfs.xfs

mke2fs命令被用于创建磁盘分区上的“etc2/etc3”文件系统  

mkfs.xfs命令创建 xfs 文件系统
语法:

mke2fs (选项)(参数)  

mke2fs -t ext4 /dev/sdb1   #格式化磁盘为ext4格式 


2、mount

mount命令用于加载文件系统到指定的加载点。此命令的最常用于挂载cdrom,使我们可以访问cdrom中的数据,因为你将光盘插入cdrom中,Linux并不会自动挂载,必须使用 mount命令来手动完成挂载。
语法:

mount (选项)(参数)
选项:

-V:显示程序版本;
-l:显示已加载的文件系统列表;
-h:显示帮助信息并退出;
-v:冗长模式,输出指令执行的详细信息;
-n:加载没有写入文件“/etc/mtab”中的文件系统;
-r:将文件系统加载为只读模式;
-a:加载文件“/etc/fstab”中描述的所有文件系统。

umount

umount命令用于卸载已经加载的文件系统


3、df

df命令用于显示磁盘分区上的可使用的磁盘空间。默认显示单位为KB。可以利用该命令来获取硬盘被占用了多少空间,目前还剩下多少空间等信息。
参数:

-a:包含全部的文件系统;
--block-size=<区块大小>:以指定的区块大小来显示区块数目;
-h:以可读性较高的方式来显示信息;
-H:与-h参数相同,但在计算时是以1000 Bytes为换算单位而非1024 Bytes;
-i:显示inode的信息;
-l:仅显示本地端的文件系统;
-m:指定区块大小为1048576字节;
--help:显示帮助;
--version:显示版本信息。

4、fdisk

fdisk命令用于观察硬盘实体使用情况,也可对硬盘分区

fdisk /dev/sdb
输入m列出可以执行的命令:

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
    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)


输入p列出磁盘目前的分区情况:

Command (m for help): p

Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1           1        8001   8e  Linux LVM
/dev/sdb2               2          26      200812+  83  Linux


输入d然后选择分区,删除现有分区:

Command (m for help): d
Partition number (1-4): 1

Command (m for help): d
Selected partition 2


查看分区情况,确认分区已经删除:

Command (m for help): p

Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

Command (m for help):


输入n建立新的磁盘分区,首先建立两个主磁盘分区:

Command (m for help): n
Command action
    e   extended
    p   primary partition (1-4)
p    #建立主分区
Partition number (1-4): 1  #分区号
First cylinder (1-391, default 1):  #分区起始位置
Using default value 1
last cylinder or +size or +sizeM or +sizeK (1-391, default 391): 100  #分区结束位置,单位为扇区

Command (m for help): n #再建立一个分区
Command action
    e   extended
    p   primary partition (1-4)
p     #建立主分区
Partition number (1-4): 2  #分区号为2
First cylinder (101-391, default 101):
Using default value 101
Last cylinder or +size or +sizeM or +sizeK (101-391, default 391): +200M  #分区结束位置,单位为M


确认分区建立成功:

Command (m for help): p

Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         100      803218+  83  Linux
/dev/sdb2             101         125      200812+  83  Linux


再建立一个逻辑分区:

Command (m for help): n
Command action
    e   extended
    p   primary partition (1-4)
e  #选择扩展分区
Partition number (1-4): 3
First cylinder (126-391, default 126):
Using default value 126
Last cylinder or +size or +sizeM or +sizeK (126-391, default 391):
Using default value 391


确认扩展分区建立成功:

Command (m for help): p

Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         100      803218+  83  Linux
/dev/sdb2             101         125      200812+  83  Linux
/dev/sdb3             126         391     2136645    5  Extended


在扩展分区上建立两个逻辑分区:

Command (m for help): n
Command action
    l   logical (5 or over)
    p   primary partition (1-4)
l #选择逻辑分区
First cylinder (126-391, default 126):
Using default value 126
Last cylinder or +size or +sizeM or +sizeK (126-391, default 391): +400M   

Command (m for help): n
Command action
    l   logical (5 or over)
    p   primary partition (1-4)
l
First cylinder (176-391, default 176):
Using default value 176
Last cylinder or +size or +sizeM or +sizeK (176-391, default 391):
Using default value 391


确认逻辑分区建立成功:

Command (m for help): p

Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         100      803218+  83  Linux
/dev/sdb2             101         125      200812+  83  Linux
/dev/sdb3             126         391     2136645    5  Extended
/dev/sdb5             126         175      401593+  83  Linux
/dev/sdb6             176         391     1734988+  83  Linux

Command (m for help):


以上操作:在硬盘sdb建立了2个主分区(sdb1,sdb2),1个扩展分区(sdb3),2个逻辑分区(sdb5,sdb6)
注意:主分区和扩展分区的磁盘号位1-4,也就是说最多有4个主分区或者扩展分区,逻辑分区开始的磁盘号为5,因此没有sdb4。

最后对分区操作进行保存:

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

Calling ioctl() to re-read partition table.
Syncing disks.


建立好分区之后,还需要对分区进行格式化才能在系统中使用磁盘。

格式化后需要手动挂载,如果需系统自动挂载的话,要更改文件/etc/fstab 在文件的后面添加对应的配置

原文地址:https://www.cnblogs.com/ArvinLinuxThink/p/15449753.html