ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Linux day12

2021-12-22 21:33:00  阅读:183  来源: 互联网

标签:512 bytes dev day12 Linux fdisk 磁盘分区 root


查询磁盘信息

  定义:Linux系统中磁盘管理就是将硬盘通过挂载的方式挂载到linux文件系统中

        1.使用df命令查看磁盘容量,不加参数则以k为单位
            1.df -i  查看inode的使用情况
            2.df -h  以G或T或M的人性化方式显示
            3.df -T  查看磁盘分区类型(文件系统类型)

            使用df -h 命令查看磁盘,下面分别介绍每列什么含义
            [root@JYC ~]# df -h
            Filesystem               Size  Used Avail Use% Mounted on
            devtmpfs                 475M     0  475M   0% /dev
            tmpfs                    487M     0  487M   0% /dev/shm
            tmpfs                    487M  7.5M  479M   2% /run
            tmpfs                    487M     0  487M   0% /sys/fs/cgroup
            /dev/mapper/centos-root  100G  2.6G   97G   3% /
            /dev/sda1                509M  131M  378M  26% /boot
            tmpfs                     98M     0   98M   0% /run/user/0

        2.使用lsblk查看磁盘分区情况
            1.[root@JYC ~]# lsblk
                NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
                sda               8:0    0  100G  0 disk 
                ├─sda1            8:1    0  512M  0 part /boot
                └─sda2            8:2    0 99.5G  0 part 
                  └─centos-root 253:0    0 99.5G  0 lvm  /
                sdb               8:16   0  100G  0 disk 
                sr0              11:0    1  4.4G  0 rom  

        3.使用du查看目录或者文件的容量,不加参数则以k为单位
            1.du -sh  人性化输出显示大小
            2.du -s   列出总和
            3.du -h   人性化显示容量信息
            [root@JYC ~]# du -sh /etc
            33M    /etc

        4.显示当前磁盘的读写速度
            1.iotop  显示磁盘的读写
            2.iotop -o 只显示在读写的进程
            3.dd if=/dev/zero of=/tmp/big bs=1k count=100000  该命令可用来测速

磁盘分区和挂载

        1.磁盘分区命令
            1.fdisk   支持mbr分区格式,2tb以内磁盘
            2.gdisk   支持mbr,gpt
            3.parted  fdisk升级版(仅支持gpt格式)

        2.fdisk
            1.参看磁盘分区信息
                fdisk -l

            2.用fdisk进行分区
                fdisk /dev/sdb
                [root@JYC ~]# 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.

                # 磁盘当前没有磁盘分区列表
                Device does not contain a recognized partition table
                Building a new DOS disklabel with disk identifier 0xbcb9ea13.
                Command (m for help):

                # 一些常用命令
                   n   new 创建磁盘分区 partition(分区)
                   p   print 显示分区信息
                   d   delete 删除磁盘分区
                   q   退出不保存
                   w   保存并退出

                # 创建一个磁盘分区
                Command (m for help): p
                Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
                Units = sectors of 1 * 512 = 512 bytes
                Sector size (logical/physical): 512 bytes / 512 bytes
                I/O size (minimum/optimal): 512 bytes / 512 bytes
                Disk label type: dos
                Disk identifier: 0xbcb9ea13

                   Device Boot      Start         End      Blocks   Id  System

                Command (m for help): n
                Partition type:
                   p   primary(主分区) (0 primary, 0 extended, 4 free)
                   e   extended(扩展分区)

                Select (default p): 
                Using default response p
                Partition number (1-4, default 1): 
                First sector (2048-209715199, default 2048): 
                Using default value 2048
                Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): +200M 
                Partition 1 of type Linux and of size 200 MiB is set

                Command (m for help): P
                Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
                Units = sectors of 1 * 512 = 512 bytes
                Sector size (logical/physical): 512 bytes / 512 bytes
                I/O size (minimum/optimal): 512 bytes / 512 bytes
                Disk label type: dos
                Disk identifier: 0xbcb9ea13

                   Device Boot      Start         End      Blocks   Id  System
                /dev/sdb1            2048      411647      204800   83  Linux

                Command (m for help): w  
                The partition table has been altered!
                Calling ioctl() to re-read partition table.
                Syncing disks.

        注:期间若有输入错误需要取消则 ctrl+u 

        3.格式化文件系统
            mkfs.xfs /dev/sdb1
            [root@JYC ~]# mkfs.xfs /dev/sdb1
            meta-data=/dev/sdb1              isize=512    agcount=4, agsize=12800 blks
                     =                       sectsz=512   attr=2, projid32bit=1
                     =                       crc=1        finobt=0, sparse=0
            data     =                       bsize=4096   blocks=51200, imaxpct=25
                     =                       sunit=0      swidth=0 blks
            naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
            log      =internal log           bsize=4096   blocks=855, version=2
                     =                       sectsz=512   sunit=0 blks, lazy-count=1
            realtime =none                   extsz=4096   blocks=0, rtextents=0

        4.挂载
            mount /dev/sdb1 /mnt
            [root@JYC ~]# mount /dev/sdb1 /mnt
            [root@JYC ~]# lsblk
            NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
            sda               8:0    0  100G  0 disk 
            ├─sda1            8:1    0  512M  0 part /boot
            └─sda2            8:2    0 99.5G  0 part 
              └─centos-root 253:0    0 99.5G  0 lvm  /
            sdb               8:16   0  100G  0 disk 
            └─sdb1            8:17   0  200M  0 part /mnt
            sr0              11:0    1  4.4G  0 rom  

查询磁盘信息

        定义:Linux系统中磁盘管理就是将硬盘通过挂载的方式挂载到linux文件系统中

        1.使用df命令查看磁盘容量,不加参数则以k为单位
            1.df -i  查看inode的使用情况
            2.df -h  以G或T或M的人性化方式显示
            3.df -T  查看磁盘分区类型(文件系统类型)

            使用df -h 命令查看磁盘,下面分别介绍每列什么含义
            [root@JYC ~]# df -h
            Filesystem               Size  Used Avail Use% Mounted on
            devtmpfs                 475M     0  475M   0% /dev
            tmpfs                    487M     0  487M   0% /dev/shm
            tmpfs                    487M  7.5M  479M   2% /run
            tmpfs                    487M     0  487M   0% /sys/fs/cgroup
            /dev/mapper/centos-root  100G  2.6G   97G   3% /
            /dev/sda1                509M  131M  378M  26% /boot
            tmpfs                     98M     0   98M   0% /run/user/0

        2.使用lsblk查看磁盘分区情况
            1.[root@JYC ~]# lsblk
                NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
                sda               8:0    0  100G  0 disk 
                ├─sda1            8:1    0  512M  0 part /boot
                └─sda2            8:2    0 99.5G  0 part 
                  └─centos-root 253:0    0 99.5G  0 lvm  /
                sdb               8:16   0  100G  0 disk 
                sr0              11:0    1  4.4G  0 rom  

        3.使用du查看目录或者文件的容量,不加参数则以k为单位
            1.du -sh  人性化输出显示大小
            2.du -s   列出总和
            3.du -h   人性化显示容量信息
            [root@JYC ~]# du -sh /etc
            33M	/etc

        4.显示当前磁盘的读写速度
            1.iotop  显示磁盘的读写
            2.iotop -o 只显示在读写的进程
            3.dd if=/dev/zero of=/tmp/big bs=1k count=100000  该命令可用来测速

image

磁盘分区和挂载

        1.磁盘分区命令
            1.fdisk   支持mbr分区格式,2tb以内磁盘
            2.gdisk   支持mbr,gpt
            3.parted  fdisk升级版(仅支持gpt格式)

        2.fdisk
            1.参看磁盘分区信息
                fdisk -l

            2.用fdisk进行分区
                fdisk /dev/sdb
                [root@JYC ~]# 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.

                # 磁盘当前没有磁盘分区列表
                Device does not contain a recognized partition table
                Building a new DOS disklabel with disk identifier 0xbcb9ea13.
                Command (m for help):

                # 一些常用命令
                   n   new 创建磁盘分区 partition(分区)
                   p   print 显示分区信息
                   d   delete 删除磁盘分区
                   q   退出不保存
                   w   保存并退出

                # 创建一个磁盘分区
                Command (m for help): p
                Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
                Units = sectors of 1 * 512 = 512 bytes
                Sector size (logical/physical): 512 bytes / 512 bytes
                I/O size (minimum/optimal): 512 bytes / 512 bytes
                Disk label type: dos
                Disk identifier: 0xbcb9ea13

                   Device Boot      Start         End      Blocks   Id  System

                Command (m for help): n
                Partition type:
                   p   primary(主分区) (0 primary, 0 extended, 4 free)
                   e   extended(扩展分区)

                Select (default p): 
                Using default response p
                Partition number (1-4, default 1): 
                First sector (2048-209715199, default 2048): 
                Using default value 2048
                Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): +200M 
                Partition 1 of type Linux and of size 200 MiB is set

                Command (m for help): P
                Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors
                Units = sectors of 1 * 512 = 512 bytes
                Sector size (logical/physical): 512 bytes / 512 bytes
                I/O size (minimum/optimal): 512 bytes / 512 bytes
                Disk label type: dos
                Disk identifier: 0xbcb9ea13

                   Device Boot      Start         End      Blocks   Id  System
                /dev/sdb1            2048      411647      204800   83  Linux

                Command (m for help): w  
                The partition table has been altered!
                Calling ioctl() to re-read partition table.
                Syncing disks.

        注:期间若有输入错误需要取消则 ctrl+u 

        3.格式化文件系统
            mkfs.xfs /dev/sdb1
            [root@JYC ~]# mkfs.xfs /dev/sdb1
            meta-data=/dev/sdb1              isize=512    agcount=4, agsize=12800 blks
                     =                       sectsz=512   attr=2, projid32bit=1
                     =                       crc=1        finobt=0, sparse=0
            data     =                       bsize=4096   blocks=51200, imaxpct=25
                     =                       sunit=0      swidth=0 blks
            naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
            log      =internal log           bsize=4096   blocks=855, version=2
                     =                       sectsz=512   sunit=0 blks, lazy-count=1
            realtime =none                   extsz=4096   blocks=0, rtextents=0

        4.挂载
            mount /dev/sdb1 /mnt
            [root@JYC ~]# mount /dev/sdb1 /mnt
            [root@JYC ~]# lsblk
            NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
            sda               8:0    0  100G  0 disk 
            ├─sda1            8:1    0  512M  0 part /boot
            └─sda2            8:2    0 99.5G  0 part 
              └─centos-root 253:0    0 99.5G  0 lvm  /
            sdb               8:16   0  100G  0 disk 
            └─sdb1            8:17   0  200M  0 part /mnt
            sr0              11:0    1  4.4G  0 rom  

标签:512,bytes,dev,day12,Linux,fdisk,磁盘分区,root
来源: https://www.cnblogs.com/ice0/p/15721187.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有