Linux新增磁盘并挂载

作者: SevenLin1993 | 来源:发表于2019-10-16 19:23 被阅读0次

    技术公众号:Java In Mind(Java_In_Mind),欢迎关注!

    linux版本:CentOS Linux release 7.4.1708 (Core)

    1. 查看现有磁盘信息

      $ fdisk -l
      
      Disk /dev/vda: 214.7 GB, 214748364800 bytes, 419430400 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: 0x000c54a5
      
         Device Boot      Start         End      Blocks   Id  System
      /dev/vda1   *        2048   125829119    62913536   83  Linux
      
      Disk /dev/vdb: 161.1 GB, 161061273600 bytes, 314572800 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/vdb磁盘没有对应的设备信息,待挂载

    2. 使用fdisk对新磁盘进行分区划分

      Linux fdisk是一个创建和维护分区表的程序,它兼容DOS类型的分区表、BSD或者SUN类型的磁盘列表。

      $ 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 0xc78ef89d.
      
      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)
      
      
    3. 使用fdiskn指令新建分区,使用默认配置,使用w指令进行保存

      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-314572799, default 2048):
      Using default value 2048
      Last sector, +sectors or +size{K,M,G} (2048-314572799, default 314572799):
      Using default value 314572799
      Partition 1 of type Linux and of size 150 GiB is set
      
      Command (m for help): w
      The partition table has been altered!
      
      Calling ioctl() to re-read partition table.
      Syncing disks.
      
      
    4. 再次查看磁盘信息

      fdisk -l
      
      Disk /dev/vda: 214.7 GB, 214748364800 bytes, 419430400 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: 0x000c54a5
      
         Device Boot      Start         End      Blocks   Id  System
      /dev/vda1   *        2048   125829119    62913536   83  Linux
      
      Disk /dev/vdb: 161.1 GB, 161061273600 bytes, 314572800 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: 0xfd187af4
      
         Device Boot      Start         End      Blocks   Id  System
      /dev/vdb1            2048   314572799   157285376   83  Linux
      
      
    5. 使用mkfs命令在新磁盘上建立文件系统

      Linux mkfs命令用于在特定的分区上建立 linux 文件系统

      -t : 给定档案系统的型式,Linux 的预设值为 ext2

      -t : 给定档案系统的型式,Linux 的预设值为 ext2

      $ mkfs -t ext4 -c /dev/vdb1
      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
      9830400 inodes, 39321344 blocks
      1966067 blocks (5.00%) reserved for the super user
      First data block=0
      Maximum filesystem blocks=2187329536
      1200 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
      
      Checking for bad blocks (read-only test): done
      Allocating group tables: done
      Writing inode tables: done
      Creating journal (32768 blocks): done
      Writing superblocks and filesystem accounting information: done
      
    6. 挂载到指定目录

      $ mkdir /foo
      $ mount /dev/vdb1 /foo
      
      $ df -h
      Filesystem      Size  Used Avail Use% Mounted on
      /dev/vda1        60G  1.7G   59G   3% /
      devtmpfs        7.8G     0  7.8G   0% /dev
      tmpfs           7.8G     0  7.8G   0% /dev/shm
      tmpfs           7.8G  8.4M  7.8G   1% /run
      tmpfs           7.8G     0  7.8G   0% /sys/fs/cgroup
      tmpfs           1.6G     0  1.6G   0% /run/user/0
      /dev/vdb1       148G   61M  140G   1% /foo
      
      
    7. 使用parted + print list查看分区信息

      $ parted /dev/vdb1
      GNU Parted 3.1
      Using /dev/vdb1
      Welcome to GNU Parted! Type 'help' to view a list of commands.
      (parted) print list
      Model: Virtio Block Device (virtblk)
      Disk /dev/vdb1: 161GB
      Sector size (logical/physical): 512B/512B
      Partition Table: loop
      Disk Flags:
      
      Number  Start  End    Size   File system  Flags
       1      0.00B  161GB  161GB  ext4
      
      Model: Virtio Block Device (virtblk)
      Disk /dev/vda: 215GB
      Sector size (logical/physical): 512B/512B
      Partition Table: msdos
      Disk Flags:
      
      Number  Start   End     Size    Type     File system  Flags
       1      1049kB  64.4GB  64.4GB  primary  xfs          boot
      
      Model: Virtio Block Device (virtblk)
      Disk /dev/vdb: 161GB
      Sector size (logical/physical): 512B/512B
      Partition Table: msdos
      Disk Flags:
      
      Number  Start   End    Size   Type     File system  Flags
       1      1049kB  161GB  161GB  primary  ext4
      
    1. 配置自动挂载

      /etc/fstab文件: 当系统启动的时候,系统会自动地从这个文件读取信息,并且会自动将此文件中指定的文件系统挂载到指定的目录

      # vim /etc/fstab,新增如下内容
      /dev/vdb1                   /foo                    xfs     defaults        0 0
      

    参考

    相关文章

      网友评论

        本文标题:Linux新增磁盘并挂载

        本文链接:https://www.haomeiwen.com/subject/htgumctx.html