Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
My root partition is on /dev/hda1 and my swap partition is on /dev/hda2.
I want to write a script that will move the swap partition to the end of the disk (or delete it and recreate it at the end of the disk) and then resize the root partition to fill the entire space in between. Script should not require any user input. Disk can be any size from 2GB to 40GB. Script will be executed while booted from SystemRescueCD.
How can I do this? I assume parted could be used in the resize step. Any help would be much appreciated. Thanks.
I assume you need to do this many times.
Yes parted would be a good choice maybe the only.
Write a simple bash script and call parted with predefined flags to handle the disk manipulation.
The swap is easy - swapoff, recreate it, mkswap, swapon.
I do a lot of fiddling with partitions. There is no way I'd use a script - too bloody dangerous if you get the maths wrong.
Yes, I need to do this many times. Basically I'm looking to do Example 1 from the GNU Parted manual (http://rush.ict.pwr.wroc.pl/docs/parted-1.4.16/USER), but without needing a user to input the start and end for the mkpartfs and the resize. The disk size can differ, so the start and end could change.
Some docs say that negative numbers in parted count from the end of the disk. Would something like the following work?
parted move 2 -125 -0
parted resize 1 0.063 -125
Would this move the swap partition in the previously cited Example to 125 megabytes from the end of the disk, and then resize the root partition to fill up the rest?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.