azure linux 挂载磁盘,如何给Azure云服务器扩展云磁盘

bb2d1e0cd592577ad5043ffe8b9e92ed.png

本文介绍一下如何给 Azure 的云服务器增加一块磁盘。

页面操作

首先切换到磁盘页面,然后点击添加数据磁盘按钮: 2018-08-02-16-42-27.jpg 然后选定存储容器,这里使用的是存储账户 Blob,然后点击确定按钮: 2018-08-02-16-43-38.jpg 主机缓存切换为“读/写”,然后点击保存: 2018-08-02-16-44-09.jpg 这样就添加好了。

挂载磁盘

接下来回到 Linux 服务器下,我们需要将磁盘进行挂载。 首先 SSH 连接到服务器,然后使用 dmesg 命令来查找磁盘:

1

dmesg | grep SCSI

输出类似如下:

1

2

3

4

5

6

[ 0.728389] SCSI subsystem initialized

[ 2.139341] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 244)

[ 2.978928] sd 1:0:1:0: [sdb] Attached SCSI disk

[ 3.341183] sd 0:0:0:0: [sda] Attached SCSI disk

[ 18.397942] Loading iSCSI transport class v2.0-870.

[ 6641.364794] sd 3:0:0:0: [sdc] Attached SCSI disk

这里 sdc 就是我们新添加的一块硬盘。 然后我们使用 fdisk 对其进行分区,将其设置为分区 1 中的主磁盘,并接受其他的默认值,命令如下:

1

sudo fdisk /dev/sdc

使用 n 命令添加新分区,然后 p 选择主分区,其他的默认:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

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 0xc305fe54.

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,default1):

First sector (2048-2145386495,default2048):

Last sector, +sectors or +size{K,M,G,T,P} (2048-2145386495,default2145386495):

Created a new partition 1 oftype'Linux' and of size 1023 GiB.

然后使用 p 打印分区表并使用 w 将表写入磁盘,然后退出:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

Command (m for help): p

Disk /dev/sdc: 1023 GiB, 1098437885952 bytes, 2145386496 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: 0xc305fe54

Device Boot Start End Sectors Size Id Type

/dev/sdc1 2048 2145386495 2145384448 1023G 83 Linux

Command (m for help): w

The partition table has been altered.

Calling ioctl() to re-read partition table.

Syncing disks.

接下来使用 mkfs 命令将文件系统写入分区,指定文件系统的类型和设备名称:

1

sudo mkfs -t ext4 /dev/sdc1

输出类似如下:

1

2

3

4

5

6

7

8

9

10

11

12

mke2fs 1.42.13 (17-May-2015)

Creating filesystem with 268173056 4k blocks and 67043328 inodes

Filesystem UUID: d744c5d7-f4d1-4f81-9f56-59dfab956782

Superblock backups stored on blocks:

32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,

102400000, 214990848

Allocating group tables: done

Writing inode tables: done

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done

然后使用 mkdir 创建一个目录来装载该文件系统,然后挂载:

1

2

sudo mkdir /datadrive

sudo mount /dev/sdc1 /datadrive

这样就挂载成功了。

添加引导信息

若要确保在重新引导后自动重新装载驱动器,必须将其添加到 /etc/fstab 文件。 此外,强烈建议在 /etc/fstab 中使用 UUID(全局唯一标识符)来引用驱动器而不是只使用设备名称(例如 /dev/sdc1)。 如果 OS 在启动过程中检测到磁盘错误,使用 UUID 可以避免将错误的磁盘装载到给定位置。 然后,为剩余的数据磁盘分配这些设备 ID。 若要查找新驱动器的 UUID,请使用 blkid 实用工具:

1

sudo -i blkid

输入类似如下:

1

2

3

/dev/sdb1: UUID="d5b61f40-4129-4b39-b861-c2d3b09cee69" TYPE="ext4" PARTUUID="4927b944-01"

/dev/sda1: LABEL="cloudimg-rootfs" UUID="b2e62f4f-d338-470e-9ae7-4fc0e014858c" TYPE="ext4" PARTUUID="577c3e7c-01"

/dev/sdc1: UUID="d744c5d7-f4d1-4f81-9f56-59dfab956782" TYPE="ext4" PARTUUID="c305fe54-01"

然后编辑 /etc/fstab,添加下面一行:

1

UUID=d744c5d7-f4d1-4f81-9f56-59dfab956782 /datadrive ext4 defaults,nofail 1 2

然后保存退出即可。 这样就成功添加了一块外部磁盘。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值