vdb卷分区及扩容

记一些基础的东西:

1、volume attach instance后,进入instance进行分区格式化,第二块盘名字为vdb:

[root@test ~]# fdisk -l


Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x000b2270

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048   104856254    52427103+  83  Linux

Disk /dev/vdb: 107.4 GB, 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

开始分区:

[root@test ~]# fdisk /dev/vdb
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.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x7ecd0300.

Command (m for help): p

Disk /dev/vdb: 107.4 GB, 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
Disk label type: dos
Disk identifier: 0x7ecd0300

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-209715199, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199):
Using default value 209715199
Partition 1 of type Linux and of size 100 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

分区结束后,查看:

[root@test ~]# fdisk -l

Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x000b2270

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048   104856254    52427103+  83  Linux

Disk /dev/vdb: 107.4 GB, 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
Disk label type: dos
Disk identifier: 0x7ecd0300

   Device Boot      Start         End      Blocks   Id  System

/dev/vdb1            2048   209715199   104856576   83  Linux

如果不格式化,直接去挂载,报错:

[root@test ~]# mount /dev/vdb1 /mnt
mount: /dev/vdb1 is write-protected, mounting read-only
mount: unknown filesystem type '(null)'

格式化:

[root@test ~]# mkfs.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
6553600 inodes, 26214144 blocks
1310707 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2174746624
800 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 

挂载:

[root@test ~]# mount /dev/vdb1 /mnt

修改/etc/fstab:添加/dev/vdb1 /mnt ext4 defaults 0 0重启后自动挂载,永久生效

2、extend volume vdb后,重新attach:

[root@test ~]# fdisk -l

Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x000b2270

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048   104856254    52427103+  83  Linux

Disk /dev/vdb: 128.8 GB, 128849018880 bytes, 251658240 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: 0x7ecd0300

   Device Boot      Start         End      Blocks   Id  System

/dev/vdb1            2048   209715199   104856576   83  Linux

对vdb1进行扩容:

[root@test ~]# fdisk /dev/vdb
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/vdb: 128.8 GB, 128849018880 bytes, 251658240 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: 0x7ecd0300

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048   209715199   104856576   83  Linux

Command (m for help): d
Selected partition 1
Partition 1 is deleted

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-251658239, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-251658239, default 251658239):
Using default value 251658239
Partition 1 of type Linux and of size 120 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

检查分区完整性:

[root@test ~]# e2fsck -f /dev/vdb1
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

/dev/vdb1: 11/6553600 files (0.0% non-contiguous), 459544/26214144 blocks

分区扩容:

[root@test ~]# resize2fs /dev/vdb1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vdb1 to 31457024 (4k) blocks.

The filesystem on /dev/vdb1 is now 31457024 blocks long.

挂载:

[root@test ~]# mount /dev/vdb1 /mnt
[root@test ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        50G  1.7G   49G   4% /
devtmpfs        1.9G     0  1.9G   0% /dev
tmpfs           1.9G     0  1.9G   0% /dev/shm
tmpfs           1.9G   17M  1.9G   1% /run
tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup
overlay          50G  1.7G   49G   4% /var/lib/docker/overlay/b00e0a4755ea2b6470c44ae489e832a08b836e933579f5b4e843626bb7386bda/merged
shm              64M     0   64M   0% /var/lib/docker/containers/8ab930a7c7cf1699b1e5b58ee7779fac54600ea3657411a7994fa6889042406a/shm
tmpfs           380M     0  380M   0% /run/user/0
/dev/vdb1       118G   60M  112G   1% /mnt


### 如何在Linux系统中对vdb数据盘进行扩容 #### 准备工作 为了确保能够顺利扩展 `/dev/vdb` 数据盘,在开始之前建议先备份重要数据。确认当前磁盘状态可以使用 `lsblk` 或者 `df -h` 命令来查看现有分区情况。 #### 扩展物理(PV) 如果已经存在 LVM 结构,则可以通过增加新空间到现有的物理来进行扩容: ```bash pvresize /dev/vdb ``` 这条命令会自动检测并调整物理大小以匹配底层设备的新尺寸[^4]。 #### 调整逻辑(LV)容量 对于基于LVM架构的情况,假设要扩展现有的逻辑 `/dev/vg0/lv0` ,执行如下指令: ```bash lvextend -l +100%FREE /dev/vg0/lv0 ``` 此操作将会把剩余未分配的空间全部加给指定的逻辑。其中 `-l +100%FREE` 表示利用所有可用空间;也可以通过 `-L +sizeG` 来指明具体增长量,比如加上额外的 5GB 可写作 `-L +5G`。 #### 文件系统在线重设大小 完成上述步骤之后,还需要相应地扩大文件系统的实际存储范围才能真正生效。针对不同的文件系统类型有不同的工具用于实现这一点。这里给出 ext4 的例子: ```bash resize2fs /dev/vg0/lv0 ``` 这一步骤通常可以在不卸载的情况下安全完成,即支持热插拔特性下的动态调整。 #### 更新挂载点设置 最后不要忘记更新 `/etc/fstab` 中的相关条目以反映最新的变更状况。例如: ```plaintext /dev/vdb /data ext4 defaults,noatime 0 0 ``` 确保路径名以及参数都保持最新和准确性是非常重要的[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值