linux磁盘和文件系统
磁盘管理及分区
fdisk -l 查看系统中的磁盘设备
未查找到系统新接入的磁盘
扫描重新加入的磁盘
ls /sys/class/scsi_host ##查询HBA总线编号###
echo "- - -" > /sys/class/scsi_host/host0/scan $$ echo "- - -" > /sys/class/scsi_host/host1/scan $$ echo "- - -" > /sys/class/scsi_host/host2/scan
### dmesg | grep -i "sd" ####检测新硬盘是否被识别#
磁盘管理及分区
列出磁盘设备信息:显示系统中所有磁盘设备的名称,如/dev/sda
、/dev/sdb
等.
展示磁盘容量:提供每个磁盘的总容量大小,以字节为单位,也会换算成更易读的单位如 GB、TB 等。
显示分区表类型:说明磁盘使用的分区表类型,常见的有 MBR(Master Boot Record)和 GPT(GUID Partition Table)。
列出分区详细信息:包括每个分区的设备名称、起始位置、结束位置、分区大小、分区类型等。
关键字信息:
Device:分区的设备文件名称。 Boot:是否是引导分区。若是引导分区,则有“*”标识。 Start :该分区在硬盘中的起始位置(柱面数)。 End:该分区在硬盘中的结束位置(柱面数) Blocks:分区的大小,以Blocks(块)为单位,默认的块大小为1024字节。 ID:分区对应的系统ID。83 表示 Linux操作系统中的XFS 分区,8e表示 LVM 逻辑卷。
system:分区类型
进入指定磁盘分区模式命令:
fdish /dev/sdb sd(二十六英文选择)
[root@localhost ~]# 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.此为日志,进入磁盘分区工具
Command (m for help): n ( 创建新的磁盘分区)
Partition type:
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): p
Partition number (3,4, default 3):
First sector (12584960-41943039, default 12584960): (可直接回车)
Using default value 12584960
Last sector, +sectors or +size{K,M,G} (12584960-41943039, default 41943039): +1G
(设置大小)
使用P查看磁盘分区情况
Command (m for help): p
创建新的分区
Command (m for help): n
创建主分区
Partition type: p
提示分区选择:
p primary (2 primary, 1 extended, 1 free) (主分区)
l logical (numbered from 5) (逻辑分区)
创建扩展分区
Select (default p): e
删除分区5
Command (m for help): d
Partition number (1,2,5, default 5): 5
Partition 5 is deleted
更改分区类型
Command (m for help): t
Partition number (1,2, default 2): 2
查询Linux中分区类型详解: 可自行查询
Hex code (type L to list all codes): l
查看分区情况
Command (m for help): p
退出
使用w和q可以退出,w保存退出,q不保存
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table. Syncing disks.
[root@localhost ~]# 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.
Command (m for help): q
[root@localhost ~]#
挂载
mkswap命令将/dev/sdb1改为xfs linux 83
(同样可设置为其他文件系统)
[root@localhost ~]# mkfs -t xfs /dev/sdb5
mkswap命令将/dev/sdb1改为交换分区(虚拟内存)
此前以做过交换分区定义
临时挂载
光盘/dev/sdb5挂载到/etc/mnt,
[root@localhost /]# mount /dev/sdb5 /etc/mnt mount: /dev/sdb5 is already mounted on /etc/mnt
卸载文件系统
[root@localhost /]# umount /etc/mnt 绝对目录 [root@localhost /]# umount /dev/sdb5 选定光盘对象
查看磁盘使用情况
[root@localhost /]# df -hT
配置永久挂载
编辑/etc/fstab文件。在文件末尾添加一行: /dev/sdb1 /mnt/data ext4 defaults 0 0
各字段含义如下:
第一个字段:磁盘分区设备名,这里是/dev/sdb1。
第二个字段:挂载点,即之前创建的/mnt/data。
第三个字段:文件系统类型,这里是ext4。
第四个字段:挂载选项,defaults表示使用默认选项。
第五个字段:用于dump工具备份,0表示不备份。
第六个字段:用于fsck工具检查磁盘的顺序,0表示不检查。
使用以下命令编辑/etc/fstab文件: vim /etc/fstab
验证永久挂载 使用mount -a
命令重新挂载/etc/fstab文件中所有的文件系统, mount -a