一、使用 ext4、xfs 格式化磁盘并挂载,实现重启后可自动挂载
1、ext4 格式化磁盘:
# fdisk -l 查看磁盘信息
[root@Demon /]# fdisk -lDisk /dev/sda: 107.4 GB, 107374182400 bytes255 heads, 63 sectors/track, 13054 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000d62dfDevice Boot Start End Blocks Id System/dev/sda1 * 1 52 409600 83 LinuxPartition 1 does not end on cylinder boundary./dev/sda2 52 574 4194304 82 Linux swap / SolarisPartition 2 does not end on cylinder boundary./dev/sda3 574 13055 100252672 83 Linux
# mkfs -t ext4 /dev/sda3 -t 是格式化后的磁盘格式,/dev/sda3 是将要格式化的磁盘
# mount /dev/sda3 /mnt/sda 将 /dev/sda3 挂载到 /mnt/sda 下
2、xfs 格式化磁盘:
格式化 xfs 需要用到 xfs工具集,先下载xfsprogs
# yum install xfsprogs
# mkfs.xfs -f /dev/sda3 -f 参数的作用是如果当前要格式化的磁盘已经是其他格式的文件系统,则覆盖
3、实现重启自动挂载
# vim /etc/fstab 磁盘挂载文件,要挂载的文件系统格式不同,挂载的参数也不同
a) ext3 / ext4 格式磁盘的挂载,在文件中加入下面参数:
/dev/sda? mount_to_file ext3 default 0 0
上面的 ? 指的是你要挂载的磁盘的盘符,mount_to_file 是你要把磁盘挂载到哪,ext3 是你要挂载的磁盘的格式,default 指明按照默认参数挂载, 0 0 表示开机不检查
b) fat32 格式磁盘的挂载,在文件中加入下面参数:
/dev/sda? mount_to_file vfat user,rw,utf8,umask=000 0 1
这里的?和 mount_to_file 跟上面的一样,vfat 为文件格式,user,rw指的是给用户读写的权限,utf8加上后会将Windows下的中文转换为 utf8格式,umask=000 指的是给
所有用户赋予了读写的权限, 0 0 表示开机检查
二、进行磁盘分区
# fdisk 参数说明
a :指定启动分区
d :删除一个存在的分区
l :显示分区 ID 号的列表
m:查看 fdisk 命令帮助
n :创建一个新的分区
p :显示分区列表
t :修改分区 ID 号
w:对分区表的修改保存,保存后会立即生效
# 对 /dev/sda3 磁盘进行分区
[root@Demon /]# fdisk /dev/sda (这里没有盘符)WARNING: DOS-compatible mode is deprecated. It's strongly recommended toswitch off the mode (command 'c') and change display units tosectors (command 'u').Command (m for help): p (查看磁盘信息)Disk /dev/sda: 107.4 GB, 107374182400 bytes255 heads, 63 sectors/track, 13054 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000d62dfDevice Boot Start End Blocks Id System/dev/sda1 * 1 52 409600 83 LinuxPartition 1 does not end on cylinder boundary./dev/sda2 52 574 4194304 82 Linux swap / SolarisPartition 2 does not end on cylinder boundary./dev/sda3 574 13055 100252672 83 LinuxCommand (m for help): d (删除磁盘)Partition number (1-4): 3 (删除 sda3)Command (m for help): pDisk /dev/sda: 107.4 GB, 107374182400 bytes255 heads, 63 sectors/track, 13054 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000d62dfDevice Boot Start End Blocks Id System/dev/sda1 * 1 52 409600 83 LinuxPartition 1 does not end on cylinder boundary./dev/sda2 52 574 4194304 82 Linux swap / SolarisPartition 2 does not end on cylinder boundary.Command (m for help): n (创建新的分区)Command actione extendedp primary partition (1-4) (主分区)e (扩展分区)Partition number (1-4): 4First cylinder (574-13054, default 574): (选择分区起始柱面)Using default value 574Last cylinder, +cylinders or +size{K,M,G} (574-13054, default 13054): (选择分区结束柱面)Using default value 13054Command (m for help): pDisk /dev/sda: 107.4 GB, 107374182400 bytes255 heads, 63 sectors/track, 13054 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000d62dfDevice Boot Start End Blocks Id System/dev/sda1 * 1 52 409600 83 LinuxPartition 1 does not end on cylinder boundary./dev/sda2 52 574 4194304 82 Linux swap / SolarisPartition 2 does not end on cylinder boundary./dev/sda4 574 13054 100251327 5 ExtendedCommand (m for help): nCommand actionl logical (5 or over)p primary partition (1-4)l (创建逻辑分区)First cylinder (574-13054, default 574):Using default value 574Last cylinder, +cylinders or +size{K,M,G} (574-13054, default 13054):Using default value 13054Command (m for help): pDisk /dev/sda: 107.4 GB, 107374182400 bytes255 heads, 63 sectors/track, 13054 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x000d62dfDevice Boot Start End Blocks Id System/dev/sda1 * 1 52 409600 83 LinuxPartition 1 does not end on cylinder boundary./dev/sda2 52 574 4194304 82 Linux swap / SolarisPartition 2 does not end on cylinder boundary./dev/sda4 574 13054 100251327 5 Extended/dev/sda5 574 13054 100251295+ 83 Linux接下来格式化分区
# mkfs -t ext4 /dev/sda4
三、查看磁盘容量
# df -lh
df 命令参数:
-a 全部文件系统列表
-h 方便阅读显示,一般用来查找大文件
-H 相当于 -h ,不过1k = 1000 而不是 1024
-i 显示 inode 信息,inode包含的信息:文件的字节数,拥有者id,组id,权限,改动时间,链接数,数据block的位置,不表示文件大小
-k 区块为1024字节
-l 只显示本地文件系统
-m 区块为1048576 字节
--no-sync 忽略sync 命令
-P 输出格式为 POSIX
--sync 在取得磁盘信息前,先执行 sync 命令
-T 文件系统类型