linux添加硬盘并挂载

添加硬盘

查看磁盘信息

# fdisk -l
.........
Disk /dev/vda: 40 GiB, 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
Disklabel type: dos
Disk identifier: 0xcd5caf0d

Device     Boot Start      End  Sectors Size Id Type
/dev/vda1  *     2048 83886079 83884032  40G 83 Linux

Disk /dev/vdb: 2 TiB, 2147483648000 bytes, 4194304000 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: 0xfdcbfa49

/dev/vda这块磁盘有40G,只有1个分区/dev/vda1
如果有一块磁盘没有分区信息,说明这块磁盘还没有使用,如/dve/vdb

磁盘分区初始化

# fdisk /dev/vdb

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.


Command (m for help): m                     //查看具体命令参数

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition                                       //新建一个分区
   p   print the partition table                                  //打印分区列表
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit                    //退出并保存磁盘分割属性
   q   quit without saving changes                  //直接退出不保存

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table

输入参数n新建磁盘分区,并根据提示进行操作,磁盘分区属性设置完成后w写入磁盘分区表并保存退出。保存后再次查看磁盘信息,确保分区创建成功

# fdisk -l
Disk /dev/vdb: 2 TiB, 2147483648000 bytes, 4194304000 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: 0xfdcbfa49

Device     Boot Start        End    Sectors Size Id Type
/dev/vdb1        2048 4194303999 4194301952   2T 83 Linux

指定分区文件系统

文件系统:ext2,ext3,ext4
mke2fs /dev/vdb1 #创建ext2文件系统,默认是ext2
mke2fs -j /dev/vdb1 #创建ext3文件系统
mke2fs -t ext4 /dev/vdb1 #创建ext4文件系统

挂载

# mkdir /export
# vim /etc/fstab   永久性挂载
/dev/vdb1 /export ext4 defaults 1 1
# mount /export

mount成功后查看磁盘使用情况

# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev             16G     0   16G   0% /dev
tmpfs           3.2G  343M  2.9G  11% /run
/dev/vda1        40G  9.3G   29G  25% /
tmpfs            16G   16K   16G   1% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            16G     0   16G   0% /sys/fs/cgroup
/dev/vdb1       2.0T  0  2.0T  0% /export

卸载

# unmount /export
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值