阿里云ECS分区格式化挂载数据盘

阿里云新买了一台ubuntu机器,并且新增了一块数据盘100G,需要手动去这台服务器上手动进行分区、格式化、挂载。

记录如下:

# 查看当前系统
root@iZmk5Z:~# cat /etc/issue
Ubuntu 16.04.6 LTS \n \l

# 查看磁盘分区,看到有一块100G的磁盘叫/dev/vdb
root@iZmk6Z:~# 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: 0xe2eb87fa

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


Disk /dev/vdb: 100 GiB, 107374182400 bytes, 209715200 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

# 对这块磁盘进行分区。没有特殊需求,直接按n,p,然后一路回车即可。最后按w保存退出
root@iZmk6Z:~# 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 0x4cf483d3.

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): 
First sector (2048-209715199, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-209715199, default 209715199): 

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

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

# 再次查看发现有一块磁盘已经是/dev/vdb1了
root@iZmk6Z:~# 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: 0xe2eb87fa

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


Disk /dev/vdb: 100 GiB, 107374182400 bytes, 209715200 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: 0x4cf483d3

Device Boot Start End Sectors Size Id Type
/dev/vdb1 2048 209715199 209713152 100G 83 Linux

# 对/dev/vdb1这块磁盘进行格式化,格式为ext4
root@iZmk6Z:~# mkfs.ext4 /dev/vdb1
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 26214144 4k blocks and 6553600 inodes
Filesystem UUID: 6d4d58f7-ca0c-4740-ba15-71a95f76116b
Superblock backups stored on blocks: 
 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
 4096000, 7962624, 11239424, 20480000, 23887872

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

# 创建一个/data目录用于后面挂载这块新增的/dev/vdb1磁盘
root@iZmk6Z:~# mkdir /data

# 执行挂载操作并查看是否成功挂载,看到如下红色的地方表示已经成功挂载上
root@iZmk6Z:~# mount /dev/vdb1 /data/
root@iZmk6Z:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 2.0G 0 2.0G 0% /dev
tmpfs 396M 2.8M 393M 1% /run
/dev/vda1 40G 1.9G 36G 6% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
tmpfs 396M 0 396M 0% /run/user/0
/dev/vdb1 99G 60M 94G 1% /data

# ubuntu下执行让他开机自动挂载磁盘
root@iZmk6Z:~# echo "/dev/vdb1 /data ext4 errors=remount-ro 0 0" >>/etc/fstab

注意:这里有一个坑点。ubuntu和centos系统不同。在进行自动挂载的时候,ubuntu是errors=remount-ro,而centos是defaults。如果这里设置错了,则服务器下次重启的时候会卡住,无法正常重启。解决方法为进入阿里云控制台,找到这台机器进入后台,然后将自动挂载这行注释掉,再次reboot。

磁盘配置LVM链接:https://www.ayunw.cn/archives/210

版权声明:
作者:allenjol
链接:https://www.ayunw.cn/archives/440
来源:爱生活,爱运维
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>