一、磁盘管理总体分类
1)磁盘结构
2)分区类型
3)管理分区
4)管理文件系统
5)挂载设备
6)管理虚拟内存
………………………………………………………………………………………………………………………
重要分类模块详解
………………………………………………………………………………………………………………………
1、磁盘常用术语
head:磁头 track:磁道 sector:扇区 cylinder:柱面
2、分区种类
1)主引导记录(MBR)
MBR: Master Boot Record,1982年,使用32位表示扇区数,分区不超过2T如何分区:按柱面0磁道0扇区:512bytes 446bytes: boot loader 64bytes:分区表 16bytes: 标识一个分区 2bytes: 55AA 4个主分区;3主分区+1扩展(N个逻辑分区)
2)GPT
GPT:GUID patition table (GUID分区表) 支持128个分区,使用64位,支 持8Z( 512Byte/block )64Z ( 4096Byte/block)使用128位UUID 表示磁盘和分区 GPT分区表自动备份在头 和尾两份,并有CRC校验位UEFI (统一扩展固件接口)硬件支持GPT
3、常用分区管理工具
lsblk命令:
lsblk – list block devices
演示:
[root@centos6 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 3.7G 0 rom sda 8:0 0 120G 0 disk ├─sda1 8:1 0 200M 0 part /boot ├─sda2 8:2 0 80G 0 part / ├─sda3 8:3 0 20G 0 part /testdir ├─sda4 8:4 0 1K 0 part ├─sda5 8:5 0 4G 0 part [SWAP] └─sda6 8:6 0 5G 0 part sdb 8:16 0 120G 0 disk sdc 8:32 0 20G 0 disk sdd 8:48 0 20G 0 disk sde 8:64 0 20G 0 disk [root@centos6 ~]#
fdisk命令:
fdisk – Partition table manipulator for Linux
fdisk -cu device fdisk device
常用子命令:
d delete a partition #删除分区表
l list known partition types #列出分区类型
m print this menu #打印帮助信息
n add a new partition #添加一个新的分区
p print the partition table #打印分区表
q quit without saving changes #不保存退出
t change a partition's system id #改变一个分区的系统ID
w write table to disk and exit #将分区表写入系统
partx/partprobe命令:通知内核重新读取硬盘分区表信息
partx -a /dev/device 例如:partx -a /dev/sda1
kpartx -a /dev/device -f:force
删除分区:
partx -d –nr # /dev/device #号表示删除的第几块分区
partx -d –nr 7 /dev/sda
CentOS5.x CentOS7.x使用:partprobe命令即可
查看内核是否已经识别新的分区:cat /proc/partitations
………………………………………………………………………………………………………………………
演示:
………………………………………………………………………………………………………………………
[root@centos6 ~]# fdisk -l /dev/sda 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: 0x000813f2 Device Boot Start End Blocks Id System /dev/sda1 * 1 26 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 26 10469 83886080 83 Linux /dev/sda3 10469 13080 20971520 83 Linux /dev/sda4 13080 15666 20765696 5 Extended /dev/sda5 13081 13603 4194304 82 Linux swap / Solaris /dev/sda6 13604 13865 2104515 83 Linux /dev/sda7 13866 13997 1060258+ 83 Linux [root@centos6 ~]# cat /proc/partitions major minor #blocks name 8 0 125829120 sda 8 1 204800 sda1 8 2 83886080 sda2 8 3 20971520 sda3 8 4 1 sda4 8 5 4194304 sda5 8 16 125829120 sdb 8 32 20971520 sdc 8 48 20971520 sdd 8 64 20971520 sde [root@centos6 ~]# partx -a /dev/sda sda sda1 sda2 sda3 sda4 sda5 [root@centos6 ~]# 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 [root@centos6 ~]# 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 BLKPG: Device or resource busy error adding partition 7 [root@centos6 ~]# !cat cat /proc/partitions major minor #blocks name 8 0 125829120 sda 8 1 204800 sda1 8 2 83886080 sda2 8 3 20971520 sda3 8 4 1 sda4 8 5 4194304 sda5 8 6 2104515 sda6 8 7 1060258 sda7 8 16 125829120 sdb 8 32 20971520 sdc 8 48 20971520 sdd 8 64 20971520 sde [root@centos6 ~]#
………………………………………………………………………………………………………………………
二、创建文件系统
mkfs命令:创建一个linux文件系统
mkfs – build a Linux file system
用法:
mkfs.fs_type /dev/device #fs_type{ext4 xfs btrfs vfat}
mkfs.fs_type /dev/device -L 'LABEL' #指定卷标
………………………………………………………………………………………………………………………
演示:
[root@centos6 ~]# mkfs.ext4 /dev/sda6 -L 'MYDATE' mke2fs 1.41.12 (17-May-2010) 文件系统标签=MYDATE 操作系统:Linux 块大小=4096 (log=2) 分块大小=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 131648 inodes, 526128 blocks 26306 blocks (5.00%) reserved for the super user 第一个数据块=0 Maximum filesystem blocks=541065216 17 block groups 32768 blocks per group, 32768 fragments per group 7744 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 正在写入inode表: 完成 Creating journal (16384 blocks): 完成 Writing superblocks and filesystem accounting information: 完成 This filesystem will be automatically checked every 27 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@centos6 ~]# blkdi -bash: blkdi: command not found [root@centos6 ~]# blkid /dev/sda2: UUID="240533cf-b37f-4460-974f-702bab867da5" TYPE="ext4" /dev/sda1: UUID="4e245c68-a392-4ce9-9a99-5d32d8d43872" TYPE="ext4" /dev/sda3: UUID="86aa7b74-24df-4043-ba83-f3b41a99ce0e" TYPE="ext4" /dev/sda5: UUID="f8ef48ef-b141-48e5-9735-ff9089bd54ba" TYPE="swap" /dev/sda6: UUID="b153fa9a-5b82-4bbc-b580-9170ab88b4a6" TYPE="ext4" LABEL="MYDATE" [root@centos6 ~]#
………………………………………………………………………………………………
mke2fs命令:创建ext系列文件系统
mke2fs – create an ext2/ext3/ext4 filesystem
选项:
-t{ext2|ext3|ext4} #指定文件类型
-b{1024|2048|4096} #指定块大小
-L 'LABEL' #指定卷标
-j #相当于mke2fs -t ext3,mkfs.ext3 = mkfs -t ext3 = mke2fs -j = mke2fs -t ext3
-i #: 为数据空间中每多少个字节创建一个inode;此大 小不应该小于block的大小
-N #: 为数据空间创建杜少而过inode
-m #: 为管理员预留的空间占总空间的百分比,默认为5%
blkid命令:
blkid – command-line utility to locate/print block device attributes
选项:
-U:UUID #按UUID来查找到相应的设备
-L:LABEL #按卷标查找到相应的设备名
e2label命令:
用法:e2label device LABEL
e2lable deveice
tune2fs命令:重新设定文件系统的超级块可调参数的属性值
选项:
-L 'LABEL':修改卷标
-j 将ext2升级到ext3
-o 调整文件系统挂载选项,acl,取消为^acl
-m #:修预留给管理员的空间百分比
dumpe2fs命令:
-h:查看超级块信息(分组信息),分区用分组管理
例如:dumpe2fs -h /dev/sda8 tune2fs -l /dev/sda8
文件修复和检测:
常发生于死机或者非正常关机之后,常发生于死机或者非正常关机之后
fsck: File System
Check fsck.FS_TYPE
fsck -t FS_TYPE
演示:
………………………………………………………………………………………………
[root@centos6 ~]# mke2fs -t ext4 -b 2048 -L 'MAN' -m 1 /dev/sda8 mke2fs 1.41.12 (17-May-2010) 文件系统标签=MAN 操作系统:Linux 块大小=2048 (log=1) 分块大小=2048 (log=1) Stride=0 blocks, Stripe width=0 blocks 804864 inodes, 6438032 blocks 64380 blocks (1.00%) reserved for the super user 第一个数据块=0 Maximum filesystem blocks=544210944 393 block groups 16384 blocks per group, 16384 fragments per group 2048 inodes per group Superblock backups stored on blocks: 16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104, 2048000, 3981312, 5619712 正在写入inode表: 完成 Creating journal (32768 blocks): 完成 Writing superblocks and filesystem accounting information: 完成 This filesystem will be automatically checked every 30 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@centos6 ~]# mount /dev/sda8 /mnt [root@centos6 ~]# tune2fs -l /dev/sda8 tune2fs 1.41.12 (17-May-2010) Filesystem volume name: MAN Last mounted on: <not available> Filesystem UUID: 8528b2b5-4dc3-48c9-91f5-a0d096442b36 Filesystem magic number: 0xEF53 Filesystem revision #: 1 (dynamic) Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize Filesystem flags: signed_directory_hash Default mount options: (none) Filesystem state: clean Errors behavior: Continue Filesystem OS type: Linux Inode count: 804864 Block count: 6438032 Reserved block count: 64380 Free blocks: 6297100 Free inodes: 804853 First block: 0 Block size: 2048 Fragment size: 2048 Reserved GDT blocks: 512 Blocks per group: 16384 Fragments per group: 16384 Inodes per group: 2048 Inode blocks per group: 256 Flex block group size: 16 Filesystem created: Mon Aug 22 22:43:55 2016 Last mount time: Mon Aug 22 22:44:44 2016 Last write time: Mon Aug 22 22:44:44 2016 Mount count: 1 Maximum mount count: 30 Last checked: Mon Aug 22 22:43:55 2016 Check interval: 15552000 (6 months) Next check after: Sat Feb 18 22:43:55 2017 Lifetime writes: 262 MB Reserved blocks uid: 0 (user root) Reserved blocks gid: 0 (group root) First inode: 11 Inode size: 256 Required extra isize: 28 Desired extra isize: 28 Journal inode: 8 Default directory hash: half_md4 Directory Hash Seed: c5fdca9f-fd8e-4a75-8301-39a64f0e9f3c Journal backup: inode blocks [root@centos6 ~]# blkid /dev/sda8 /dev/sda8: LABEL="MAN" UUID="8528b2b5-4dc3-48c9-91f5-a0d096442b36" TYPE="ext4" [root@centos6 ~]# blkid -U "8528b2b5-4dc3-48c9-91f5-a0d096442b36" /dev/sda8 [root@centos6 ~]# blkid -L MAN /dev/sda8 [root@centos6 ~]# [root@centos6 ~]# e2label /dev/sda8 HUMAN [root@centos6 ~]# e2label /dev/sda8 HUMAN [root@centos6 ~]# tune2fs -L 'BABY' /dev/sda8 tune2fs 1.41.12 (17-May-2010) [root@centos6 ~]# tune2fs -o acl /dev/sda8 tune2fs 1.41.12 (17-May-2010) [root@centos6 ~]# tune2fs -l /dev/sda8 tune2fs 1.41.12 (17-May-2010) Filesystem volume name: BABY Last mounted on: <not available> Filesystem UUID: 8528b2b5-4dc3-48c9-91f5-a0d096442b36 Filesystem magic number: 0xEF53 Filesystem revision #: 1 (dynamic) Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize Filesystem flags: signed_directory_hash Default mount options: acl Filesystem state: clean Errors behavior: Continue Filesystem OS type: Linux Inode count: 804864 Block count: 6438032 Reserved block count: 64380 Free blocks: 6297100 Free inodes: 804853 First block: 0 Block size: 2048 Fragment size: 2048 Reserved GDT blocks: 512 Blocks per group: 16384 Fragments per group: 16384 Inodes per group: 2048 Inode blocks per group: 256 Flex block group size: 16 Filesystem created: Mon Aug 22 22:43:55 2016 Last mount time: Mon Aug 22 22:44:44 2016 Last write time: Mon Aug 22 23:01:13 2016 Mount count: 1 Maximum mount count: 30 Last checked: Mon Aug 22 22:43:55 2016 Check interval: 15552000 (6 months) Next check after: Sat Feb 18 22:43:55 2017 Lifetime writes: 262 MB Reserved blocks uid: 0 (user root) Reserved blocks gid: 0 (group root) First inode: 11 Inode size: 256 Required extra isize: 28 Desired extra isize: 28 Journal inode: 8 Default directory hash: half_md4 Directory Hash Seed: c5fdca9f-fd8e-4a75-8301-39a64f0e9f3c Journal backup: inode blocks [root@centos6 ~]# tune2fs -m 5 /dev/sda8 tune2fs 1.41.12 (17-May-2010) Setting reserved blocks percentage to 5% (321901 blocks) [root@centos6 ~]# tune2fs -l /dev/sda8
………………………………………………………………………………………………
三、挂载文件系统
mount命令:
用法:
mount DEVICE MOUNT_POINT
mount [-fnrsvw] [-t vfstype] [-o options] device dir
挂载方式:
1)设备文件 例如:mount /dev/sda5 /mnt
2)卷标 例如:mount -L 'MYDATE' /mnt
3)UUID 例如:mount -U '40d51666-7a52-4613-bac9-0a1f27afeee8'/mnt
选项:
-t:指定文件类型
-r:只读挂载
-w:读写挂载
-n:不更新/etc/mtab
-a:自定挂载/etc/fstab定义的设备
-L:卷标
-U:uuid
-B:绑定目录到另一个目录上
查看内核最终到的挂载的所有设备:cat /proc/mounts
-o options:(挂载文件系统的选项),多个选项使用逗号分隔 async:异步模式 sync:同步模式,内存更改时,同时写磁盘 atime/noatime:包含目录和文件 diratime/nodiratime:目录的访问时间戳 auto/noauto:是否支持自动挂载,是否支持-a选项 exec/noexec:是否支持将文件系统上运行应用程序 dev/nodev:是否支持在此文件系统上使用设备文件 suid/nosuid:不否支持suid和sgid权限 remount:重新挂载 ro:只读 rw:读写 user/nouser:是否允许普通用户挂载此设备,默认管理员才能挂载 acl:启用此文件系统上的acl功能 Defaults:相当于rw, nosuid, dev, exec, auto, nouser, async
umount命令:
umount DEVICE
umount MOUNT_POINT
………………………………………………………………………………………………
四、挂载至配置文件
/etc/fstab 每行定义一个要挂载的文件系统说明
[root@centos6 ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Thu Aug 11 03:07:57 2016 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=240533cf-b37f-4460-974f-702bab867da5 / ext4 defaults 1 1 UUID=4e245c68-a392-4ce9-9a99-5d32d8d43872 /boot ext4 defaults 1 2 UUID=86aa7b74-24df-4043-ba83-f3b41a99ce0e /testdir ext4 defaults 1 2 UUID=f8ef48ef-b141-48e5-9735-ff9089bd54ba swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 #要挂载的设备或为文件系统 #挂载点 #文件类型 #选项 #转储 #自检 [root@centos6 ~
………………………………………………………………………………………………
本文出自小耳朵,小编乏了,洪荒之力已用完,觉得文章还可以记得点赞哦:)!!!
原创文章,作者:alren,如若转载,请注明出处:http://www.178linux.com/40656