I'm trying to automate the reinstallation process of existing Ubuntu installations.

Partition layout:

  • md0( raid1, /dev/sda1#/dev/sdb1 ) - swap (2G)
  • md1( raid1, /dev/sda2#/dev/sdb2 ) - / (20G)
  • md2( raid1, /dev/sda3#/dev/sdb3 ) - PV (remaining space)

What I want to accomplish is:

  • reuse existing RAIDs if they exist

Most important is to keep the data on existing PVs. I was able to accomplish that by setting a filter in lvm.conf, which excludes all block devices, ergo lvm support is disabled.

The problem is that after the installation I have to recreate /dev/md/2, hoping that data is intact.

The preseeding part of the configuration is:

d-i partman/early_command string sed 's/filter\ =\ \[\ "a\/.*\/\"\ \]/filter\ =\ \[\ "r\/.*\/\"\ \]/g' -i /etc/lvm/lvm.conf

d-i partman-auto-raid/recipe string \
    1 2 0 swap  -   /dev/sda1#/dev/sdb1     .\
    1 2 0 ext3  /   /dev/sda2#/dev/sdb2     .

d-i partman-auto/expert_recipe  string  \
    multiraid ::    \
        2000 10 2000 raid   $primary{ } method{ raid } format{ }  .\
        20000 11 20000 raid $primary{ } method{ raid } format{ }  . \
        20000 12 2000000 raid    $primary{ } method{ keep }    .

Maybe there is some other, more deterministic way to solve this problem?


There are some late_command examples in the Ubuntu Forums, the proposed example is based on one. But first, two points:

1) Automating an install that forces formatting of one file system while preserving another is inherently dangerous. If you don't back up before proceeding, you will lose data. "Maybe not today. Maybe not tomorrow, but soon, and for the rest of your life." ;-)

2) Recreating /dev/md2 is actually the safest part. That's an mdadm mirror RAID, your data is intact barring two simultaneous hard drive failures.

Anyway, you should be able to do something like this to get /dev/md2 rebuilt & mounted where you want it:

d-i preseed/late_command string \
in-target sed 's/^ARRAY/#&/g' -i /etc/mdadm/mdadm.conf; \
in-target mdadm --detail --scan >> /etc/mdadm/mdadm.conf; \
in-target mkdir /md2; \
in-target echo '/dev/md2  /md2  ext3  defaults 0 0' >>/etc/fstab;

I will test my solution & add a comment with my results, I'm working on preseed configs for 14.04 LTS right now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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