1

I want to mount another root partition, edit the grub.cfg file with a python script and afterwards umount the partition again. How can I wait for the python script to finish and check if the partition is ready to be umounted? Currently I have tried to use wait but this doesn't do the trick.

if mountpoint $MPOINT; then
    echo "Already mounted. To prevent potential file loss aborting."
else
    echo "OK, will now mount the needed device."
    mkdir $MPOINT
    mount $DEVICE $MPOINT
    if [ $? -eq 0 ]; then
        # Edit config file
        python /usr/bin/grubcfgmgr.py "$MPOINT" &
        pid=$!
    else
        echo "Failed, could not mount. Aborting."
        rm -rf $MPOINT
        exit n
    fi

    # Umount
    wait $pid
    umount $MPOINT
    if [ $? -eq 0 ]; then
        echo "OK, umount was succesfull. Will delete empty mount point."
        rm -rf $MPOINT
    else
        echo "Failed, could not umount. Aborting."
    fi
fi
5
  • 4
    Why is the python script backgrounded? Wouldn’t you accomplish if staying fg?
    – Dani_l
    Jan 13, 2019 at 13:43
  • Not for a specific reason. But running the script in fg unfortunately doesn't help either.
    – conste
    Jan 13, 2019 at 13:58
  • Small nitpick: if [ $? -eq 0 ] is unnecessay. Do if mount "$DEVICE" "$MPOINT" ; then Jan 13, 2019 at 14:00
  • What's the expected result and what are you seeing? Jan 13, 2019 at 22:30
  • This is the current output: mountpoint: /run/media/con/773a2bb3-546b-4483-a777-275ac1a57427: No such file or directory OK, will now mount the needed device. umount: /run/media/con/773a2bb3-546b-4483-a777-275ac1a57427: device is busy. Failed, could not umount. Aborting.
    – conste
    Jan 19, 2019 at 14:15

0

You must log in to answer this question.

Browse other questions tagged .