阿里云挂载新磁盘

阿里云挂载新磁盘


偶然使用公司的服务器做压力测试,就在阿里云中看了服务器信息,发现在shell 中只能看见40G的硬盘,但是在阿里云网站中却显示还有一块200G的硬盘,那就是没有挂载,让那40G空间的磁盘承受了不该承受的压力


下面是挂载步骤,参考阿里云官方文档:分区格式化数据盘(Linux) (aliyun.com)

发现问题

Xshell 7 (Build 0096)
Copyright (c) 2020 NetSarang Computer, Inc. All rights reserved.

Type `help' to learn how to use Xshell prompt.
[C:\~]$ 

Connecting to 39.104.53.178:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Wed May  4 11:52:12 2022 from 111.194.44.180

Welcome to Alibaba Cloud Elastic Compute Service !
## 这里可以发现并没有显示 200G 的硬盘
[root@iZhp3h4x7t41yl0eevhf1dZ ~]# df -h 
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        7.8G     0  7.8G   0% /dev
tmpfs           7.8G     0  7.8G   0% /dev/shm
tmpfs           7.8G  572K  7.8G   1% /run
tmpfs           7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/vda1        40G   32G  5.9G  85% /
tmpfs           1.6G     0  1.6G   0% /run/user/0

步骤一 登录ECS实例并查看数据盘

## 但是直接查看分区信息是可以看见的
[root@iZhp3h4x7t41yl0eevhf1dZ ~]# fdisk -l

Disk /dev/vda: 42.9 GB, 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
Disk label type: dos
Disk identifier: 0x000b2d99

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    83875364    41936658+  83  Linux
## 它在这里
Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 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

后面有两个步骤二,针对不同的分区方式

步骤二:为数据盘创建GPT分区

## 安装个工具
[root@iZhp3h4x7t41yl0eevhf1dZ ~]# yum install -y parted
Loaded plugins: fastestmirror
Determining fastest mirrors
base                                                                                                                                                          | 3.6 kB  00:00:00     
epel                                                                                                                                                          | 4.7 kB  00:00:00     
extras                                                                                                                                                        | 2.9 kB  00:00:00     
updates                                                                                                                                                       | 2.9 kB  00:00:00     
(1/5): epel/x86_64/group_gz                                                                                                                                   |  96 kB  00:00:00     
(2/5): epel/x86_64/updateinfo                                                                                                                                 | 1.0 MB  00:00:00     
(3/5): epel/x86_64/primary_db                                                                                                                                 | 7.0 MB  00:00:00     
(4/5): extras/7/x86_64/primary_db                                                                                                                             | 246 kB  00:00:00     
(5/5): updates/7/x86_64/primary_db                                                                                                                            |  15 MB  00:00:00     
Package parted-3.1-32.el7.x86_64 already installed and latest version
Nothing to do
## 另一个工具
[root@iZhp3h4x7t41yl0eevhf1dZ ~]# yum install -y e2fsprogs
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Package e2fsprogs-1.42.9-19.el7.x86_64 already installed and latest version
Nothing to do
## 运行以下命令开始分区
[root@iZhp3h4x7t41yl0eevhf1dZ ~]# parted /dev/vdb
GNU Parted 3.1
Using /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)                                                                  
(parted)                                                                  
(parted)                                                                  
(parted) help                                                             
  align-check TYPE N                        check partition N for TYPE(min|opt) alignment
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a particular partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END
  
  resizepart NUMBER END                    resize partition NUMBER
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected device
  disk_toggle [FLAG]                       toggle the state of FLAG on selected device
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and copyright information of GNU Parted
## 运行以下命令,设置GPT分区格式
(parted) mklabel gpt                                                      
## 运行以下命令,划分一个主分区,并设置分区的开始位置和结束位置
(parted) mkpart primary 1 100%        
## 运行以下命令,检查分区是否对齐
(parted) align-check optimal 1                                            
1 aligned
## 运行以下命令,查看分区表
(parted) print                                                            
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 215GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End    Size   File system  Name     Flags
 1      1049kB  215GB  215GB               primary
 
## 运行以下命令,退出Parted工具
(parted) quit                                                             
Information: You may need to update /etc/fstab.

## 运行以下命令,使系统重读分区表
[root@iZhp3h4x7t41yl0eevhf1dZ ~]# partprobe   
## 运行以下命令,查看新分区信息 如果出现gpt的相关信息,表示新分区已创建完成
[root@iZhp3h4x7t41yl0eevhf1dZ ~]# fdisk -lu /dev/vdb
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 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
## 在这里(gpt)
Disk label type: gpt
Disk identifier: 426A3CC1-8187-4E3B-90FB-773832C38D5F

步骤二:为数据盘创建MBR分区

#         Start          End    Size  Type            Name
 1         2048    419428351    200G  Microsoft basic primary
 
## 运行以下命令对数据盘进行分区
[root@iZhp3h4x7t41yl0eevhf1dZ ~]# fdisk -u /dev/vdb
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

## 输入p查看数据盘的分区情况
Command (m for help): p

Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 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
Disk label type: gpt
Disk identifier: 426A3CC1-8187-4E3B-90FB-773832C38D5F


#         Start          End    Size  Type            Name
 1         2048    419428351    200G  Microsoft basic primary
 
## 输入n创建一个新分区。
Command (m for help): n
## 输入p选择分区类型为主分区
Partition number (2-128, default 2): p
First sector (34-419430366, default 419428352): 
Last sector, +sectors or +size{K,M,G,T,P} (419428352-419430366, default 419430366): 
Created partition 2

## 输入w开始分区,并在完成分区后退出
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
## 运行以下命令,查看新分区信息 如果出现/dev/vdb1的相关信息,表示新分区已创建完成
[root@iZhp3h4x7t41yl0eevhf1dZ ~]# fdisk -lu /dev/vdb
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 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
Disk label type: gpt
Disk identifier: 426A3CC1-8187-4E3B-90FB-773832C38D5F


#         Start          End    Size  Type            Name
 1         2048    419428351    200G  Microsoft basic primary
 2    419428352    419430366  1007.5K  Linux filesyste 

步骤三:为分区创建文件系统

## 运行以下命令,创建一个ext4文件系统,下面还有一个创建 xfs文件系统 的命令,选一个就行
[root@iZhp3h4x7t41yl0eevhf1dZ ~]# mkfs -t ext4 /dev/vdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
13107200 inodes, 52428288 blocks
2621414 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2199912448
1600 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, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done     
## 运行以下命令,创建一个xfs文件系统
[root@iZhp3h4x7t41yl0eevhf1dZ ~]# mkfs -t xfs /dev/vdb1
mkfs.xfs: /dev/vdb1 appears to contain an existing filesystem (ext4).
mkfs.xfs: Use the -f option to force overwrite.

步骤四:配置/etc/fstab文件并挂载分区

## 运行以下命令,备份/etc/fstab文件
[root@iZhp3h4x7t41yl0eevhf1dZ ~]# cp /etc/fstab /etc/fstab.bak
## 在/etc/fstab里写入新分区信息 如果您使用root用户,可以运行以下命令直接修改/etc/fstab文件
[root@iZhp3h4x7t41yl0eevhf1dZ ~]# echo `blkid /dev/vdb1 | awk '{print $2}' | sed 's/\"//g'` /mnt ext4 defaults 0 0 >> /etc/fstab
## 运行以下命令,查看/etc/fstab中的新分区信息
[root@iZhp3h4x7t41yl0eevhf1dZ ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Thu Jul 11 02:52:01 2019
#
# 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=1114fe9e-2309-4580-b183-d778e6d97397 /                       ext4    defaults        1 1
/home/swap swap swap defaults    0  0
UUID=25cf0120-fb93-462c-92f5-438ec41b0383 /mnt ext4 defaults 0 0
## 运行以下命令,挂载/etc/fstab配置的文件系统
[root@iZhp3h4x7t41yl0eevhf1dZ ~]# mount -a

步骤五:检查挂接结果

## 运行以下命令,检查挂载结果
[root@iZhp3h4x7t41yl0eevhf1dZ ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        7.8G     0  7.8G   0% /dev
tmpfs           7.8G     0  7.8G   0% /dev/shm
tmpfs           7.8G  616K  7.8G   1% /run
tmpfs           7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/vda1        40G   32G  5.9G  85% /
tmpfs           1.6G     0  1.6G   0% /run/user/0
/dev/vdb1       197G   61M  187G   1% /mnt  ## 在这里

你可能感兴趣的:(Linux,linux)