Linux lossless expansion method

Linux lossless expansion method

Overview

The cloud platform customer's server may run out of disk space as the business volume continues to grow. For example, if the shared file server's hard disk space is insufficient, you need to increase the disk space to meet the online business needs. Or when we use Linux, sometimes some partitions may have insufficient space due to improper partitioning during system installation, while others may have excess space. You can use the fdisk partition tool to dynamically adjust the partition size.

step

1. Backup

Even if it is lossless expansion, accidents are inevitable, so backup is essential. Generally, cloud platforms have backup functions that can directly make a full backup of the disk.

2. Repartition with fdisk

The default partitions are as follows

root@i-abnawjwo:/# df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 497752 4 497748 1% /dev
tmpfs 101700 440 101260 1% /run
/dev/sda1 20509308 1337636 18106816 7% /
none 4 0 4 0% /sys/fs/cgroup
none 5120 0 5120 0% /run/lock
none 508488 0 508488 0% /run/shm
none 102400 0 102400 0% /run/user
/dev/sdc1 10190136 23032 9626432 1% /data
root@i-abnawjwo:/data# cat hello
test1

Unmount the current partition umount /dev/sdc1

If you cannot uninstall it, there may be a process using it. You can use fuser or lsof to check

fuser -m -v /data
fuser -m -v -i -k /data
lsof /data

After uninstalling, use fdisk to delete the original partition and repartition it. Note that the starting cylinder number must be consistent with the original one (this is a key step to ensure that data is not lost)

root@i-abnawjwo:/# umount /data
root@i-abnawjwo:/# fdisk /dev/sdc

Command (m for help): d
Selected partition 1

Command (m for help): n
Partition type:
 p primary (0 primary, 0 extended, 4 free)
 e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-104857599, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599):
Using default value 104857599

Command (m for help): p

Disk /dev/sdc: 53.7 GB, 53687091200 bytes
64 heads, 32 sectors/track, 51200 cylinders, total 104857600 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: 0x305cddae

 Device Boot Start End Blocks Id System
/dev/sdc1 2048 104857599 52427776 83 Linux

Command (m for help): wq
The partition table has been altered!

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

Restart the system

3. Detect partitions and expand partition size

root@i-abnawjwo:~# e2fsck -f /dev/sdb1
e2fsck 1.42.9 (4-Feb-2014)
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/sdb1: 12/655360 files (0.0% non-contiguous), 79664/2621440 blocks
root@i-abnawjwo:~# resize2fs -p /dev/sdb1
resize2fs 1.42.9 (4-Feb-2014)
Resizing the filesystem on /dev/sdb1 to 13106944 (4k) blocks.
The filesystem on /dev/sdb1 is now 13106944 blocks long.

4. Remount, check partition size, and check data

root@i-abnawjwo:~# mount /dev/sdb1 /data/
root@i-abnawjwo:/data# cat hello
acasdcacsa
root@i-abnawjwo:/data# df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 497752 4 497748 1% /dev
tmpfs 101700 428 101272 1% /run
/dev/sda1 20509308 1337768 18106684 7% /
none 4 0 4 0% /sys/fs/cgroup
none 5120 0 5120 0% /run/lock
none 508488 0 508488 0% /run/shm
none 102400 0 102400 0% /run/user
/dev/sdb1 51474044 33100 48803172 1% /data

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • How to resize partitions in Linux without loss

<<:  MySql forgotten password modification method is suitable for versions 5.7 and above

>>:  Solution to Vue data assignment problem

Recommend

HTML Basics: The basic structure of HTML

The basic structure of HTML hypertext documents is...

Vite+Electron to quickly build VUE3 desktop applications

Table of contents 1. Introduction 2. Create a Vit...

Sample code of uniapp vue and nvue carousel components

The vue part is as follows: <template> <...

Two ways to completely delete users under Linux

Linux Operation Experimental environment: Centos7...

How to set PATH environment variable in Linux system (3 methods)

1. In Windows system, many software installations...

How to Completely Clean Your Docker Data

Table of contents Prune regularly Mirror Eviction...

MySQL partition table is classified by month

Table of contents Create a table View the databas...

Basic principles for compiling a website homepage

1. The organizational structure of the hypertext d...

Summary of seven sorting algorithms implemented in JavaScript (recommended!)

Table of contents Preface Bubble Sort Basic Algor...

The difference between docker run and start

The difference between run and start in docker Do...

React Synthetic Events Explained

Table of contents Start by clicking the input box...