Centos7 挂载新硬盘(SSD|M.2)的操作方法

常用命令
df -h					# 列出所有已挂载磁盘
fdisk -l				# 查看磁盘情况
fdisk /dev/xxx			# 格式化命令
mkfs.ext4 /dev/xxx		# 创建分区
实例1:挂载一块新的 2T SSD3.0 硬盘
  • 查看磁盘情况

    $ sudo fdisk -l
    Disk /dev/loop0: 154 MiB, 161472512 bytes, 315376 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/sda: 447.1 GiB, 480103981056 bytes, 937703088 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
    Disklabel type: dos
    Disk identifier: 0x9cdcecb0
    
    Device     Boot     Start       End   Sectors   Size Id Type
    /dev/sda1  *         2048 870733823 870731776 415.2G 83 Linux
    /dev/sda2       870735870 937701375  66965506    32G  5 Extended
    /dev/sda5       870735872 937701375  66965504    32G 82 Linux swap / Solaris
    
    Disk /dev/sdb: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes
    ......
    
  • 确认新硬盘的名称(/dev/sdb

  • 格式化(/dev/sdb)

    $ sudo fdisk /dev/sdb
    Welcome to fdisk (util-linux 2.27.1).
    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.
    Created a new DOS disklabel with disk identifier 0xcc220bb9.
    
    Command (m for help): n
    Partition type
       p   primary (0 primary, 0 extended, 4 free)
       e   extended (container for logical partitions)
    Select (default p): p
    Partition number (1-4, default 1): 1
    First sector (2048-3907029167, default 2048):
    Last sector, +sectors or +size{K,M,G,T,P} (2048-3907029167, default 3907029167):
    
    Created a new partition 1 of type 'Linux' and of size 1.8 TiB.
    
    Command (m for help): w
    The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Syncing disks.
    

    依次输入n,p,1,w,其中 n 表示创建一个新分区,p表示分区类型为主分区,1表示分区编号是1,w 表示保存。

  • 创建分区(sdb + 分区编号)

    $ sudo mkfs.ext4 /dev/sdb1
    mke2fs 1.42.13 (17-May-2015)
    Discarding device blocks: done                            
    Creating filesystem with 488378390 4k blocks and 122101760 inodes
    Filesystem UUID: 9b9f1658-673e-4970-8cd0-9d1ccf33aede
    Superblock backups stored on blocks:
    	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
    	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
    	102400000, 214990848
    
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done  
    
  • 创建挂载目录

    $ mkdir -p /test 
    
  • 挂载硬盘至 “/test”

    $ sudo vi /etc/fstab
    .....
    # 在最后一行中加入,"/test"分区目录, "ext4"磁盘格式
    /dev/sdb1 /test ext4 defaults 0 0   
    
  • 重启电脑

    sudo reboot
    
  • 查看是否成功

    $ df -h
    Filesystem           Size  Used Avail Use% Mounted on
    udev                  16G     0   16G   0% /dev
    tmpfs                3.2G   11M  3.2G   1% /run
    /dev/sda1            409G   15G  374G   4% /
    tmpfs                 16G  238M   16G   2% /dev/shm
    tmpfs                5.0M  4.0K  5.0M   1% /run/lock
    tmpfs                 16G     0   16G   0% /sys/fs/cgroup
    tmpfs                3.2G   72K  3.2G   1% /run/user/1000
    /home/test/.Private  409G   15G  374G   4% /home/test
    /dev/sdb1            1.8T   68M  1.7T   1% /test
    
实例2:挂载一块新的 1T 长江存储 M.2 硬盘
  • 查看磁盘情况

    $ sudo fdisk -l
    ......
    磁盘 /dev/nvme0n1:1024.2 GB, 1024209543168 字节,2000409264 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节
    ......
    
  • 格式化(/dev/nvme0n1)

    $ sudo fdisk /dev/nvme0n1
    Welcome to fdisk (util-linux 2.27.1).
    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.
    Created a new DOS disklabel with disk identifier 0xcc220bb9.
    
    Command (m for help): n
    Partition type
       p   primary (0 primary, 0 extended, 4 free)
       e   extended (container for logical partitions)
    Select (default p): p
    Partition number (1-4, default 1): 1
    First sector (2048-2000409263, default 2048):
    Last sector, +sectors or +size{K,M,G,T,P} (2048-2000409263, default 2000409263):
    
    Created a new partition 1 of type 'Linux' and of size 953.9 GiB.
    
    Command (m for help): w
    The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Syncing disks.
    
  • 创建分区(nvme0n1 + p1)

    $ sudo mkfs.ext4 /dev/nvme0n1p1
    
  • 创建挂载目录

    $ mkdir -p /data-test 
    
  • 挂载硬盘至 “/data-test”

    $ sudo vi /etc/fstab
    .....
    # 在最后一行中加入
    /dev/nvme0n1p1 /data-test ext4 defaults 0 0   
    
  • 重启电脑

    sudo reboot
    
  • 查看是否成功

    $ df -h
    Filesystem           Size  Used Avail Use% Mounted on
    udev                  16G     0   16G   0% /dev
    tmpfs                3.2G   11M  3.2G   1% /run
    /dev/sda1            409G   15G  374G   4% /
    tmpfs                 16G  238M   16G   2% /dev/shm
    tmpfs                5.0M  4.0K  5.0M   1% /run/lock
    tmpfs                 16G     0   16G   0% /sys/fs/cgroup
    tmpfs                3.2G   72K  3.2G   1% /run/user/1000
    /home/test/.Private  409G   15G  374G   4% /home/test
    /dev/nvme0n1p1       939G   77M  891G   1% /data-test
    
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值