阿里云磁盘扩展操作笔记
2019-11-10 本文已影响0人
do_young
磁盘扩展
查看磁盘
现有一个300GB的磁盘设备/dev/vda,有一个主分区并挂载于/dev/vda1下。
[root@kubernetes ~]# fdisk -l /dev/vda
Disk /dev/vda: 322.1 GB, 322122547200 bytes, 629145600 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: 0x0008d73a
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 209713151 104855552 83 Linux
查看分区所占存储大小
可以看到主分区分配了100G的磁盘空间
[root@kubernetes ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 99G 60G 34G 64% /
还有200GB的存储空间实际上是新增的存储,还没有分配使用。
查看文件系统类型
查看一下该分区所使用的文件系统类型,这里实际是使用的ext4。
[root@kubernetes rpms]# blkid /dev/vda1
/dev/vda1: UUID="eb448abb-3012-4d8d-bcde-94434d586a31" TYPE="ext4"
创建新分区及分配存储空间
[root@kubernetes ~]# fdisk -u /dev/vda
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.
Command (m for help): p
Disk /dev/vda: 322.1 GB, 322122547200 bytes, 629145600 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: 0x0008d73a
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 209713151 104855552 83 Linux
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (209713152-629145599, default 209713152):
Using default value 209713152
Last sector, +sectors or +size{K,M,G} (209713152-629145599, default 629145599):
Using default value 629145599
Partition 2 of type Linux and of size 200 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
其中有一段WARNING
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
可以使用partprobe指令处理,具体详情可以考虑该文档
查看新分区情况
lsblk /dev/vda
通过该指令将看到新的分区/dev/vda2.
格式化新的分区
使用mkfs.ext4指令创建ext4文件系统:
[root@kubernetes ~]# mkfs.ext4 /dev/vda2
mke2fs 1.42.9 (28-Dec-2013)
warning: 256 blocks unused.
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
13132800 inodes, 52428800 blocks
2621439 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
8208 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
查看新分区的详情
[root@kubernetes ~]# blkid /dev/vda2
/dev/vda2: UUID="f7f6ca5e-7271-yyyy-xxxx-c746164ad124" TYPE="ext4"
将新分区挂载到文件系统指定路径
运行mount /dev/vda2 /mnt挂载文件系统。
[root@kubernetes ~]# mount /dev/vda2 /mnt
查看磁盘使用情况
[root@kubernetes ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 99G 83G 11G 89% /
/dev/vda1 99G 83G 11G 89% /
/dev/vda2 197G 61M 187G 1% /mnt
//TODO
系统启动自动挂载新分区
5.设置开机自动挂载,打开自动挂载文件:vi /etc/fstab,加入如下图所示内容行:
image保存退出,重启主机看下是否自动挂载:df -lh
image