Linux磁盘挂载

root@instance-txphg7nh-2:~# 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: 0x46392edb

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


Disk /dev/vdb: 500 GiB, 536870912000 bytes, 1048576000 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
root@instance-txphg7nh-2:~# fdisk /dev/vdb  #进入磁盘

Welcome to fdisk (util-linux 2.31.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 0x89f6810c.

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  #各分区类型所对应的ID
   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


Command (m for help): p  #显示该磁盘下的当前分区信息
Disk /dev/vdb: 500 GiB, 536870912000 bytes, 1048576000 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: 0x89f6810c

Command (m for help): n  #添加一个分区
Partition type
   p   primary (0 primary, 0 extended, 4 free)  #输入p为创建逻辑分区
   e   extended (container for logical partitions)  #输入e为创建扩展分区
Select (default p): p
Partition number (1-4, default 1): 1  #划分逻辑分区
First sector (2048-1048575999, default 2048): 1048575999  #磁盘分区大小

Created a new partition 1 of type 'Linux' and of size 512 B.

Command (m for help): p  #显示该磁盘下的当前分区信息
Disk /dev/vdb: 500 GiB, 536870912000 bytes, 1048576000 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: 0x89f6810c

Device     Boot      Start        End Sectors  Size Id Type
/dev/vdb1       1048575999 1048575999       1  512B 83 Linux

Command (m for help): w  #保存退出
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

root@instance-txphg7nh-2:~# 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: 0x46392edb

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


Disk /dev/vdb: 500 GiB, 536870912000 bytes, 1048576000 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: 0x89f6810c

Device     Boot      Start        End Sectors  Size Id Type
/dev/vdb1       1048575999 1048575999       1  512B 83 Linux
root@instance-txphg7nh-2:~# mkfs.ext4 /dev/vdb  #格式化分区
mke2fs 1.44.1 (24-Mar-2018)
Found a dos partition table in /dev/vdb
Proceed anyway? (y,N) y
Creating filesystem with 131072000 4k blocks and 32768000 inodes
Filesystem UUID: bc440c38-2ac5-41e1-a532-79c9084dadb9
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
        102400000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done     

root@instance-txphg7nh-2:~# echo /dev/vdb【磁盘分区】 /data【挂载目录】 ext4【文件格式】 defaults 0 0 >> /etc/fstab  #写入新分区信息 开机自动挂载 =>  echo /dev/vdb /data ext4 defaults 0 0 >> /etc/fstab
root@instance-txphg7nh-2:~# cat /etc/fstab 
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/vda1 during installation
UUID=0dfa4835-38d0-426d-bbb9-2e0056aa6e34 /               ext4    errors=remount-ro 0       1
/dev/vdb /data ext4 defaults 0 0
root@instance-txphg7nh-2:~# mkdir /data  #挂载目录
root@instance-txphg7nh-2:~# mount /dev/vdb /data  #挂载磁盘
root@instance-txphg7nh-2:~# df -h  #查看磁盘信息
Filesystem      Size  Used Avail Use% Mounted on
udev            7.9G     0  7.9G   0% /dev
tmpfs           1.6G  3.3M  1.6G   1% /run
/dev/vda1        40G  2.5G   36G   7% /
tmpfs           7.9G     0  7.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           7.9G     0  7.9G   0% /sys/fs/cgroup
tmpfs           1.6G     0  1.6G   0% /run/user/0
/dev/vdb        492G   73M  467G   1% /data
root@instance-txphg7nh-2:~# 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值