码迷,mamicode.com
首页 > 其他好文 > 详细

磁盘管理及文件系统管理

时间:2015-09-15 16:41:28      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:磁盘和文件系统管理

[root@localhost ~]# fdisk /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。


命令(输入 m 获取帮助):m
命令操作
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition‘s system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

命令(输入 m 获取帮助):p

磁盘 /dev/sda:128.8 GB, 128849018880 字节,251658240 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000b24e3

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    42969087    20971520   83  Linux
/dev/sda3        42969088    63940607    10485760   83  Linux
/dev/sda4        63940608   251658239    93858816    5  Extended
/dev/sda5        63942656    68136959     2097152   82  Linux swap / Solaris
/dev/sda6        68139008    89110527    10485760   83  Linux

命令(输入 m 获取帮助):n
All primary partitions are in use
添加逻辑分区 7
起始 扇区 (89112576-251658239,默认为 89112576):
将使用默认值 89112576
Last 扇区, +扇区 or +size{K,M,G} (89112576-251658239,默认为 251658239):+10G  
分区 7 已设置为 Linux 类型,大小设为 10 GiB

命令(输入 m 获取帮助):W
The partition table has been altered!
正在同步磁盘。
[root@localhost ~]# partx /dev/sda          //刷新分区表
NR    START       END   SECTORS  SIZE NAME UUID
 1     2048   1026047   1024000  500M      
 2  1026048  42969087  41943040   20G      
 3 42969088  63940607  20971520   10G      
 4 63940608 251658239 187717632 89.5G      
 5 63942656  68136959   4194304    2G      
 6 68139008  89110527  20971520   10G      
 7 89112576 110084095  20971520   10G      
[root@localhost ~]# fdisk -l /dev/sda

磁盘 /dev/sda:128.8 GB, 128849018880 字节,251658240 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000b24e3

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    42969087    20971520   83  Linux
/dev/sda3        42969088    63940607    10485760   83  Linux
/dev/sda4        63940608   251658239    93858816    5  Extended
/dev/sda5        63942656    68136959     2097152   82  Linux swap / Solaris
/dev/sda6        68139008    89110527    10485760   83  Linux
/dev/sda7        89112576   110084095    10485760   83  Linux
[root@localhost ~]# mkfs.ext4 /dev/sda7     //格式化分区
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2151677952
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成 

[root@localhost ~]# mkdir /mydata                     //创建目录
[root@localhost ~]# vi /etc/fstab                //编辑/etc/fstab,使能开机自动挂载/mydata
[root@localhost ~]# blkid /dev/sda7               //查看/dev/sda7 uuid信息
/dev/sda7: UUID="bee9ad7a-7f48-4c23-bb61-ab34da08cf55" TYPE="ext4"

技术分享

将mydata 添加到fstab文件中,实现开机自动挂载

reboot重启后


技术分享



总结

fdisk工具的使用:
        最多支持在一块硬盘上的15个分区;

        分区管理子命令:
            p: 显示
            n: 创建
            d: 删除
            t: 修改分区ID
            l: 列出所有支持ID类型
            w: 保存退出
            q: 放弃修改并退出
            m: 获取帮助

命令(输入 m 获取帮助):m
命令操作
   a   toggle a bootable flag   
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition‘s system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)


        创建完成之后,查看内核是否已经识别新的分区:
            # cat /proc/partitions

[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   10485760 sda6
   8        7   10485760 sda7       \\新建立的分区
  11        0    4209664 sr0


            有三个命令可以让内核重读磁盘分区表:
                CentOS 5: partprobe [DEVICE]
                CentOS 6,7:
                    partx
                    kpartx

                partx命令:
                    partx DEVICE
                    partx -a DEVICE
                    partx -a -n M:N DEVICE
                        M
                        M:
                        :N

                kpartx命令:
                    kpartx -af DEVICE


Linux文件系统管理

    文件系统:
        Linux:ext2, ext3, ext4, reiserfs, xfs, btrfs, swap
        光盘:iso9660
        Windows: fat32(vfat), ntfs
        Unix: ffs, ufs, jfs, jfs2
        网络文件系统:nfs, cifs
        集群文件系统:ocfs2, gfs2
        分布式文件系统:ceph,
            moosefs, mogilefs, hdfs, gfs, glusterfs

        (1) 日志型文件系统
            非日志型文件系统:ext2
            日志型文件系统:ext3
        (2) swap:交换分区

    创建文件系统:
        在分区上执行格式化(高级格式化)
            要使用某种文件系统,满足两个条件:
                内核中:支持此种文件系统
                用户空间:有文件系统管理工具


        创建工具:mkfs (make filesystem)
            mkfs -t type DEVICE

     mkfs.type DEVICE

            ext系列文件系统的专用管理工具:
                mke2fs -t {ext2|ext3|ext4} DEVICE
                    -b BLOCK: 1024, 2048, 4096
                    -L ‘LABEL‘: 设定卷标

新建分区/dev/sda8 使用mke2fs工具进行格式化操作。

[root@localhost ~]# mke2fs -t ext4 /dev/sda8
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

             

            blkid命令:
                blkid DEVICE
                    LABEL, UUID, TYPE

使用blkid工具查看uuid

[root@localhost ~]# blkid /dev/sda8
/dev/sda8: UUID="9ec61cb9-4dee-45fa-8e5f-47afa551bc98" TYPE="ext4" 

文件系统属性查看及调整工具:
        e2label
            e2lable DEVICE [LABEL]

        tune2fs
            显示ext系列文件系统的属性,或调整其属性;

            -l:显示超级块中的信息;显示整个文件的属性及布局等相关信息;
            -L ‘LABEL‘:修改卷标;
            -m #: 调整预留给管理员的管理空间百分比;
            -j: ext2 --> ext3
            -O:文件系统属性的启动或关闭 
            -o:文件系统默认挂载选项的启用或关闭
            
      [root@localhost ~]# tune2fs -L ‘KFC210‘ /dev/sda8
tune2fs 1.42.9 (28-Dec-2013)
[root@localhost ~]# blkid /dev/sda8
/dev/sda8: LABEL="KFC210" UUID="9ec61cb9-4dee-45fa-8e5f-47afa551bc98" TYPE="ext4" 


        dumpe2fs:
            -h: 仅显示超级块信息;

    文件系统检测:
        fsck: Filesystem check
            fsck -t type
            fsck.type
                -a: 自动修复错误
                -r: 交互式修复错误
                -f: 强制检测

        e2fsck:ext系列文件系统专用的检测修复工具;
            -y: 自动回答为“yes”
            -f:force

文件系统的挂载和使用:
   
    将额外文件系统与根文件系统某现存的目录建立起关联关系,进而使得此目录做为其它文件系统访问入口的行为,称之为挂载;

    解除此关联关系的过程:卸载;

    挂载点:mount point, 设备挂载至目录;

        注意:挂载点在挂载在之后,其内部原有的文件会被暂时隐藏;建立使用空目录做为挂载点;

    挂载方法:
        mount:通过读取/etc/mtab文件来显示当前系统所有已经挂载的设备;
        mount -a:挂载/etc/fstab文件中的所有支持自动挂载的文件系统;
        mount [options] [-o options] DEVICE MOUNT_POINT
            [options]:命令选项
            [-o options]:挂载选项

            DEVICE: 要挂载的设备
                (1) 设备文件:/dev/sda5
                (2) 卷标:-L ‘LABEL‘
                (3) UUID:-U ‘UUID‘
                (4) 伪文件系统名称
            MOUNT_POINT: 挂载点

            常用选项:
                -t type:文件系统类型
                -r: 以“只读”方式挂载此文件系统
                -w: 以“读写”方式挂载此文件系统
                -n:每个文件系统在挂载时都会自动更新/etc/mtab文件,-n用于禁止此功能;
                    此时,如果想查看挂载的所有文件系统:cat /proc/mounts
                -a: 自动挂载所有支持自动挂载的设备;
                -B:绑定目录至另一个目录上;

            -o 挂载选项:
                async:异步模式
                sync: 同步模式
                atime/noatime:是否更新访问时间戳;
                diratime/nodiratime:是否更新目录的访问时间戳;
                auto/noauto: 是否允许此设备被自动挂载;
                exec/noexec:是否允许执行此文件系统上应用程序;
                dev/nodev:是否支持在此设备上使用设备文件;
                suid/nosuid:
                remount:重新挂载
                ro
                rw
                user/nouser: 是否允许普通挂载此设备;
                acl:是否支持此设备上使用facl;
                defaults:rw, suid, dev, exec, auto, nouser, and async

        umount:卸载命令
            # umount DEVICE
            # umount MOUNT_POINT

            查看正在访问指定挂载点的进程:
                # fuser -v MOUNT_POINT

            终止所有正在访问指定的挂载点的进程:
                # fuser -km MOUNT_POINT

磁盘管理及文件系统管理

标签:磁盘和文件系统管理

原文地址:http://blackhuuu.blog.51cto.com/372322/1694927

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!