前两天web实体服务器电源告警,总担心电源炸了,服务一倒,客户肯定得跳脚,领导估计要杀了我祭慰客户爸爸那受伤的心,脖子一凉,麻利儿的申请了一台云服务器 16c 32g 1t,个人觉得应该稳了。。。。
奈何太年轻,配置环境,迁移数据。。。 1t的磁盘不够,哪怕是删去垃圾数据文件,也还是占了865G,这要是跑着跑着,日志文件增多,导致空间不足宕机,估计还是要找工作。。
遂提oa单子,又申请了1T的空间。。
磁盘空间扩展不是个常用的操作,所以记录一下,以备以后使用。。
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 1007G 840G 168G 84% /
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 16G 9.6M 16G 1% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/vda1 1014M 166M 849M 17% /boot
tmpfs 3.2G 0 3.2G 0% /run/user/0
可以看到目前磁盘目前空间只有1T,而且占用了84%,这怎么能睡得着。。
[root@localhost ~]# fdisk -l
Disk /dev/vda: 2199.0 GB, 2199023255552 bytes, 4294967296 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: 0x000b63a7
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 2099199 1048576 83 Linux
/dev/vda2 2099200 2147483647 1072692224 8e Linux LVM
Disk /dev/mapper/centos-root: 1081.5 GB, 1081518063616 bytes, 2112339968 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 /dev/mapper/centos-swap: 16.9 GB, 16911433728 bytes, 33030144 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
fdisk 可以看出,Disk /dev/vda: 2199.0 GB ,磁盘实际上有2199G的空间的,所以有空间没有没分配和使用。
fdisk /dev/vda
警告:删除分区时要小心,请看好分区的序号,如果您删除了扩展分区,扩展分区之下的逻辑分区都会删除;所以操作时一定要小心;如果知道自己操作错了,请不要惊慌,用q不保存退出;切记切记!!!!在分区操作错了之时,千万不要输入w保存退出!!!
然后输入m->n->p->回车->回车->回车->w //命令解析如下:
n 注:添加分区 - 》 p 注:添加主分区,默认主分区;- 》 回车 默认分区号 -》 回车 使用所有未分区的空间 -》w 保存操作
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition 注:这是删除一个分区的动作;
l list known partition types 注:l是列出分区类型,以供我们设置相应分区的类型;
m print this menu 注:m 是列出帮助信息;
n add a new partition 注:添加一个分区;
o create a new empty DOS partition table
p print the partition table 注:p列出分区表;
q quit without saving changes 注:不保存退出;
s create a new empty Sun disklabel
t change a partition's system id 注:t 改变分区类型;
u change display/entry units
v verify the partition table
w write table to disk and exit 注:把分区表写入硬盘并退出;
x extra functionality (experts only) 注:扩展应用,专家功能;
具体每个参数的含义,请仔细阅读。常用的就是:d l m p q t w
reboot 重启
[root@localhost ~]# fdisk -l
Disk /dev/vda: 2199.0 GB, 2199023255552 bytes, 4294967296 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: 0x000b63a7
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 2099199 1048576 83 Linux
/dev/vda2 2099200 2147483647 1072692224 8e Linux LVM
/dev/vda3 2147483648 4294967294 1073741823+ 83 Linux
Disk /dev/mapper/centos-root: 1081.5 GB, 1081518063616 bytes, 2112339968 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 /dev/mapper/centos-swap: 16.9 GB, 16911433728 bytes, 33030144 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 -l 就可以看到、dev/vda3了
对 vda3格式化
[root@localhost ~]# mkfs.xfs /dev/vda3
meta-data=/dev/vda3 isize=512 agcount=4, agsize=67108864 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=268435455, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=131071, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
创建pv
[root@localhost ~]# pvcreate /dev/vda3
WARNING: xfs signature detected on /dev/vda3 at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/vda3.
Physical volume "/dev/vda3" successfully created.
查看逻辑卷
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- <1023.00g 4.00m
对 centos卷进行扩展
[root@localhost ~]# vgextend centos /dev/vda3
Volume group "centos" successfully extended
再次查看逻辑卷
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 2 2 0 wz--n- <2.00t 1.00t
可以看到由原来的1023G变成了2T。其中1T是空闲的
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 1007G 840G 168G 84% /
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 16G 9.6M 16G 1% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/vda1 1014M 166M 849M 17% /boot
tmpfs 3.2G 0 3.2G 0% /run/user/0
通过df -h 看到空间还没有添加上
通过lvextend对目录进行扩展
[root@localhost ~]# lvextend -l +100%free /dev/mapper/centos-root
Size of logical volume centos/root changed from 1007.24 GiB (257854 extents) to 1.98 TiB (519998 extents).
Logical volume centos/root successfully resized.
重新扩容 xfs_growfs 计算空间
[root@localhost ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=66010624 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=264042496, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=128927, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 264042496 to 532477952
再使用df -h , 就会发现,新的空间挂载上了
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 2.0T 840G 1.2T 42% /
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 16G 9.6M 16G 1% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/vda1 1014M 166M 849M 17% /boot
tmpfs 3.2G 0 3.2G 0% /run/user/0
打完手工!
感谢linux fdisk 分区、格式化、挂载!_时光与流水的博客-CSDN博客_fdisk
-------------------------------------------------------补充-----------------------------------------------------------------
一下操作在Ubuntu系统操作,数据无价
对于Ubuntu来说 xfs_growfs /dev/mapper/vgubuntu-root 回报错
dingqiang@dingqiang-MS:/home$ xfs_growfs /dev/mapper/vgubuntu-root
xfs_growfs: /dev/mapper/vgubuntu-root is not a mounted XFS filesyste
虽然vgs表明数据空间已经扩容在上面了
dingqiang@dingqiang-MS:~$ sudo vgs
VG #PV #LV #SN Attr VSize VFree
vgubuntu 2 2 0 wz--n- <1.02t 0
经过查资料,Ubuntu用了lvm格式,所以扩容需要lvextend命令
lvextend -L 20G /dev/mapper/ubuntu–vg-ubuntu–lv //增大或减小至20G
lvextend -L +20G /dev/mapper/ubuntu–vg-ubuntu–lv //增加20G
lvreduce -L -20G /dev/mapper/ubuntu–vg-ubuntu–lv //减小20G
lvresize -l +100%FREE /dev/mapper/ubuntu–vg-ubuntu–lv //按百分比扩容
resize2fs /dev/mapper/ubuntu–vg-ubuntu–lv //执行调整
如这一步还能跟centos一样
dingqiang@dingqiang-MS:~$ sudo lvresize -l +100%FREE /dev/mapper/vgubuntu-root
New size (266710 extents) matches existing size (266710 extents).
重要的是centos扩容 和 Ubuntu的扩容区别在 resize2fs 和 xfs_growfs
dingqiang@dingqiang-MS:~$ sudo resize2fs /dev/mapper/vgubuntu-root
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/mapper/vgubuntu-root is mounted on /; on-line resizing required
old_desc_blocks = 14, new_desc_blocks = 131
The filesystem on /dev/mapper/vgubuntu-root is now 273111040 (4k) blocks long.
df -h 可以看到 /dev/mapper/vgubuntu-root 1.1T 8.7G 974G 1% /
dingqiang@dingqiang-MS:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 7.8G 0 7.8G 0% /dev
tmpfs 1.6G 1.7M 1.6G 1% /run
/dev/mapper/vgubuntu-root 1.1T 8.7G 974G 1% /
tmpfs 7.8G 4.0K 7.8G 1% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sdb1 511M 5.3M 506M 2% /boot/efi
tmpfs 1.6G 28K 1.6G 1% /run/user/1000
收工------------------------