暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Linux磁盘空间扩展

原创 侯海兵 2020-10-29
1268

1、扩展前磁盘信息:
[root@linux_copy ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_hisdg-lv_root 50G 13G 35G 26% /
tmpfs 64G 0 64G 0% /dev/shm
/dev/vda1 485M 39M 421M 9% /boot
/dev/mapper/vg_hisdg-lv_home 427G 81G 325G 20% /home
/dev/vdb1 1008G 420G 538G 44% /data
[root@linux_copy ~]#
[root@linux_copy ~]# fdisk -l

Disk /dev/vda: 536.9 GB, 536870912000 bytes
16 heads, 63 sectors/track, 1040253 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0004ef2e

Device Boot Start End Blocks Id System
/dev/vda1 * 3 1018 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2 1018 1040254 523774976 8e Linux LVM
Partition 2 does not end on cylinder boundary.

Disk /dev/vdb: 1314.3 GB, 1314259992576 bytes
16 heads, 63 sectors/track, 2546541 cylinders ////此处是已扩展的总数量
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x439194e9

Device Boot Start End Blocks Id System
/dev/vdb1 1 2130440 1073741728+ 83 Linux
/////但现在这个分区只分配到2130440

Disk /dev/mapper/vg_hisdg-lv_root: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg_hisdg-lv_swap: 16.9 GB, 16911433728 bytes
255 heads, 63 sectors/track, 2056 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/vg_hisdg-lv_home: 465.7 GB, 465743904768 bytes
255 heads, 63 sectors/track, 56623 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

[root@linux_copy ~]#

2、扩容过程:
2.1、将磁盘卸载掉
[root@linux_copy ~]# umount /dev/vdb1
umount: /data: device is busy. /////这里提示磁盘忙,需要查找看看哪个进程占用。
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@linux_copy ~]#

各种UMOUNT不管用,使用fuser也查不出什么程序在占用
[root@linux_copy ~]# umount /dev/vdb1
umount: /data: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@linux_copy ~]# fuser -m -v /data
[root@linux_copy ~]# umount /dev/vdb1
umount: /data: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@linux_copy ~]# umount /data
umount: /data: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@linux_copy ~]# umount /dev/vdb1 -f
umount2: Device or resource busy
umount: /data: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
umount2: Device or resource busy

于是修改/etc/fstab将其自动挂载先去掉,reboot看看
[root@linux_copy ~]# vi /etc/fstab

# /etc/fstab
# Created by anaconda on Tue Oct 15 08:55:09 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
LABEL=dm-0 /                       ext4    defaults        1 1
UUID=a94bd11a-baa5-408c-b9c2-2bccf7ebdbcd /boot                   ext4    defaults        1 2
LABEL=dm-2 /home                   ext4    defaults        1 2
/dev/mapper/vg_hisdg-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults,size=64G        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
# /dev/vdb1               /data                   ext4    defaults        2 1
/data/swapfile           swap                    swap    defaults        0 0

[root@linux_copy ~]#
[root@linux_copy ~]# reboot
重启后已不再挂载
[root@linux_copy ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_hisdg-lv_root 50G 13G 35G 26% /
tmpfs 64G 0 64G 0% /dev/shm
/dev/vda1 485M 39M 421M 9% /boot
/dev/mapper/vg_hisdg-lv_home 427G 81G 325G 20% /home
[root@linux_copy ~]#
2.2、使用fdisk对磁盘重新分区
[root@linux_copy ~]# fdisk /dev/vdb

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’).

Command (m for help): p —先查看分区信息

Disk /dev/vdb: 1314.3 GB, 1314259992576 bytes
16 heads, 63 sectors/track, 2546541 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x439194e9

Device Boot Start End Blocks Id System
/dev/vdb1 1 2130440 1073741728+ 83 Linux

Command (m for help): d --删除分区信息,因为这里就一个分区,因此自动选择
Selected partition 1

Command (m for help): p --再次查看,分区已删除

Disk /dev/vdb: 1314.3 GB, 1314259992576 bytes
16 heads, 63 sectors/track, 2546541 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x439194e9

Device Boot Start End Blocks Id System

Command (m for help): n --新建分区
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2546541, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2546541, default 2546541):
Using default value 2546541

Command (m for help): p --再次查看 此处很重要,如果不一致,不要保存

Disk /dev/vdb: 1314.3 GB, 1314259992576 bytes
16 heads, 63 sectors/track, 2546541 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x439194e9

Device Boot Start End Blocks Id System
/dev/vdb1 1 2546541 1283456632+ 83 Linux

Command (m for help): wp --保存分区修改信息
The partition table has been altered!

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

2.3、重新创建分区后,需要重启
[root@linux_copy ~]# reboot

Broadcast message from root@linux_copy
(/dev/pts/0) at 10:04 …

The system is going down for reboot NOW!
[root@linux_copy ~]#

2.4、重启后检查分区信息,调整分区大小
[root@linux_copy ~]# e2fsck -f /dev/vdb1
e2fsck 1.41.12 (17-May-2010)
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: 1543/67108864 files (40.2% non-contiguous), 114152898/268435432 blocks
[root@linux_copy ~]# resize2fs -p /dev/vdb1
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/vdb1 to 320864158 (4k) blocks.
Begin pass 1 (max = 1600)
Extending the inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/vdb1 is now 320864158 blocks long.

[root@linux_copy ~]# mount /dev/vbd1 /data
mount: you must specify the filesystem type
[root@linux_copy ~]# mount -t ext4 /dev/vdb1 /data
[root@linux_copy ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_hisdg-lv_root 50G 13G 35G 26% /
tmpfs 64G 0 64G 0% /dev/shm
/dev/vda1 485M 39M 421M 9% /boot
/dev/mapper/vg_hisdg-lv_home 427G 81G 325G 20% /home
/dev/vdb1 1.2T 420G 725G 37% /data ////已扩展
[root@linux_copy ~]# vi /etc/fstab

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论