Home>

I want to extend the file system of a Linux server
Environment: CentOS 6.8/Sakura Internet VPS
Scale up from Sakura Internet control panel
Disk expanded from SSD 25G to SSD 50G
There is a business system in vda3 and I want to add more because the capacity is insufficient.
As a result of performing the procedure of Sakura Internet, the number of SSDs has increased, but the number of partitions has also increased.
vda4 (30G) has been added, but vda3 has not changed.
I want to integrate vda4 into vda3.
Perhaps you should delete the partition, specify a new sector, and then recreate it.
Below, I will describe the situation, what I am about to do, and questions.
I am not confident in the content of my first work, so please point it out. (* The work content quotes the procedure of Sakura Internet and describes my expectations. I have not executed it yet)
All the system data of the corresponding server has been moved to another server, and the corresponding server is not currently used at all. Recovery is possible even if system data is blown away.

〇Situation
==================================
[root @ prod ~] # df -h
Filesystem Size Used Avail Use% Mounted on
/ dev/vda3 18G 11G 6.1G 64%/← I want to add here
tmpfs 499M 0 499M 0%/dev/shm
/ dev/vda1 239M 58M 168M 26%/boot
/ dev/vda4 30G 44M 28G 1%/data
==================================
[root @ prod ~] # df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
/ dev/vda3 ext4 18193828 10881440 6381524 64%/← File system is ext4
tmpfs tmpfs 510024 0 510024 0%/dev/shm
/ dev/vda1 ext4 243823 59263 171760 26%/boot
/ dev/vda4 ext4 30832616 44992 29214764 1%/data
==================================
[root @ prod ~] # lsblk
NAME MAJ: MIN RM SIZE RO TYPE MOUNTPOINT
vda 252: 0 0 50G 0 disk
| -vda1 252: 1 0 250M 0 part/boot
| -vda2 252: 2 0 2G 0 part [SWAP]
| -vda3 252: 3 0 17.8G 0 part /* The goal is to set the SIZE of vda3 to 47.8G.
`-vda4 252: 4 0 30G 0 part/data
sr0 11: 0 1 1024M 0 rom
==================================
[root @ prod ~] # gdisk -l/dev/vdaGPT fdisk (gdisk) version 0.8.10

Partition table scan: MBR: protective BSD: not present present APM: not present GPT: present

Found valid GPT with protective MBR;using GPT. Disk/dev/vda: 104857600 sectors, 50.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): A797FC2B-C56A-40FF-B708-68DC6F16831B Partition table holds up to 128 entries First usable sector is 34, last usable sector is 104857566 Partitions will be aligned on 2048-sector boundaries Total free space is 2047 sectors (1023.5 KiB)

Number Start (sector) End (sector) Size Code Name 1 2048 514047 250.0 MiB 8300 Linux filesystem 2 514048 4708351 2.0 GiB 8200 Linux swap 3 4708352 41943006 17.8 GiB 8300 Linux filesystem 4 41943040 104857566 30.0 GiB 8300 Linux filesystem
=======================================
* Probably it will be integrated if Start (sector) 4708352/End (sector) 104857566 is used.

〇 Work content
===============
[root @ prod ~] #gdisk/dev/vda
===============
Command (help with m): d Selected area 4

Command (help with m): d Selected area 3
* Partitions 3 and 4 should now be deleted

Command (help with m): n
Partition Number: 3
First sector: 4708352
Last sector: 104857566

Current type is'Linux filesystem'
Hex ode or GUID (L to show codes, Enter = 8300):

Command (help with m): p
* Probably in the following state.Number Start (sector) End (sector) Size Code Name 1 2048 514047 250.0 MiB 8300 Linux filesystem 2 514048 4708351 2.0 GiB 8200 Linux swap 3 4708352 104857566 17.8 GiB 8300 Linux filesystem

Command (help with m): w Do I want to proceed? (Y/N): y
===============================
[root @ prod ~] #reboot
* Restart the OS to recognize the partition size change.
===============================
[root @ prod ~] # ls/dev/vda3
* Check if vda3 is recognized

[root @ prod ~] # mount/dev/vda3 /
* Mount vda3 on /

[root @ prod ~] #mount | grep vda3
* Check if it is mounted
===============================
[root @ prod ~] # resize2fs/dev/vda3
* If i resize vda3, it will probably be in the following state.
[root @ prod ~] # lsblk
NAME MAJ: MIN RM SIZE RO TYPE MOUNTPOINT
vda 252: 0 0 50G 0 disk
| -vda1 252: 1 0 250M 0 part/boot
| -vda2 252: 2 0 2G 0 part [SWAP]
`-vda3 252: 3 0 47.8G 0 part /
sr0 11: 0 1 1024M 0 rom

〇Question
1. 1. Is it correct to recognize that if you delete the partition with the gdisk command "g", the vda3 system data will not be deleted?
2. 2. When repartitioning, it seems that vda3 system data cannot be accessed if the Start sector changes. If that happens, will it be possible to access it by re-doing the above work correctly? (Does recovery work even if it fails?)
3. 3. There should be a file system called vda3, so
[mkfs.ext4/dev/vda3]
Is it correct with the recognition that it does not need to be formatted with a command?
4. Do you need the [umount /] command? When do you need it?
5. Since vda3 should already be mounted on /, isn't it necessary to remount it?
6. If remounting is required, which comes first, the mount command or the resize2fs command?

It's been a long sentence, but it would be helpful if someone could answer.

  • Answer # 1

    1. 1. Is it correct to recognize that if you delete the partition with the gdisk command "g", the vda3 system data will not be deleted?

    Yes, it fits.

    2. 2. When repartitioning, it seems that vda3 system data cannot be accessed if the Start sector changes. If that happens, will it be possible to access it by re-doing the above work correctly? (Does recovery work even if it fails?)

    Yes, if you only have partition operations with gdisk and no other operations, you can start over.
    However, it turns out to be "failed" only after some other operation, such as an OS reboot.

    3. 3. There should be a file system called vda3, so
    [mkfs.ext4/dev/vda3]
    Is it correct with the recognition that it does not need to be formatted with a command?

    Do not format.

    4. Do you need the [umount /] command? When do you need it?
    5. Since vda3 should already be mounted on /, isn't it necessary to remount it?
    6. If remounting is required, which comes first, the mount command or the resize2fs command?

    Since it is the root partition, it cannot be unmounted.
    If it's an extension, I think I could have resize2fs even with it mounted.

    Or do you expect to boot and work in rescue mode from an ISO image?

  • Answer # 2

    I worked while checking the partition status frequently with the df command and gdisk command.
    As a result, it failed and I couldn't access the server, so I reinstalled the OS and copied the system and data from another server to recover.
    I didn't know the rescue mode because I worked before other people answered.

    I deleted the partition with the gdisk command and respecified the sector with the gdisk command.
    When I rebooted with the reboot command, I couldn't access it.

    Perhaps I should have done the resize2fs command after respecifying the sector.
    Also, the rescue mode is useful, so I would like to make use of it next time.

  • Answer # 3

    I have already answered, so it will be a fluke, but

    2. 2. When repartitioning, it seems that vda3 system data cannot be accessed if the Start sector changes. If that happens, will it be possible to access it by re-doing the above work correctly? (Does recovery work even if it fails?)

    The theory is that, but if you make a mistake, you will not be able to mount the root partition, and you will have a hard time starting rescue with the installation media, so please be careful not to make a mistake in the sector information.
    * If you follow the default when creating a partition, it should usually be the correct starting position.

    5. Since vda3 should already be mounted on /, isn't it necessary to remount it?

    Since resize2fs can be extended with ext4 mounted, it does not need to be remounted. Except for very old systems, CentOS 6 series is sufficient. From the resize2fs man page below

    If the filesystem is mounted, it can be used toexpand the size of the mounted filesystem, assuming the kernel supports on-line resizing. (As of this writing, theLinux 2.6 kernel supports on-line resizefor filesystems mountedusing ext3 and ext4.).