Linux/Ubuntu服务器数据盘挂载及扩容

服务器部署:
运行 fdisk -l 命令查看实例上的数据盘:    fdisk -l
查看磁盘使用情况:    df    -lh
 
① 分区:
    依次执行以下命令以创建一个单分区数据盘:
    1. 运行 fdisk -u /dev/vdb:分区数据盘。
    2. 输入 p:查看数据盘的分区情况。本示例中,数据盘没有分区。
    3. 输入 n:创建一个新分区。
    4. 输入 p:选择分区类型为主分区。
        说明 本示例中创建一个单分区数据盘,所以只需要创建主分区。如果要创建 4 个以上分区,您应该创建至少一个扩展分区,即选择 e(extended)。
    5. 输入分区编号并按回车键。本示例中,仅创建一个分区,输入 1。
    6. 输入第一个可用的扇区编号:按回车键采用默认值 2048。
    7. 输入最后一个扇区编号:本示例仅创建一个分区,按回车键采用默认值。
    8. 输入 p:查看该数据盘的规划分区情况。
    9. 输入 w:开始分区,并在分区后退出。
② 运行命令 fdisk -lu /dev/vdb 查看新分区。
③ 写系统文件:
    mkfs.ext4 /dev/vdb1
④ 挂载:
    1.(建议)运行命令 cp /etc/fstab /etc/fstab.bak 备份 etc/fstab。
    2. 运行命令 echo /dev/vdb1 /mnt ext4 defaults 0 0 >> /etc/fstab 向 /etc/fstab 写入新分区信息。
⑤ 运行命令 cat /etc/fstab 查看 /etc/fstab 中的新分区信息。
⑥ 运行命令 mount /dev/vdb1 /mnt 挂载文件系统。
⑦ 运行命令 df -h 查看目前磁盘空间和使用情况。
在 mnt 下可新建目录进行使用。
 
对已有的进行扩展容量 参考:
 
​扩展已有MBR分区:
首先在阿里服务器添加数据盘
① 修改分区表:
    1. 运行以下命令查看分区信息,并记录旧分区的起始和结束的扇区位置。    
fdisk -lu /dev/vdb
    本示例中,分区 /dev/vdb1 的起始扇区是2048,结束扇区是41943039。
[root@ecshost ~]# fdisk -lu /dev/vdb
Disk /dev/vdb: 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: 0x9277b47b
 
Device Boot Start End Blocks Id System
/dev/vdb1 2048 41943039 20970496 83 Linux
    2. 查看数据盘的挂载路径,根据返回的文件路径卸载分区,直至完全卸载已挂载的分区。
[root@ecshost ~]# mount | grep "/dev/vdb"
/dev/vdb1 on /mnt type ext4 (rw,relatime,data=ordered)
[root@ecshost ~]# umount /dev/vdb1
[root@ecshost ~]# mount | grep "/dev/vdb"
    3.  使用 fdisk工具删除旧分区。*   删除旧分区会一同删除分区内的数据。如有重要数据请备份,避免因删除旧分区而造成数据丢失。
        1. 运行 fdisk -u /dev/vdb:分区数据盘。
        2. 输入 p:打印分区表。
        3. 输入 d:删除分区。
        4. 输入 p:确认分区已删除。
        5. 输入 w:保存修改并退出。
[root@ecshost ~]# fdisk -u /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: 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: 0x9277b47b
Device Boot Start End Blocks Id System
/dev/vdb1 2048 41943039 20970496 83 Linux
Command (m for help): d
Selected partition 1Partition 1 is deleted
Command (m for help): p
Disk /dev/vdb: 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: 0x9277b47b
Device Boot Start End Blocks Id System
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.
    4.  使用fdisk命令新建分区。
        1. 运行 fdisk -u /dev/vdb:分区数据盘。
        2. 输入 p:打印分区表。
        3. 输入 n:新建分区。
        4. 输入 p:选择分区类型为主分区。
        5. 输入<分区号>:选择分区号。本示例选取了 1
        * 警告 新分区的起始位置必须和旧分区的起始位置相同,结束位置必须大于旧分区的结束位置,否则会导致扩容失败。
        6. 输入 w:保存修改并退出。
       本示例中,将 /dev/vdb1 由20GiB扩容到40GiB。
[root@ecshost ~]# fdisk -u /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: 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: 0x9277b47b
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-83886079, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-83886079, default 83886079):
Partition 1 of type Linux and of size 30 GiB is set
Command (m for help): p
Disk /dev/vdb: 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: 0x9277b47b
Device Boot Start End Blocks Id System
/dev/vdb1 2048 62916607 31457280 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
        7 . 运行 lsblk /dev/vdb 确保分区表已经增加。
        8. 运行 e2fsck -n /dev/vdb1 再次检查文件系统,确认扩容分区后的文件系统状态为clean。
② 扩容文件系统。
    1. ext*文件系统(例如ext3和ext4):依次运行以下命令调整ext*文件系统大小并重新挂载分区。
root@iZj6c3drthhdo9qs7guv0xZ:~# e2fsck -f /dev/vdb1
e2fsck 1.42.9 (4-Feb-2014)
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: 5901/19660800 files (84.0% non-contiguous), 74693043/78642944 blocks​
[root@ecshost ~]# resize2fs /dev/vdb1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vdb1 to 7864320 (4k) blocks.
The filesystem on /dev/vdb1 is now 7864320 blocks long.
[root@ecshost ~]# mount /dev/vdb1 /mnt
     
    2.  xfs文件系统:依次运行以下命令先重新挂载分区,再调整xfs文件系统大小。
[root@ecshost ~]# mount /dev/vdb1 /mnt/
[root@ecshost ~]# xfs_growfs /dev/vdb1meta-data=/dev/vdb1 isize=512 agcount=4, agsize=1310720 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=5242880, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 5242880 to 7864320
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Darryl_Tang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值