Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm looking for a way to change a partition type on a linux system without starting fdisk. (In this particular case from "linux" to "softwareRAID")

The ultimate goal here is a script that is going to take /dev/sda and automatically create a software RAID1 with /dev/sdb

I'm not looking for anyone here to write me a script, just trying to provide some info changing the partition type in a script. I can take care of the rest.

Thanks in advance.

share|improve this question
    
err, so who do i give this to!? Thank you both for the answer. –  jemmille Jul 28 '09 at 0:47

4 Answers 4

up vote 7 down vote accepted

or you could use sfdisk, it's also designed to be scriptable.

e.g. to change partition 1 of /dev/sda to type 0xfd (linux raid):

sfdisk --id /dev/sda 1 fd

you can also dump out an existing partition table to a file (in a format that is intended to be re-imported back into sfdisk), then modify that file with vi/awk/sed/perl/ed/whatever and then feed it back in to sfdisk.

e.g.

sfdisk -d /dev/sda | sed -e 's/Id=83/Id=fd/' > /tmp/sda.txt
sfdisk /dev/sda </tmp/sda.txt

i often use that when building raid arrays of identical disks. manually create the partition table on one drive then use sfdisk to copy it to the other drives.

share|improve this answer

I would look into parted, it is easily scriptable

share|improve this answer
    
I think we have to call it a tie ;-) –  Chad Huneycutt Jul 28 '09 at 0:05
1  
There are some good examples of parted within Debian FAI's 'setup_storage' script. –  Paul Lathrop Jul 28 '09 at 0:08

Use parted. You can script it, and it won't make you reboot :)

share|improve this answer

If you're looking to clone a partition table, dd bs=512 count=1 if=/dev/sda of=/dev/sdb; partprobe /dev/sdb is the easiest way.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.