I have a Remote Dedicated Server with no Online control panel to resize partitions after initial OS install, so I am using the debian based rescue environment to manipulate the partitions unmounted. Problem is, I am a bit stupid when it comes to Partition manipulation on remote drives, I have tried using GNU Parted command line tool, since GParted isn't an option, and fdisk is useless since the drive is formatted with GPT, only to find out the resize command has been removed as of version 2.4. So, Below is a list of my partitions from the print command of parted:
Number Start End Size File system Name Flags
1 20.5kB 1049kB 1029kB primary bios_grub
2 2097kB 21.0GB 21.0GB ext4 primary
3 21.0GB 2000GB 1979GB ext4 primary
4 2000GB 2000GB 536MB linux-swap(v1) primary
What I need to figure out, is how to shrink #3 to about 1.2TB and then expand the #2 to fill what was moved when #3 was shrunk. My #2 Partition is full, and the #3 partition has space to spare.
Best Answer
Doing what you want might or might not be possible, depending on what is (and must be) currently mounted, and whether you can boot from some other medium to work around mount problems. Factors to consider here:
resize2fs
utility does this job from the command line.parted
does not provide by default. You need to setunit s
to get this; or you can usegdisk
, which provides sector-level precision by default. (Evengdisk
, though, automatically aligns partitions to 2048-sector values by default, so you may need to adjust alignment with thed
option on the experts' menu.)dd
or some other tool to move the entire contents of the filesystem. Depending on the direction of the movement, this may need to be done before or after you delete the original partition, and the new one may need to be created before or after the move. If the move operation overlaps the original location, you must be very careful about how you do this, lest you destroy some partition data!resize2fs
to grow the filesystem to the size of the new surrounding partition. This procedure minimizes the chances of getting a size mis-match.Because of these issues, attempting to do what you want without the help of GParted or some other tool designed to coordinate partition and filesystem changes can be extremely risky. It can be done, but one slip-up in specifying a sector value can leave you with a disk that's totally worthless. The fact that you're asking for help about this makes me wary about suggesting you even make the attempt; the risk of trashing a production system is just too great for somebody who's never before done this sort of thing. If you have no other option, I strongly recommend you re-create your server locally and practice on the copy before you try it on your remote server.
You might want to consider some alternatives:
In the future, you might want to consider using Logical Volume Management (LVM), which makes these sorts of manipulations much simpler and safer. LVM has a significant learning curve, but once you've got the basics down, it helps a lot because you need not worry about moving partitions; filesystems are stored like files in a filesystem, so once you shrink one, you can expand another into the free space without changing the start point. LVM also helps you add space in the form of new disks.