Skip to content
Snippets Groups Projects
Commit 8d2df93b authored by Pietsch, Martin's avatar Pietsch, Martin
Browse files

added function getPartitionDeviceByIndex

parent 86347112
No related branches found
No related tags found
No related merge requests found
......@@ -206,6 +206,16 @@ setDiskPartitionFlags() {
return
}
# getPartitionDeviceByIndex - returns the partition device of a disk by index
# parameter:
# $1 - name of the disk device
# $2 - index of the disk partition
# return:
# partition device of the given disk on STDOUT
getPartitionDeviceByIndex() {
fdisk -l /dev/$1 2>/dev/null | sed -n -e "s/^\(\/dev[^ ]*\) .*$/\1/p" | sed -n "$2p"
}
# formatDiskPartion - format a partition
# parameter:
# $1 - disk device name
......@@ -216,9 +226,11 @@ setDiskPartitionFlags() {
# 1 - error occurred
# 2 - unknown filesystem
formatDiskPartion() {
local device="/dev/$1$2"
local device
local retval=0
device=$(getPartitionDeviceByIndex $1 $2)
case $(echo $3 | tr "[A-Z]" "[a-z]") in
"ext4") mkfs.ext4 -q -F ${device} >/dev/null|| retval=1 ;;
"ext3") mkfs.ext3 -q -F ${device} >/dev/null || retval=1 ;;
......@@ -283,6 +295,7 @@ generateFSTab() {
local dmp
local pass
local dev
local partdev
if [ $# -eq 3 ];
then
......@@ -296,8 +309,9 @@ generateFSTab() {
idx=1
for part in $(eval "for p in \${DISK_$(echo ${disk} | tr [a-z] [A-Z])_PARTITIONS[@]}; do echo \$p; done ")
do
uuid=$(blkid -s UUID -o value /dev/${disk}${idx})
fs=$(blkid -s TYPE -o value /dev/${disk}${idx})
partdev=$(getPartitionDeviceByIndex ${disk} ${idx})
uuid=$(blkid -s UUID -o value ${partdev})
fs=$(blkid -s TYPE -o value ${partdev})
mntpnt=$(echo ${part} | cut -f 3 -d ";")
opts=$(echo ${part} | cut -f 4 -d ";")
dmp=$(echo ${part} | cut -f 5 -d ";")
......@@ -313,10 +327,10 @@ generateFSTab() {
case ${2} in
"uuid") dev="UUID=${uuid}" ;;
*)
dev="/dev/${disk}${idx}"
dev=${partdev}
;;
esac
echo "#/dev/${disk}${idx}" >>$1
echo "#${dev}" >>$1
if [ "${mntpnt}" != "none" ];
then
echo -e "${dev} ${mntpntpfx}${mntpnt} ${fs} ${opts} ${dmp} ${pass}\n" >>$1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment