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."
    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" &
        echo "Failed, could not mount. Aborting."
        rm -rf $MPOINT
        exit n

    # Umount
    wait $pid
    umount $MPOINT
    if [ $? -eq 0 ]; then
        echo "OK, umount was succesfull. Will delete empty mount point."
        rm -rf $MPOINT
        echo "Failed, could not umount. Aborting."
  • 4
    Why is the python script backgrounded? Wouldn’t you accomplish if staying fg? – Dani_l Jan 13 '19 at 13:43
  • Not for a specific reason. But running the script in fg unfortunately doesn't help either. – conste Jan 13 '19 at 13:58
  • Small nitpick: if [ $? -eq 0 ] is unnecessay. Do if mount "$DEVICE" "$MPOINT" ; then – Sergiy Kolodyazhnyy Jan 13 '19 at 14:00
  • What's the expected result and what are you seeing? – Mark Plotnick Jan 13 '19 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 '19 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.