parted question

Forum: LXer Meta ForumTotal Replies: 4
Author Content

Aug 21, 2015
4:37 PM EDT
Hello fellow LXers,

I'm sure one of you knows the answer to this question, but for the life of me I can't find a solution on my favorite search engine.

I'm doing a dual boot Linux installation on 25 (university classroom) computers and, of course, I'm wanting to script the whole thing in order to save time.

The idea is to boot up a system in a Linux live disk and then run a custom installation script that shrinks the existing system, creates partitions of the right size, and then dd's prepared images into those partitions.

The first step is to shrink the existing NTFS partition down to half its present size and herein lies my difficulty. This step can be nicely handled using the gui gparted program, but I need to find the command line equivalent so that this step can be scripted. It looks like the "parted resize" is destructive and does not preserve the partition's existing filesystem. Does anyone know what the command line equivalent to the gparted non-destructive shrink capability would be?

Aug 21, 2015
4:54 PM EDT
While I am not answering your question, I just wish to caution you with this approach from a past experience. I used GParted to shrink an NTFS partition with Win 8.1 on a new EFI HP laptop. This process went on fine, except that Windows would not boot again. I re-expanded the partition with GParted to spread across the whole disk to be able to start Windows. The only way I found to shrink the partition conservatively was to do it in a running Windows session. Then I could dual boot. There may be other ways to do that. I'll be following the responses to know what I have been missing.

Aug 21, 2015
5:04 PM EDT
Gparted gives you the commands it's using for each operation...

So do it once, and copy the command to use it in your script.

Aug 21, 2015
5:11 PM EDT
Perfect! I knew that someone in our community would have the answer. Thanks, you saved me a lot of time.

Aug 21, 2015
8:20 PM EDT
Note the sizes above are absolute. So if you have varying size hard drives you'll have to adjust them. Also note these sections of the ntfsresize man page:

To resize a filesystem on a partition, you must resize BOTH the filesystem and the partition by editing the partition table on the disk ... ntfsresize doesn't manipulate the size of the partitions, hence to do that you must use a disk partitioning tool as well, for example fdisk(8) ... If you wish to shrink an NTFS partition, first use ntfsresize to shrink the size of the filesystem. Then you could use fdisk(8) to shrink the size of the partition by deleting the partition and recreating it with the smaller size. Do not make the partition smaller than the new size of NTFS otherwise you won't be able to boot.

It's not as simple as the single command would indicate.

Posting in this forum is limited to members of the group: [Editors, MEMBERS, SITEADMINS.]

Becoming a member of LXer is easy and free. Join Us!