磁盘和文件系统的管理命令

磁盘和文件系统的管理命令

fdisk:磁盘分区工具

功能说明:

  • 受mbr分区表的影响,fdisk工具只能给小于2TB的磁盘划分分区。
  • 如果使用fdisk对大于2TB的磁盘进行分区,虽然可以分区,但是仅识别2TB的空间。
  • 磁盘容量大于2TB的,可以使用parted工具进行分区

语法格式:

fdisk [option] device(设备名)

选项说明:

参数选项 解释说明
-l 显示磁盘分区的信息

案例:

#fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x0006cf2a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    41943039    20458496   8e  Linux LVM

Disk /dev/mapper/centos-root: 18.8 GB, 18756927488 bytes, 36634624 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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


  • 信息说明:

    • Device:分区,显示有3个分区
    • Boot:启动分区,* 表示的是启动分区。
    • Start:表示开始的柱面。
    • End:表示结束的柱面。
    • Blocks:block块的数量
    • Id:分区类型ID
    • Sysytem:系统类型
  • 添加一个1GB的硬盘

#fdisk -l

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x0006cf2a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    41943039    20458496   8e  Linux LVM

  • 指定特定分区查看信息
#fdisk -l /dev/sdb

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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

  • 交互式分区
#ls /dev/sd*          》》》查看分区前设备的状态
/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb
#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 0xcbde9f8c.

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): 
Using default response p
Partition number (1-4, default 1): 
First sector (2048-2097151, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +100M
Partition 1 of type Linux and of size 100 MiB is set

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): 
Using default response p
Partition number (2-4, default 2): 
First sector (206848-2097151, default 206848): 
Using default value 206848
Last sector, +sectors or +size{K,M,G} (206848-2097151, default 2097151): +200M
Partition 2 of type Linux and of size 200 MiB is set

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): 
Using default response p
Partition number (3,4, default 3): 
First sector (616448-2097151, default 616448): 
Using default value 616448
Last sector, +sectors or +size{K,M,G} (616448-2097151, default 2097151): +300M
Partition 3 of type Linux and of size 300 MiB is set

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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: 0x63ff9647

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048      206847      102400   83  Linux
/dev/sdb2          206848      616447      204800   83  Linux
/dev/sdb3          616448     1230847      307200   83  Linux
Command (m for help): n
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): e
Selected partition 4
First sector (1230848-2097151, default 1230848): 
Using default value 1230848
Last sector, +sectors or +size{K,M,G} (1230848-2097151, default 2097151): _^H
Last sector, +sectors or +size{K,M,G} (1230848-2097151, default 2097151): +100M
Partition 4 of type Extended and of size 100 MiB is set

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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: 0x8dcdc089

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048      206847      102400   83  Linux
/dev/sdb2          206848      616447      204800   83  Linux
/dev/sdb3          616448     1230847      307200   83  Linux
/dev/sdb4         1230848     1435647      102400    5  Extended

Command (m for help): n
All primary partitions are in use
Adding logical partition 5
First sector (1232896-1435647, default 1232896): 
Using default value 1232896
Last sector, +sectors or +size{K,M,G} (1232896-1435647, default 1435647): +100M
Value out of range.
Last sector, +sectors or +size{K,M,G} (1232896-1435647, default 1435647): +50M
Partition 5 of type Linux and of size 50 MiB is set

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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: 0x8dcdc089

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048      206847      102400   83  Linux
/dev/sdb2          206848      616447      204800   83  Linux
/dev/sdb3          616448     1230847      307200   83  Linux
/dev/sdb4         1230848     1435647      102400    5  Extended
/dev/sdb5         1232896     1335295       51200   83  Linux

Command (m for help): n
All primary partitions are in use
Adding logical partition 6
First sector (1337344-1435647, default 1337344): q
First sector (1337344-1435647, default 1337344): 
Using default value 1337344
Last sector, +sectors or +size{K,M,G} (1337344-1435647, default 1435647): 
Using default value 1435647
Partition 6 of type Linux and of size 48 MiB is set

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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: 0x8dcdc089

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048      206847      102400   83  Linux
/dev/sdb2          206848      616447      204800   83  Linux
/dev/sdb3          616448     1230847      307200   83  Linux
/dev/sdb4         1230848     1435647      102400    5  Extended
/dev/sdb5         1232896     1335295       51200   83  Linux
/dev/sdb6         1337344     1435647       49152   83  Linux

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

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

  • 格式化磁盘,并挂载
#mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25688 inodes, 102400 blocks
5120 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33685504
13 block groups
8192 blocks per group, 8192 fragments per group
1976 inodes per group
Superblock backups stored on blocks: 
    8193, 24577, 40961, 57345, 73729

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


[root@lhf 13:44:34 /root]
#mkdir /data1

[root@lhf 13:45:03 /root]
#mount /dev/sdb1 /data1/

[root@lhf 13:45:13 /root]
#df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        18G  978M   17G   6% /
devtmpfs                devtmpfs  479M     0  479M   0% /dev
tmpfs                   tmpfs     489M     0  489M   0% /dev/shm
tmpfs                   tmpfs     489M  6.8M  483M   2% /run
tmpfs                   tmpfs     489M     0  489M   0% /sys/fs/cgroup
/dev/sda1               xfs       497M  125M  373M  25% /boot
tmpfs                   tmpfs      98M     0   98M   0% /run/user/0
/dev/sdb1               ext4       93M  1.6M   85M   2% /data1

partprobe: 更新内核的硬盘分区表信息

功能说明:

  • 在硬盘分区发生变化时,更新Linux内核中硬盘分区表数据。
  • 有时候使用fdisk或parted对硬盘进行分区后,找不到新分区,需要重新才能生效,】
  • 使用partprobe可以不重新系统让修改的分区表生效。

语法格式

partprobe [option]
参数选项 解释说明
-d 不更新内核
-s 显示摘要和分区

案例

  • 更新分区表信息
#partprobe /dev/sdb

tune2fs:调整ext2/ext3/ext4文件系统参数

功能说明:

  • 调整ext2/ext3/ext4文件系统的参数

语法格式:

tune2fs [option]
选项参数 解释说明
-c 设置强制自检的挂载次数
-C 设置文件系统已经被挂载的次数
-i 设置强制自检的时间间隔(天、周、月)
-j 将ext2文件转化为ext3类型的文件系统
-l 查看文件系统信息

案例

  • 查看文件的挂载信息
#tune2fs -l /dev/sdb1 | grep -i Mount
Last mounted on:          
Default mount options:    user_xattr acl
Last mount time:          Thu Oct 31 13:45:13 2019
Mount count:              1
Maximum mount count:      -1

  • 设置挂载次数
#tune2fs -C 30 /dev/sdb1
tune2fs 1.42.9 (28-Dec-2013)
Setting current mount count to 30

[root@lhf 14:21:32 /root]
#tune2fs -l /dev/sdb1 | grep -i Mount
Last mounted on:          
Default mount options:    user_xattr acl
Last mount time:          Thu Oct 31 13:45:13 2019
Mount count:              30
Maximum mount count:      -1
  • 设置强制自检的挂载次数
#tune2fs -c 40 /dev/sdb1
tune2fs 1.42.9 (28-Dec-2013)
Setting maximal mount count to 40

[root@lhf 14:22:47 /root]
#tune2fs -l /dev/sdb1 | grep -i Mount
Last mounted on:          
Default mount options:    user_xattr acl
Last mount time:          Thu Oct 31 13:45:13 2019
Mount count:              30
Maximum mount count:      40

  • 设置强制自检的时间间隔
#tune2fs -i 10 /dev/sdb1
tune2fs 1.42.9 (28-Dec-2013)
Setting interval between checks to 864000 seconds

[root@lhf 14:24:43 /root]
#tune2fs -l /dev/sdb1 | grep -i check
Last checked:             Thu Oct 31 13:44:34 2019
Check interval:           864000 (1 week, 3 days)
Next check after:         Sun Nov 10 12:44:34 2019

你可能感兴趣的:(磁盘和文件系统的管理命令)