Linux的磁盘管理:
Linux的核心:一切介文件: open,read,write,close 块设备:block,存取单位‘块’,磁盘 字符设备:char 存取单位‘字符’,键盘 设备文件:关联至一个设备驱动程序,进而能够跟与之对应硬件设备进行通信: 设备号码: 主设备号:major number:标识设备类型: 次设备号:minor number:表示同一类型的不同设备: 设备类型基本上都存放在/dev下:使用ls-l可以看到 [root@localhost dev]# ls -l total 0 crw-rw----. 1 root root 10, 57 Jul 14 22:02 autofs drwxr-xr-x. 2 root root 660 Jul 14 22:01 block drwxr-xr-x. 2 root root 60 Jul 14 22:01 bsg drwxr-xr-x. 3 root root 60 Jul 14 22:01 bus drwxr-xr-x. 2 root root 2660 Jul 14 22:02 char crw-------. 1 root root 5, 1 Jul 14 22:01 console lrwxrwxrwx. 1 root root 11 Jul 14 22:01 core -> /proc/kcore drwxr-xr-x. 3 root root 80 Jul 14 22:01 cpu crw-rw----. 1 root root 10, 61 Jul 14 22:01 cpu_dma_latency crw-rw----. 1 root root 10, 62 Jul 14 22:01 crash drwxr-xr-x. 6 root root 120 Jul 14 22:01 disk lrwxrwxrwx. 1 root root 3 Jul 14 22:01 fb -> fb0 crw-rw----. 1 root root 29, 0 Jul 14 22:01 fb0 lrwxrwxrwx. 1 root root 13 Jul 14 22:01 fd -> /proc/self 综上可以看到前一个代表的主设备号,后面标记这主设备下各个不同的设备: 硬盘接口类型: 并行: IDE:133MB/s SCSI:640MB/s 串口: SATA:6Gbps SAS:6Gbps USB:480MB/s 磁盘设备的设备文件名称: /dev/DEV_FILE IDE:/dev/hd SCSI,SATA,SAS,USB:/dev/sd 不同设备可以使用:a-z 同一设备上的不同分区:1.2.3。。。。。 机械式硬盘: track:磁道 cylinder:柱面 secotr:扇区 一个扇区=512bytes 综上所述:按柱面进行分区 ❤❤❤同一个磁盘只能有3个主分区任意个逻辑分区❤❤❤ Linux上的分区管理工具:fdisk,parted,sfdisk fdisk:对于单块硬盘来说,最多只能管理15个分区!! [root@localhost ~]# fdisk -l Disk /dev/sda: 128.8 GB, 128849018880 bytes 255 heads, 63 sectors/track, 15665 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00073dc7 Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 2675 20971520 83 Linux /dev/sda3 2675 3981 10485760 83 Linux /dev/sda4 3981 15666 93858816 5 Extended [root@localhost ~]# fdisk -l /dev/sda1 Disk /dev/sda1: 524 MB, 524288000 bytes 255 heads, 63 sectors/track, 63 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 使用磁盘参数查看具体每个磁盘的参数: fdisk的命令中的分项: p:print,显示已有分区 n:new,创建一个新分区 d:delete,删除 w:write 写入磁盘并退出 q:quit,放弃更新并退出 m:获取帮助 l:列表所分区id t:调整分区id 查看内核是否已经识别新的分区: cat/proc/partations [root@localhost ~]# cat /proc/partitions major minor #blocks name 8 0 125829120 sda 8 1 512000 sda1 8 2 20971520 sda2 8 3 10485760 sda3 8 4 1 sda4 8 5 2097152 sda5 8 6 10486742 sda6 通知内核重新读取硬盘分区表 partx -a /dev/DEVICE [root@localhost ~]# partx -a /dev/sda BLKPG: Device or resource busy error adding partition 1 BLKPG: Device or resource busy error adding partition 2 BLKPG: Device or resource busy error adding partition 3 BLKPG: Device or resource busy error adding partition 4 BLKPG: Device or resource busy error adding partition 5 BLKPG: Device or resource busy error adding partition 6 如果上诉命名不生效的时候可以使用: koartx kpartx -a /dev/DEVICE
Linux文件系统管理:
Linux文件系统:ext2,ext3,ext4,btrfs,swap,xfs,jfs,reiserfs
swap:是交换分区,用来将磁盘当内存使用
光盘:iso9660
Windows:fat32,ntfs
Unix:FFS,UFS,JFS2
网络文件系统:NFS,CIFS
集群文件:GFS2,OCFS2
分布式文件系统:cdph,
moosefs,mogilefs,gluserFS,Lunstre
根据其是否支持:“journal”功能
日志型文件系统:ext3,ext4,xfs....
非日志型文件系统:ext2,vfat
文件系统的组成部分:
内核中的模块:ext4,xfs,vfat
用户空间的管理工具:mkfs.ext4,mkfs.xfs,mkfs.vfat
Linux虚拟文件系统:VFS
查看系统上可以使用的文件系统:
cat/proc/filesystems
❤❤❤❤这里实验发现:如果在内核没有识别新的分区的时候,开始对新分区的磁盘进行格式化,那么系统会报错,指出系统上没有此文件无法进行调用,所以对磁盘创建文件系统的时候先使用partx -a对已划分的磁盘进行内核读取!!!!❤❤❤
mkfs命令:
(1)mkfs.FS_TYPE /dev/DEVICE
ext4
[root@localhost ~]# mkfs.ext4 /dev/sda6
mke2fs 1.41.12 (17-May-2010)
warning: 245 blocks unused.
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
656640 inodes, 2621440 blocks
131084 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
8208 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
xfs
[root@localhost ~]# mkfs.xfs -f /dev/sda5
meta-data=/dev/sda5 isize=256 agcount=4, agsize=655360 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=2621440, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
btrfs
root@localhost ~]# mkfs.btrfs -f /dev/sda5
btrfs-progs v3.19.1
See http://btrfs.wiki.kernel.org for more information.
Turning ON incompat feature 'extref': increased hardlink limit per file to 65536
Turning ON incompat feature 'skinny-metadata': reduced-size metadata extent refs
fs created label (null) on /dev/sda5
nodesize 16384 leafsize 16384 sectorsize 4096 size 10.00GiB
vfat
mke2fs:ext系列文件系统专用管理工具
-t {ext2|ext3|ext4}
-b {1024|2048|4096}
-L 'LABEL'
-j: 相当于 -t ext3
mkfs.ext3 = mkfs -t ext3 = mke2fs -j = mke2fs -t ext3
-i #: 为数据空间中每多少个字节创建一个inode;此大小不应该小于block的大小;
-N #:为数据空间创建个多少个inode;
-m #: 为管理人员预留的空间占据的百分比;
-O FEATURE[,...]:启用指定特性
-O ^FEATURE:关闭指定特性
mkswap:创建交换分区
mkswap [options] device
-L 'LABEL'
前提:调整其分区的ID为82;
其它常用工具:
blkid:块设备属性信息查看
blkid [OPTION]... [DEVICE]
[root@localhost ~]# blkid /dev/sda6
/dev/sda6: LABEL="MYDATA" UUID="2bc19b3c-d451-473e-81ad-e28ed346f844" TYPE="ext4"
-U UUID: 根据指定的UUID来查找对应的设备
[root@localhost ~]# blkid -U 2bc19b3c-d451-473e-81ad-e28ed346f844
/dev/sda6
-L LABEL:根据指定的LABEL来查找对应的设备
[root@localhost ~]# blkid -L MYDATA
/dev/sda6
e2label:管理ext系列文件系统的LABEL
# e2label DEVICE [LABEL]
[root@localhost ~]# e2label /dev/sda6 hahah
[root@localhost ~]# blkid /dev/sda6
/dev/sda6: LABEL="hahah" UUID="2bc19b3c-d451-473e-81ad-e28ed346f844" TYPE="ext4"
tune2fs:重新设定ext系列文件系统可调整参数的值
-l:查看指定文件系统超级块信息;super block
-L 'LABEL':修改卷标
-m #:修预留给管理员的空间百分比
-j: 将ext2升级为ext3
-O: 文件系统属性启用或禁用
-o: 调整文件系统的默认挂载选项
-U UUID: 修改UUID号;
dumpe2fs:
-h:查看超级块信息
每一个独立的文件系统都对应了一个超级块
文件系统检测:
fsck: File System CheCk
fsck.FS_TYPE
fsck -t FS_TYPE
-a: 自动修复错误
-r: 交互式修复错误
Note: FS_TYPE一定要与分区上已经文件类型相同;
e2fsck:ext系列文件专用的检测修复工具
-y:自动回答为yes;
-f:强制修复;
:如果U盘既要在Windows上使用又要在linux 上使用文件系统必须为Vfat=fat32
原创文章,作者:wostop,如若转载,请注明出处:http://www.178linux.com/24932

