Safer code
loop_file=$(awk '$2=="/" && $4~"loop" {print $1}' /etc/fstab) if [ -f "$loop_file" ]; then dev_mountpoint=$(awk '"'${loop_file}'"~"^"$2 && $2!="/" {print $1";"$2}' /proc/mounts|tail -n 1) host_device="${dev_mountpoint%;*}" host_mountpoint="${dev_mountpoint#*;}" fi if [ -n "$host_device" ]; then boot_device= root_device="$host_device" default_kopt="root=$host_device loop=${loop_file#$host_mountpoint} ro" else default_kopt="root=$root_device ro" fi kopt="$default_kopt"
Safer code
loop_file=$(awk '$2=="/" && $4~"loop" {print $1}' /etc/fstab) mountpoint= $(awk '"'${loop_ file}'" ~"^"$2 && $2!="/" {print $1";"$2}' /proc/mounts|tail -n 1) device= "${dev_ mountpoint% ;*}" mountpoint= "${dev_ mountpoint# *;}" device= "$host_ device" kopt="root= $host_device loop=${ loop_file# $host_mountpoin t} ro" kopt="root= $root_device ro" default_ kopt"
if [ -f "$loop_file" ]; then
dev_
host_
host_
fi
if [ -n "$host_device" ]; then
boot_device=
root_
default_
else
default_
fi
kopt="$