2

I have a preseed script that creates a raid mirror out of the two first disks (/dev/sda, /dev/sdb)

d-i partman/early_command string \
DISKA=$(list-devices disk|head -n1);\
DISKB=$(list-devices disk|head -n2|tail -1);\
if [ "${DISKA#/dev/cciss}" != "$DISKA" ]; then DISKAP="p"; fi;\
if [ "${DISKB#/dev/cciss}" != "$DISKB" ]; then DISKBP="p"; fi;\
if [ "$DISKA" = "$DISKB" ]; then\
debconf-set partman-auto/disk "$DISKA";\
debconf-set partman-auto-raid/recipe "1 2 0 ext3 /boot ${DISKA}${DISKAP}1 . 1 2 0 lvm - ${DISKA}${DISKAP}5 .";\
debconf-set grub-installer/bootdev "$DISKA";\
else\
debconf-set partman-auto/disk "$DISKA $DISKB";\
debconf-set partman-auto-raid/recipe "1 2 0 ext3 /boot ${DISKA}${DISKAP}1#${DISKB}${DISKBP}1 . 1 2 0 lvm - ${DISKA}${DISKAP}5#${DISKB}${DISKBP}5 .";\
debconf-set grub-installer/bootdev "$DISKA $DISKB";\
fi;

But I need to be able to choose disk on size or type instead of sda/sdb. For example I have 2 160GB disks I want to use instead of the two 2TB SSD that are chosen as sda/sdb

How would one approach this using preseed?

1

This might not be the most elegant solution but it did the trick for me. It selects the first two disks that are less than 1000MB to use for the raid

d-i partman/early_command string \
NODEVICES=$(list-devices disk | wc -l);\
SIZELIMIT=1000;\
FOUNDDISK=0;\
COUNTER=0;\
while [ "$COUNTER" -ne "$NODEVICES" ]; do\
COUNTER=$((COUNTER+1));\
if [ $COUNTER -eq 1 ]; then\
DEVICE=$(list-devices disk|head -n1);\
else DEVICE=$(list-devices disk|head -n$COUNTER|tail -1);fi;\
echo $DEVICE >> /disks.txt;\
DEVICESIZE=$(fdisk -l|grep -o "$DEVICE: [0-9.]* GB"|grep -o "[0-9.]*");\
INT=${DEVICESIZE%.*};\
if [ $INT -lt $SIZELIMIT ]; then\
if [ $FOUNDDISK -eq 0 ]; then FOUNDDISK=1; DISKA=${DEVICE};\
elif [ $FOUNDDISK -eq 1 ]; then FOUNDDISK=2; DISKB=${DEVICE};fi;\
fi;\
done;\
if [ "${DISKA#/dev/cciss}" != "$DISKA" ]; then DISKAP="p"; fi;\
if [ "${DISKB#/dev/cciss}" != "$DISKB" ]; then DISKBP="p"; fi;\
if [ "$DISKA" = "$DISKB" ]; then\
debconf-set partman-auto/disk "$DISKA";\
debconf-set partman-auto-raid/recipe "1 2 0 ext3 /boot ${DISKA}${DISKAP}1 . 1    2 0 lvm - ${DISKA}${DISKAP}5 .";\
debconf-set grub-installer/bootdev "$DISKA";\
else\
debconf-set partman-auto/disk "$DISKA $DISKB";\
debconf-set partman-auto-raid/recipe "1 2 0 ext3 /boot ${DISKA}${DISKAP}1#${DISKB}${DISKBP}1 . 1 2 0 lvm - ${DISKA}${DISKAP}5#${DISKB}${DISKBP}5 .";\
debconf-set grub-installer/bootdev "$DISKA $DISKB";\
fi;

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.