最新公告
  • 欢迎您光临仿站吧 帝国CMS模板一站式建站供应平台 . 欢迎加入VIP
  • CentOS磁盘挂载教程

    正文概述 仿站吧   2022-03-23 13:17:21  

    查看磁盘情况

    通过df命令可以查看当前已挂载的磁盘信息

    [root@iZ2ze5x5mt3210wm46kjgwZ ~]# df -h
    Filesystem      Size  Used Avail Use% Mounted on
    devtmpfs        3.8G     0  3.8G   0% /dev
    tmpfs           3.8G     0  3.8G   0% /dev/shm
    tmpfs           3.8G  500K  3.8G   1% /run
    tmpfs           3.8G     0  3.8G   0% /sys/fs/cgroup
    /dev/vda1        40G  2.4G   36G   7% /
    tmpfs           768M     0  768M   0% /run/user/0

    通过上面的信息可以看出,目前只挂载的系统盘。 

    查看当前磁盘的分区情况


    [root@iZ2ze5x5mt3210wm46kjgwZ ~]# fdisk -l
     
    Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x000bf3aa
       Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *        2048    83886046    41941999+  83  Linux
     
    Disk /dev/vdb: 268.4 GB, 268435456000 bytes, 524288000 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 /dev/vdc: 268.4 GB, 268435456000 bytes, 524288000 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

    通过以上信息可以看出系统中一共有三个磁盘/dev/vda、/dev/vdb、/dev/vdc分别为42G,268G、268G,跟当初购买的磁盘大小有差距。

    新增磁盘挂载

    通过上一步我们知道了每个磁盘的名称,现在对硬盘进行分区(如果是挂载一整块磁盘,可省略本步骤),分区的步骤如下:

                fdisk /dev/vdb(/dev/vdb为上一步中查询到的磁盘名称)
                输入参数 m  (显示帮助可不输入)
                输入参数n  (新建分区)
                输入参数e  (extended扩展分区,p  primary 主分区)
                输入参数1   (1-4  1表示只分一个区)
                enter键跳过
                enter键跳过(表示全部,也可输入起柱面cylinder号来完成分区,该号不能大于磁盘末尾号)
                输入参数w   (保存)
     
    [root@iZ2ze5x5mt3210wm46kjgwZ ~]# fdisk /dev/vdb
     
    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 0xbacfd979.
     
     
     
    Command (m for help): m
     
    Command action
     
       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)
    Command (m for help): n
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       e   extended
    Select (default p): e
    Partition number (1-4, default 1): 1
    First sector (2048-524287999, default 2048):
    Using default value 2048
    Last sector, +sectors or +size{K,M,G} (2048-524287999, default 524287999):
    Using default value 524287999
    Partition 1 of type Extended and of size 250 GiB is set
    Command (m for help): w
    The partition table has been altered!
    Calling ioctl() to re-read partition table.
    Syncing disks.

     

    格式化磁盘

    使用mkfs.ext4 /dev/vdb格式化磁盘:


    [root@iZ2ze5x5mt3210wm46kjgwZ mnt]# mkfs.ext4 /dev/vdb
     
    mke2fs 1.42.9 (28-Dec-2013)
     
    Filesystem label=
     
    OS type: Linux
     
    Block size=4096 (log=2)
     
    Fragment size=4096 (log=2)
     
    Stride=0 blocks, Stripe width=0 blocks
     
    16384000 inodes, 65536000 blocks
     
    3276800 blocks (5.00%) reserved for the super user
     
    First data block=0
     
    Maximum filesystem blocks=2214592512
     
    2000 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, 2654208,
     
            4096000, 7962624, 11239424, 20480000, 23887872
     
     
     
    Allocating group tables: done                            
     
    Writing inode tables: done                            
     
    Creating journal (32768 blocks): done
     
    Writing superblocks and filesystem accounting information: done    

    挂载磁盘

    挂载前需要创建挂载点,就是一个文件夹,然后使用命令mount把磁盘挂载到这个文件夹中


    [root@iZ2ze5x5mt3210wm46kjgwZ ~]# cd /mnt
     
    [root@iZ2ze5x5mt3210wm46kjgwZ mnt]# ll
     
    total 0
     
    [root@iZ2ze5x5mt3210wm46kjgwZ mnt]# mkdir software
     
    [root@iZ2ze5x5mt3210wm46kjgwZ mnt]# mount /dev/vdb /mnt/software

    查看是否成功
    df -h

    [root@iZ2ze5x5mt3210wm46kjgwZ mnt]# df -h
     
    Filesystem      Size  Used Avail Use% Mounted on
     
    devtmpfs        3.8G     0  3.8G   0% /dev
     
    tmpfs           3.8G     0  3.8G   0% /dev/shm
     
    tmpfs           3.8G  476K  3.8G   1% /run
     
    tmpfs           3.8G     0  3.8G   0% /sys/fs/cgroup
     
    /dev/vda1        40G  2.0G   36G   6% /
     
    tmpfs           768M     0  768M   0% /run/user/0
     
    /dev/vdb        246G   61M  234G   1% /mnt/software

    从结果可以看出已经挂载成功,磁盘为/dev/vdb。这一步之后只是临时挂载,重启后,挂载点会消失,下面把挂载信息设为开机自动挂在。

    自动挂载

    使用UUID挂载 blkid 查看UUID

    使用vim删除/etc/ fstab中的挂载信息。

    真实的例子

    UUID=6e26ed03-df7d-47e7-9324-8408341aeacb /mnt/software ext4    defaults        0 0

    <fs spec> <fs file> <fs vfstype> <fs mntops> <fs freq> <fs passno>
    具体说明,以挂载/dev/sdb1为例:
    <fs spec>:分区定位,可以给UUID或LABEL,例如:UUID=6E9ADAC29ADA85CD或LABEL=software
    <fs file>:具体挂载点的位置,例如:/data
    <fs vfstype>:挂载磁盘类型,linux分区一般为ext4,windows分区一般为ntfs
    <fs mntops>:挂载参数,一般为defaults
    <fs freq>:磁盘检查,默认为0
    <fs passno>:磁盘检查,默认为0,不需要检查
    自动挂载/etc/fstab里面的东西

     

    修改完/etc/fstab文件后,运行

    sudo mount -a

    重启系统
    仿站吧,一个优质的源码资源平台!
    仿站吧 » CentOS磁盘挂载教程