美文网首页
关于AWS云服务器硬盘的梗

关于AWS云服务器硬盘的梗

作者: 吃土的司机 | 来源:发表于2017-12-19 17:01 被阅读0次

    相信不少人使用过阿里云的服务器,使用阿里云服务器对于添加的硬盘需要自行挂载。这里记录下使用亚马逊云硬盘方面碰到的坑。

    一、事件起因

    我创建了一个新的CentOS Linux实例。我实例的创建后,但是当系统上线时只显示盘8GB是可用的。创建实例的时候我很认真的确认我选择了30GB的硬盘,百思不得其解,最后在有过aws经验的朋友帮助下解决此问题,其实是他也踩过的坑。

    二、操作步骤

    1.查看分区信息

    使用 df -h 查看分区信息,发现根分区只有8个G


    fdisk -l 可以看到实际空间是32.2 G


    2.扩大硬盘空间

    对磁盘重新分区操作(接下来会介绍详细步骤):




    现在来对命令进行介绍:

    对/dev/xvda 分区进行操作

    [root@ip-172-31-26-162 ~]# fdisk /dev/xvda     
    WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
             switch off the mode (command 'c') and change display units to
             sectors (command 'u').
    

    使用u选项 显示单元扇区

    Command (m for help): u 
    Changing display/entry units to sectors
    

    按p 显示详细信息:

    Command (m for help): p 
    
    Disk /dev/xvda: 32.2 GB, 32212254720 bytes
    255 heads, 63 sectors/track, 3916 cylinders, total 62914560 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 identifier: 0x0050d75
    
        Device Boot      Start         End      Blocks   Id  System
    /dev/xvda1   *        2048    62914559     31456256   83  Linux
    

    删除第一个分区

    Command (m for help): d
    Selected partition 1
    

    开始创建一个新的分区,第一个扇面输入2048,需跟原有的start扇区一致。结尾的扇区选择最后一块(默认即最后一个)

    Command (m for help): n
    Command action
       e   extended
       p   primary partition (1-4)
    p
    Partition number (1-4): 1
    First sector (63-62914559, default 63): 2048 
    Last sector, +sectors or +size{K,M,G} (2048-62914559, default 62914559):
    Using default value 62914559
    

    再打印分区信息,会发现所有的磁盘空间都使用上了

    Command (m for help): p 
    
    Disk /dev/xvda: 32.2 GB, 32212254720 bytes
    255 heads, 63 sectors/track, 3916 cylinders, total 62914560 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 identifier: 0x0050d75
    
        Device Boot      Start         End      Blocks   Id  System
    /dev/xvda1            2048   62914559    31456256   83  Linux
    

    设置分区1为启动标志

    Command (m for help): a 
    Partition number (1-4): 1
    

    按 w 将分区信息写入磁盘:

    Command (m for help): w 
    

    最后重启系统并再次运行resize2fs

    [root@ip-172-31-26-162 ~]# reboot
    [root@ip-172-31-26-162 ~]# resize2fs /dev/xvda1 
    ......
    [root@ip-172-31-26-162 ~]# df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/xvda1       30G  1.9G   27G   7% /
    tmpfs           498M     0  498M   0% /dev/shm
    

    磁盘已经成功扩大到实际大小了

    相关文章

      网友评论

          本文标题:关于AWS云服务器硬盘的梗

          本文链接:https://www.haomeiwen.com/subject/eiqiwxtx.html