[SOLVED] what happens to data when I delete one partition and resize the other
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
While it isn't a definitive answer from my test the file offset remained the same with the original partition 2 as when it was resized to the entire drive which implies the file was moved.
Expanding a partition should not lead to data loss and many filesystems allow you to expand "on the fly" i.e. while it is mounted. resizing smaller or moving is always best when the filesystem is unmounted. In the case of your example the steps would be to move first then expand. Regardless of what operation is being performed you should always have a backup of data you do not want to lose because you never no what might happen.
If you delete the 1st partition, the data on the 2nd partition is untouched.
Then you certainly have the problem that the sectors of the 1st partition are before the 2nd partition, and a file system can grow at its end only. And a simple partition manager like (g)parted cannot move or remap any data.
The solution that I know:
move the 2nd partition to a volume manager (usually LVM). Under the volume manager the data is still there, but in a new device path, a virtual disk. The virtual device can always grow; if you grow it by the 1st partition then the LVM will remap the low sectors to high sectors. And the file system can grow normally (online).
If you delete the 1st partition, the data on the 2nd partition is untouched.
Then you certainly have the problem that the sectors of the 1st partition are before the 2nd partition, and a file system can grow at its end only. And a simple partition manager like (g)parted cannot move or remap any data.
The solution that I know:
move the 2nd partition to a volume manager (usually LVM). Under the volume manager the data is still there, but in a new device path, a virtual disk. The virtual device can always grow; if you grow it by the 1st partition then the LVM will remap the low sectors to high sectors. And the file system can grow normally (online).
Thank you for this. Makes sense - as far as my somewhat limited understanding of LVMs goes.
You can get detailed information on GParted if that is what you are going to use by reading through their online manual at the link below. Go to the Advanced Partition Actions section of the Table of Contents. According to this, if you delete a partition, you can expand the partition either way and also copy data but it will take quite a while to do with a partition of 1TB. As stated at the site, it would be problematic (possibly) if it was a boot drive with boot files on it, the 2nd partition you want to move.
Operations on partition table affect nothing but the partition table, the data will stay where it was. If you do this however, results could surprise you: filesystems typically expect to find superblock or equivalent data structure at the start of the block device (partition), so if you try to mount this monstrosity you'll find the contents of partition 1, and contents of partition 2 will become inaccessible.
This may or may not be true depending upon which tool is used.
Gparted manages moving, resizing, formatting, etc. on partitions and will cleanly delete partition 1 then resize partition 2 to occupy that space without any of the mentioned errors. It even recreates the appropriate superblocks and backups for the newer enlarged partition size so the user is not caught by surprise.
Thus, with the proper tools this type task is easy. In the past when doing everything manually with only a partition management tool your scenario may have been valid, but not today when using the proper tools.
My suggestion, since the OP claimed to have an up-to-date copy of the data made with rsync would have been to simply enlarge the partition, reformat, then restore from his backup.
With the concern about times for the files, a tar archive of the data would save and restore the existing times for each file.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.