Linux – Can you change the partition type on a linux server without starting up fdisk

fdisklinuxsoftware-raid

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.

Best Answer

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.

Related Topic