Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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.


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
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


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.