Rootop 服务器运维与web架构

linux下磁盘分区扩容(非lvm)

参考阿里云云盘扩容方法:https://help.aliyun.com/document_detail/25452.html

root@eth-public-01:~# fdisk /dev/xvdb

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.

Command (m for help): m # 帮助命令

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table

Command (m for help): d # 删除原分区 不会丢失数据
Selected partition 1
Partition 1 has been deleted.

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, default 1):  # 直接回车
First sector (2048-734003199, default 2048):  # 直接回车
Last sector, +sectors or +size{K,M,G,T,P} (2048-734003199, default 734003199):  # 直接回车

Created a new partition 1 of type 'Linux' and of size 350 GiB.

Command (m for help): wq # 保存退出
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

# ubuntu好像会自动挂载,再手动卸载它。
root@eth-public-01:~# umount /dev/xvdb1
root@eth-public-01:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            7.9G     0  7.9G   0% /dev
tmpfs           1.6G  8.7M  1.6G   1% /run
/dev/xvda1       18G  7.4G  9.2G  45% /
tmpfs           7.9G     0  7.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           7.9G     0  7.9G   0% /sys/fs/cgroup
tmpfs           1.6G     0  1.6G   0% /run/user/0

# 检查文件系统
root@eth-public-01:~# e2fsck -f /dev/xvdb1
e2fsck 1.42.13 (17-May-2015)
Pass 1: Checking inodes, blocks, and sizes
resizPass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information  
/dev/xvdb1: 110213/13107200 files (69.6% non-contiguous), 52423642/52428544 blocks
                                                                                                                                             
# 变更文件系统大小
root@eth-public-01:~# resize2fs /dev/xvdb1
resize2fs 1.42.13 (17-May-2015)
Resizing the filesystem on /dev/xvdb1 to 91750144 (4k) blocks.
The filesystem on /dev/xvdb1 is now 91750144 (4k) blocks long.

# 重新挂载即可
root@eth-public-01:~# mount -a # 我这里已经写到/etc/fstab了
root@eth-public-01:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            7.9G     0  7.9G   0% /dev
tmpfs           1.6G  8.7M  1.6G   1% /run
/dev/xvda1       18G  7.4G  9.2G  45% /
tmpfs           7.9G     0  7.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           7.9G     0  7.9G   0% /sys/fs/cgroup
tmpfs           1.6G     0  1.6G   0% /run/user/0
/dev/xvdb1      345G  197G  131G  61% /home

这样就实现数据不丢失且实现分区扩容。

原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/4095.html

作者:Venus

服务器运维与性能优化

评论已关闭。