linux 扩充磁盘记录
Yi
Linux
2024-05-06
110
1,查看扩容磁盘的空间
[root@VM_0_4_centos ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 140M 0 rom
vda 253:0 0 100G 0 disk
└─vda1 253:1 0 100G 0 part /
vdb 253:16 0 1.2T 0 disk
└─vdb1 253:17 0 600G 0 part /test1
目前数据盘(vdb)只有一个分区(vdb1)且大小只有600G
2、在分区目录中建立文件,验证扩充过程是否会影响分区中的数据
[root@VM_0_4_centos /]# cd test1
[root@VM_0_4_centos test1]# touch 1.txt
[root@VM_0_4_centos test1]# echo 测试数据 >> 1.txt
[root@VM_0_4_centos test1]# cat 1.txt
测试数据
3、删除要扩充的分区,然后再建立新分区(和原分区Partition number相同)
[root@VM_0_4_centos ~]# fdisk /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): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): d
Selected partition 1
Partition 1 is deleted
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-2516582399, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2516582399, default 2516582399):
Using default value 2516582399
Partition 1 of type Linux and of size 1.2 TiB is set
Command (m for help): p
Disk /dev/vdb: 1288.5 GB, 1288490188800 bytes, 2516582400 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: 0x3a9f652c
Device Boot Start End Blocks Id System
/dev/vdb1 2048 2516582399 1258290176 83 Linux
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.
fdisk编辑中使用到的命令有
m帮助d删除分区n新建分区,注:新建的分区号要和删除的分区号保持一致p查看分区w保存配置并写入分区表,注:一定要确认无误在输入这个命令不然会导致数据丢失
4、重启服务器
[root@VM_0_4_centos ~]# init 6
5、使用df -T查看原分区文件系统格式是
[root@VM_0_4_centos ~]# df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/vda1 ext4 103079844 17984600 80675064 19% /
devtmpfs devtmpfs 16370140 0 16370140 0% /dev
tmpfs tmpfs 16380784 0 16380784 0% /dev/shm
tmpfs tmpfs 16380784 1052 16379732 1% /run
tmpfs tmpfs 16380784 0 16380784 0% /sys/fs/cgroup
/dev/vdb1 ext4 619139232 340655956 247009664 58% /test1
tmpfs tmpfs 3276160 0 3276160 0% /run/user/0
可以看到分区格式为ext4
6、扩充分区(/dev/vdb1)
[root@VM_0_4_centos ~]# resize2fs /dev/vdb1
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vdb1 is mounted on /test1; on-line resizing required
old_desc_blocks = 75, new_desc_blocks = 150
The filesystem on /dev/vdb1 is now 314572544 blocks long.
7、查看磁盘分区是否扩容成功
[root@VM_0_4_centos test1]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 140M 0 rom
vda 253:0 0 100G 0 disk
└─vda1 253:1 0 100G 0 part /
vdb 253:16 0 1.2T 0 disk
└─vdb1 253:17 0 1.2T 0 part /test1
目前数据盘(vdb)分区(vdb1)成功扩容到1.2T
8、查看原数据是否存在
[root@VM_0_4_centos ~]# cat /test1/1.txt
测试数据