Partitioning with BASH Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Partitioning with BASH Script
# 1  
Old 04-16-2009
Partitioning with BASH Script

Hello. I've used these one-liners successfully to resize the existing FAT partition on a flash drive (to about 1GB), then add an ext2 partition to the remaining space.

parted $device --script -- resize 1 1000
mount ${device}1
parted $device --script -- mkpartfs primary ext2 1001 -- -1
mount ${device}2

But it doesn't work always. It seems to work at times only. If, later, I remove the partitions and reinstate the single FAT32 partition that uses the entire disk, I then get errors from parted when using these commands again. And I've gotten other random errors as well. I've read about the errors I received and evidently they are parted bugs, so I've lost confidence in using parted for my script.

I'm struggling a bit with figuring out the script equivalents for cfdisk, sfdisk or fdisk. Suggestions regarding how to script these specific tasks with other partition tools would be very much appreciated.
# 2  
Old 04-16-2009
fdisk: old, reliable, more or less scriptable
cfdisk: pretty, easy to use, hell to script
sfdisk: ugly, very strict about syntax, no-nonsense interface, very scriptable

Just my €0.02
# 3  
Old 04-16-2009
Um -- thanks, but I was hoping for some guidance on how to use those alternatives for the resizing and creation of partitions as shown with parted in my original post.
# 4  
Old 04-16-2009
First: neither of them support resizing a partition by themselves, they only deal with the partition table. So the example above would require
  1. resizing the filesystem (if supported)
  2. recreating the (smaller) partition table entry
  3. creating the new partition
  4. creating a filesystem on the new partition
I'd suggest doing this by hand, using either fdisk or sfdisk, and writing down what you entered. You can then automate this by echo-ing it in, eg
Code:
$ echo "c
p
1
1
+1024M
t
b
a
1
w
" | fdisk /dev/sdg

would (assuming the partition table on /dev/sdg is blank) create a primary partiton, starting at cylinder 1, 1G in size, change the type of the partition to 'b' (W95 FAT32), activate the bootflag, and write the partition table to the disk.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed

In Bash shell - the ps -ef shows only the /bin/bash but the script name is not displayed ? Is there any way to get the script names for the process command ? --- Post updated at 08:39 AM --- in KSH (Korn Shell), my command output shows the script names but when run in the Bash Shell... (3 Replies)
Discussion started by: i4ismail
3 Replies

2. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

3. Shell Programming and Scripting

Different behavior between bash shell and bash script for cmd

So I'm trying to pass certain json elements as env vars and use them later on in a script. Sample json: JSON='{ "Element1": "file-123456", "Element2": "Name, of, company written in, a very weird way", "Element3": "path/to/some/file.txt", }' (part of the) script: for s... (5 Replies)
Discussion started by: da1
5 Replies

4. Red Hat

Need help Partitioning

I am getting ready to install RHEL6 server. I have to create these partitions: / 10GB SWAP 3GB /opt/kent 10GB /opt/kent/logs /backup 20 GB Will Gparted do this? or whats the easiest way? or even a tutorial?I am so new to this (4 Replies)
Discussion started by: linux4noob
4 Replies

5. UNIX for Dummies Questions & Answers

Im new to bash scriping and i found this expression on a bash script what does this mean.

# check host value regex='^(||1|2|25)(\.(||1|2|25)){3}$' if ')" != "" ]; then if ]; then echo host $host not found exit 4 fi elif ]; then echo $host is an invalid host address exit 5 fi espeacailly the top regex part? ---------- Post updated at 06:58 PM ---------- Previous update was... (1 Reply)
Discussion started by: kevin298
1 Replies

6. Ubuntu

About partitioning

Hi folks, Ubuntu 10.04-1 64-bit HD - 1T SATA3 I ran graphic installation installing Ubuntu-10.04-1 desktop from Live CD The partition on the new HD is as follow; /root /home /kvm (kvm is for keeping the guests of KVM, the virtualizer) Installion went through without problem abd... (0 Replies)
Discussion started by: satimis
0 Replies

7. Shell Programming and Scripting

how to make your bash script run on a machine with csh and bash

hi, i have a script that runs on bash and would like to run it on a machine that has csh and bash. the default setting on that machine is csh. i dont want to change my code to run it with a csh shell. is there any way i can run the script (written in bash) on this machine? in other words is there... (3 Replies)
Discussion started by: npatwardhan
3 Replies

8. Shell Programming and Scripting

Partitioning script for rescue mode (disk size calculation)

Hello! I need to write partitioning script wich would work in rescue mode. It will prepare partitions and unpack linux on it. However I need to calculate whole size of the disk and create: /dev/sda1 --> One big partition (minus (2*size of memory) for swap) /dev/sda2 --> Swap partition... (1 Reply)
Discussion started by: pug123
1 Replies

9. Red Hat

Partitioning?

Hey, this question is generated purely out of my lack of knowledge. Ok, obviously you can partition hard drives, I have Windows 2k, and can partition it from administrative tools, however, all of the help sections have utterly failed to give me any information other than "when you partition, it... (5 Replies)
Discussion started by: Mal_Zapatos
5 Replies

10. Shell Programming and Scripting

passing variable from bash to perl from bash script

Hi All, I need to pass a variable to perl script from bash script, where in perl i am using if condition. Here is the cmd what i am using in perl FROM_DATE="06/05/2008" TO_DATE="07/05/2008" "perl -ne ' print if ( $_ >="$FROM_DATE" && $_ <= "$TO_DATE" ) ' filename" filename has... (10 Replies)
Discussion started by: arsidh
10 Replies
Login or Register to Ask a Question