本文共 2337 字,大约阅读时间需要 7 分钟。
fdisk是Linux系统中一个强大的磁盘分区工具,常用于管理和分区硬盘。以下是使用fdisk的一些常用操作示例:
使用fdisk -l
命令查看当前挂载设备的磁盘情况:
[root@VM_168_102_centos ~]# fdisk -l
输出会显示每个硬盘的总大小、分区情况、磁头、扇区等详细信息。
如果需要查看某个特定磁盘的分区情况,可以使用fdisk -l /dev/xvda
命令:
[root@VM_168_102_centos ~]# fdisk -l /dev/xvda
在进入fdisk界面之前,系统会提示是否需要写入更改内容,输入y
继续:
[root@VM_168_102_centos ~]# fdisk /dev/xvda
进入界面后,可以输入m
查看帮助信息。
选择n
创建新分区,输入p
创建主分区:
[root@VM_168_102_centos ~]# fdisk /dev/xvdb[root@VM_168_102_centos ~]# n[root@VM_168_102_centos ~]# p
选择n
创建新分区,并选择e
表示扩展分区:
[root@VM_168_102_centos ~]# fdisk /dev/xvdb[root@VM_168_102_centos ~]# n[root@VM_168_102_centos ~]# e
选择l
创建逻辑分区:
[root@VM_168_102_centos ~]# fdisk /dev/xvdb[root@VM_168_102_centos ~]# n[root@VM_168_102_centos ~]# l
选择分区并输入t
命令调整类型:
[root@VM_168_102_centos ~]# fdisk /dev/xvdb[root@VM_168_102_centos ~]# t
选择要删除的分区并输入d
命令:
[root@VM_168_102_centos ~]# fdisk /dev/xvdb[root@VM_168_102_centos ~]# d
使用cat /proc/mounts
查看当前挂载情况:
[root@VM_168_102_centos ~]# cat /proc/mounts
使用mke2fs
命令格式化文件系统:
[root@VM_168_102_centos ~]# mke2fs /dev/xvdb1
使用blkid
命令查看设备属性:
[root@VM_168_102_centos ~]# blkid /dev/xvdb1
指定文件系统类型:
[root@VM_168_102_centos ~]# mke2fs -t ext4 /dev/xvdb1
使用e2label
命令设置卷标:
[root@VM_168_102_centos ~]# e2label /dev/xvdb1
使用tune2fs
命令优化文件系统参数:
[root@VM_168_102_centos ~]# tune2fs -m /dev/xvdb1
使用fsck
命令修复文件系统错误:
[root@VM_168_102_centos ~]# fsck -a /dev/xvda1
使用mount
命令挂载文件系统:
[root@VM_168_102_centos ~]# mount /dev/xvda1 /
使用umount
命令卸载文件系统:
[root@VM_168_102_centos ~]# umount /dev/xvda1
指定挂载点:
[root@VM_168_102_centos ~]# mount /dev/xvda1 /mnt/wanghan
/etc/fstab
编辑/etc/fstab
文件:
[root@VM_168_102_centos ~]# vim /etc/fstab
使用df
命令:
[root@VM_168_102_centos ~]# df
使用free
命令:
[root@VM_168_102_centos ~]# free
使用dd
命令:
[root@VM_168_102_centos ~]# dd if=/tmp/test.sh of=/tmp/ceshi.sh
备份MBR并恢复:
[root@VM_168_102_centos ~]# dd if=/dev/xvdb of=/tmp/xvdb[root@VM_168_102_centos ~]# dd if=/dev/zero of=/dev/xvdb[root@VM_168_102_centos ~]# fdisk -l /dev/xvdb[root@VM_168_102_centos ~]# dd if=/tmp/xvdb of=/dev/xvdb
通过以上命令,可以完成磁盘分区管理和文件系统操作的常用任务,熟练掌握这些命令有助于系统维护和管理。
转载地址:http://chzfk.baihongyu.com/