Determine disk type for clearpart on kickstarts
I would like to develop logic in my kickstart to determine whether or not there is an sda or nvme0n1 drive and then clearpart that disk. So far, I have tried the solutions here:
https://www.redhat.com/archives/kickstart-list/2012-October/msg00014.html
https://gist.github.com/oogali/7629503#file-root-disk-selection-ks
But, they fail saying the drive cannot be located (it is an sda drive on my test machine). I have also tried just using the command "clearpart --drives=sda,nvme0n1 --Linux" and it fails saying it could not locate the drive.
Any assistance is appreciated. I am using RHEL 6.9, Satellite 5.7.
Responses
This is a great idea for identifying dynamically the boot disk device, be it NVME or SATA/SAS!
I've made some simplifying changes below, and also added a check if ROOTDRIVE is undefined.
I'm assuming that NVME boot drives will be preferred over /dev/sd* drives, YMMV.
I introduced a MAXSIZE as well because we do not want to clobber any large data-disks!
Also the partitioning details may be defined differently.
# The file /tmp/part-include is created below in the %pre section
%include /tmp/part-include
....
# Start of the %pre section with logging into /root/ks-pre.log
%pre --log=/root/ks-pre.log
#----- partitioning logic below--------------
# pick the first drive that is not removable and is over MINSIZE
DIR="/sys/block"
# minimum size of hard drive needed specified in GIGABYTES
MINSIZE=60
MAXSIZE=1100
ROOTDRIVE=""
# /sys/block/*/size is in 512 byte chunks
# The loop first checks NVME then SATA/SAS drives:
for d in $DIR/nvme* $DIR/sd*
do
DEV=`basename "$d"`
if [ -d $DIR/$DEV ]; then
if [[ "`cat $DIR/$DEV/removable`" = "0" ]]
then
GB=$((`cat $DIR/$DEV/size`/2**21))
echo "Disk device $DEV has size $GB GB"
if [ $GB -gt $MINSIZE -a $GB -lt $MAXSIZE -a -z "$ROOTDRIVE" ]
then
ROOTDRIVE=$DEV
echo "Select ROOTDRIVE=$ROOTDRIVE"
fi
fi
fi
done
if [ -z "$ROOTDRIVE" ]
then
echo "ERROR: ROOTDRIVE is undefined"
else
echo "ROOTDRIVE=$ROOTDRIVE"
cat << EOF > /tmp/part-include
zerombr
clearpart --drives=$ROOTDRIVE --all --initlabel
ignoredisk --only-use=$ROOTDRIVE
reqpart --add-boot
part swap --size 32768 --asprimary
part pv.01 --fstype xfs --size=1 --grow --asprimary
volgroup VolGroup00 pv.01
logvol / --fstype xfs --name=lv_root --vgname=VolGroup00 --size=32768
EOF
fi
%end