云服务器挂载数据盘

云服务器(ECS)是一种简单高效、安全可靠、处理能力可弹性伸缩的计算服务。目前,大部分云服务器购买的数据盘需要自行挂载,以阿里云为例,挂载数据盘的步骤为:

[root@appblog.cn ~]# df -hT  //查看分区格式及空间使用信息(-h空间使用-T分区格式)
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/xvda1     ext4    20G  2.8G   16G  15% /  //只有系统盘,数据盘还未挂载
tmpfs          tmpfs  498M     0  498M   0% /dev/shm
[root@appblog.cn ~]# fdisk -l  //查看磁盘信息

Disk /dev/xvda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00078f9c

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1        2611    20970496   83  Linux

Disk /dev/xvdb: 21.5 GB, 21474836480 bytes  //可以看到分配有数据盘
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

[root@appblog.cn ~]# fdisk /dev/xvdb  //分区
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x41e88dbf.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n  //输入n
Command action
   e   extended
   p   primary partition (1-4)
p  //输入p
Partition number (1-4): 1  //输入1
First cylinder (1-2610, default 1):   //回车
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):   //回车
Using default value 2610

Command (m for help): wq  //执行
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@appblog.cn ~]# fdisk -l  //重新查看磁盘信息

Disk /dev/xvda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00078f9c

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1        2611    20970496   83  Linux

Disk /dev/xvdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x41e88dbf

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1        2610    20964793+  83  Linux  //可以看到创建新分区/dev/xvdb1
[root@appblog.cn ~]# mkfs.ext4 /dev/xvdb1  //格式化
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5241198 blocks
262059 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
160 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

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@appblog.cn ~]# mkdir /data  //创建分区挂载目录
[root@appblog.cn ~]# echo '/dev/xvdb1 /data ext4 defaults 0 0' >> /etc/fstab  //设置系统启动挂载新分区
[root@appblog.cn ~]# cat /etc/fstab  //查看启动挂载分区信息

#
# /etc/fstab
# Created by anaconda on Thu Aug 14 21:16:42 2014
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=94e4e384-0ace-437f-bc96-057dd64f42ee / ext4 defaults,barrier=0 1 1
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
none                  /proc/xen               xenfs   defaults        0 0
/dev/xvdb1 /data ext4 defaults 0 0  //可以看到新添加的新分区
[root@appblog.cn ~]# mount -a  //挂载所有分区
[root@appblog.cn ~]# df -hT  //重新查看分区格式及空间使用情况
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/xvda1     ext4    20G  2.8G   16G  15% /
tmpfs          tmpfs  498M     0  498M   0% /dev/shm
/dev/xvdb1     ext4    20G  172M   19G   1% /data
[root@appblog.cn ~]# 

版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/02/26/cloud-server-mount-data-disk/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
云服务器挂载数据盘
云服务器(ECS)是一种简单高效、安全可靠、处理能力可弹性伸缩的计算服务。目前,大部分云服务器购买的数据盘需要自行挂载,以阿里云为例,挂载数据盘的步骤……
<<上一篇
下一篇>>
文章目录
关闭
目 录