I want to write a script to automatically modify the partition table
I am starting with 3 partitions like this
# parted /dev/sda print
Model: VMware, VMware Virtual S (scsi) Disk /dev/sda: 10.7GB Sector size (logical/physical): 512B/512B Partition Table: msdos
Number Start End Size Type File system Flags 1 32.3kB 107MB 107MB primary ext3 boot 2 107MB 4828MB 4721MB primary ext3 3 4828MB 9023MB 4195MB primary lvm
And I want to remove partitions 2 & 3 and recreate 2 from the end of 1 to the end of the disk i.e. all the free space.
Removing 2 and 3 is easy.
# parted /dev/sda rm 3 # parted /dev/sda rm 2
# parted /dev/sda print
Model: VMware, VMware Virtual S (scsi) Disk /dev/sda: 10.7GB Sector size (logical/physical): 512B/512B Partition Table: msdos
Number Start End Size Type File system Flags 1 32.3kB 107MB 107MB primary ext3 boot
Is there a way to use a non-interactive command to create the new 2nd partition in the free space?
Thanks
Dean
Karanbir Singh wrote:
Plant, Dean wrote:
Is there a way to use a non-interactive command to create the new 2nd partition in the free space?
parted works well for such situations, and if python is your thing, pyparted is already included in the distro.
Sorry, I should have worded my first email better.
I know there are command line tools like fdisk, sfdisk and parted.
I am trying to script the creation of a partition in the free space of a disk without knowing the exact structure of the disk. Parted seems to want to know the exact layout you want to create
From the man page
mkpart part-type [fs-type] start end
But the script will not know the start or the end point.
Something similar to what I am trying to achieve is described here http://ubuntuforums.org/showthread.php?p=5435429
They seem to be creating a single partition the size of the disk without specifying the exact sizes.
# parted /dev/${i} --script -- mkpart primary 0 -1
Similar to this, I want to create a partition without knowing the exact start or end point but im not interested in that, I just want to use the free space.
Hope this is clearer.
Thanks
Dean.
On Fri, 2008-08-08 at 15:10 +0100, Plant, Dean wrote:
Karanbir Singh wrote:
Plant, Dean wrote:
Is there a way to use a non-interactive command to create the new 2nd partition in the free space?
Yes.
parted works well for such situations, and if python is your thing, pyparted is already included in the distro.
Sorry, I should have worded my first email better.
I know there are command line tools like fdisk, sfdisk and parted.
Sfdisk is your friend.
<snip>
start or end point but im not interested in that, I just want to use the free space.
Hope this is clearer.
Having made my living for some months doing this, I offer the general below guidelines.
1. Study sfdisk man page closely. 2. Look especially for the parts where it can output disk and partition information in the form that can be re-read by sfdisk. 3. Use that information in a script (with your preferred combo of bash, perl, (g)awk, bc, dc, ...) to locate total size, amount used, start/end points, etc. 4. Calculate desired changes. 5. Apply to the saved information. 6. Run sfdisk reading the modified output from sfdisk. 7. sfdisk -R (IIRC) to re-read the partition information.
Alternately, steps 6/7 could be replaced with gparted if you structure the results properly.
Thanks
Dean.
<snip sig stuff>
HTH