centos挂载硬盘,Ubuntu挂载硬盘通用。

1.查看磁盘信息: fdisk -l

root@Block-Data001:/# 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: 0x77ba45a4

Device     Boot Start      End  Sectors Size Id Type
/dev/vda1  *     2048 83884031 83881984  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

找到我们准备挂载的500G的硬盘的名字:/dev/vdb

2.创建硬盘分区: 

root@Block-Data001:/# 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.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x2bb51603.

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


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: 0x2bb51603

Command (m for help): n # 创建新的分区
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): # 直接回车

Using default response p.
Partition number (1-4, default 1):# 直接回车
First sector (2048-1048575999, default 2048):# 直接回车
Last sector, +sectors or +size{K,M,G,T,P} (2048-1048575999, default 1048575999):# 直接回车

Created a new partition 1 of type 'Linux' and of size 500 GiB.

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: 0x2bb51603

Device     Boot Start        End    Sectors  Size Id Type
/dev/vdb1        2048 1048575999 1048573952  500G 83 Linux

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

3.再次查看磁盘信息:fdisk -l

root@Block-Data001:/# 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: 0x77ba45a4

Device     Boot Start      End  Sectors Size Id Type
/dev/vda1  *     2048 83884031 83881984  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: 0x2bb51603

Device     Boot Start        End    Sectors  Size Id Type
/dev/vdb1        2048 1048575999 1048573952  500G 83 Linux

4.格式化新分区:mkfs.ext3 /dev/vdb1

root@Block-Data001:/# mkfs.ext3 /dev/vdb1
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 131071744 4k blocks and 32768000 inodes
Filesystem UUID: e947b3c8-a525-410b-b8af-055e29c821a6
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 (32768 blocks): done
Writing superblocks and filesystem accounting information: done

5.格式化完毕后,挂载分区

5.1.创建被挂载的路径,我挂载到/data:

mkdir /data/

5.2.进行挂载:

mount /dev/vdb1 /data/

5.3.查看挂载结果:df -lh

root@Block-Data001:/# df -lh
Filesystem      Size  Used Avail Use% Mounted on
udev            7.9G     0  7.9G   0% /dev
tmpfs           1.6G  3.2M  1.6G   1% /run
/dev/vda1        40G  2.7G   35G   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/vdb1       493G   70M  467G   1% /data

6.设置开机自动挂载:

编辑/etc/fstab文件,再最后面添加(复制过去就好,第一个第二个参数改成自己的):

/dev/vdb1       /data           ext3    defaults 0 0

7.重启机器:reboot

8.重启后查看挂载结果,依然存在,至此,挂载完成:

root@Block-Data001:~# df -lh
Filesystem      Size  Used Avail Use% Mounted on
udev            7.9G     0  7.9G   0% /dev
tmpfs           1.6G  3.2M  1.6G   1% /run
/dev/vda1        40G  2.6G   35G   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
/dev/vdb1       493G   70M  467G   1% /data
tmpfs           1.6G     0  1.6G   0% /run/user/0

 

Logo

更多推荐