Was scared just now — extend the partition

  • A+
Categories:Linux

Have to say, these days I should be more careful when I dealt with any problem.

I have extended many partitions in the past, including the real environment or in my VMs. And I also know this is a very dangerous action, so for every step, need to know what I am doing and the possible result.

I know this, but this is not enough!

Today I wanted to enlarge a partition in an AWS EC2 instance. I could create a new partition but in that way I have to do more extra actions when I manage the data files in the future, so I prefer to extend the existing partition.

OK, did a check first:

I recalled parted could resize partition directly so I searched and found there should be 'resize' or 'resizepart' subcommands, but I could not find them in the system (RHEL7.3), so just one way left to me: deleting the current partition, and creating a new partition with the same start point. I read some webpages and knew I should use 'unit s' to get the actual sector for every partition, and did it as below:

Tried to mount it:

I guessed maybe something wrong. The partition name was /dev/xvdf1, but at that time it became /dev/xvdf2!

I run 'fdisk -l', and it did become /dev/xvdf2.

And I tried the following things in a short time:

  1. changed the partition type to 'Linux Filesystem'
  2. removed both partitions and created a new one large partition
  3. tried to adjust the start sector to 34

All of them failed to mount the filesystem, so I did lose my mind. I just did one thing right -- in such situation, never write any data on it.

I know I can change the partition many times as the partition information will not destroy the filesystem, which is stored at the beginning of the hard disk, and some in the end of the partition.

Why not checked the message file? Usually when I lose my mind, I will not do any change on the system, and just check the log files.

This time, the message file save me again!

So it seems I could not mount it just because the UUID was duplicated, right? Google helped me many many times!

XFS Filesystem has duplicate UUID problem

My Putty kept long history so I restored the partitions to the initial layout, and tried the nouuid option:

So I got my files back finally!

One issue left for me: how to quit parted without saving?

And more important, I should backup the partition table first!

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: