Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

Sparing most details/reasons, I have a situation in which I'm cloning drives for mass production. Some of them are being installed in servers that only need one disk (in that case this is a non-issue), but some are being installed in servers that will use 2 of them in RAID1.

In another case we're building a tool to assist the admin in replacing a faulty disk by ensuring the new disk is large enough and then copying the MBR and Partition Table, and then adding it to the RAID1. When this happens LILO complains about duplicate volume IDs (which makes sense).

This is why I would like to generate new volume IDs for the partition being added to the RAID1 array. Does it make sense to use sfdisk to rewrite a disks partition table, or is there a more straightforward command/technique to create a new volume id for an existing volume?

share|improve this question
up vote 1 down vote accepted

Read the mbr from the disk, change the disk signature which is the 4 bytes @ offset 440 in the mbr then write it back to the disk.

dd if=/dev/sda of=mbr.dat bs=512 count=1 # see script below
dd if=newmbr.dat of=/dev/sda bs=512 count=1

Note: I tested this by saving the output of od -x for mbr.dat and newmbr.dat and then running a diff on the 2 text files which shows that only the relevant 4 bytes are changed.

open FILE,"<mbr.dat" or die $!;
binmode FILE, ":raw";
my ($data,$n);
if ( ( $n=read FILE,$data,512 ) !=512 ) {
    print "Error - Only managed to read $n bytes from file";
   exit 2;
close FILE;
my @mbr=unpack("c*", $data);

$mbr[440] = int(rand(255));
$mbr[441] = int(rand(255));
$mbr[442] = int(rand(255));
$mbr[443] = int(rand(255));

open FILE,">newmbr.dat" or die $!;
binmode FILE;
print FILE  $data;
close FILE;
exit 0;
share|improve this answer
This technique makes sense to me, but once I executed it against my first bootable disk, it wrecked my grub installation, i had to flip my disks and copy the original MBR back on.. – andyortlieb Oct 28 '10 at 17:07
Can you try editing the 4 bytes manually with a hex editor & tell me what happens ? – Iain Oct 28 '10 at 17:47
I had a change to test this on an Ubuntu VM running under ESXi. The system boots fine with the changed mbr. – Iain Oct 29 '10 at 9:48
My fault, you're right. I actually hosed my grub installation on this disk in a previous life. It works perfectly, thank you. And thank you for clarifying what the disk signature is, the documents I've read have not been totally clear. – andyortlieb Oct 29 '10 at 14:48

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.