使用 Preseed 根据大小或类型选择安装磁盘

使用 Preseed 根据大小或类型选择安装磁盘

我有一个预置脚本,它从前两个磁盘(/dev/sda、/dev/sdb)创建一个 raid 镜像

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;

但我需要能够选择磁盘大小或类型,而不是 sda/sdb。例如,我有 2 个 160GB 磁盘,我想使用它们,而不是选择为 sda/sdb 的两个 2TB SSD

如何使用预先设定的方法来解决这个问题?

答案1

这可能不是最优雅的解决方案,但对我来说很管用。它选择前两个小于 1000MB 的磁盘用于 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;

相关内容