Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: unmounting drives, sync command needed

  1. #1

    Default unmounting drives, sync command needed

    In a script to access a plugin memory card, I received help and wrote a script. It used a sync command after unmounting the memory card.

    Code:
    umount /mnt
    
    #flush buffers to make sure all the data is written to the SD card
    sync
    In the scanvirus script, I mount and unmount drives in the scanning process. It can include flash drives. Do need the sync command after unmounting a drive?

  2. #2

    Default Re: unmounting drives, sync command needed

    Quote Originally Posted by lord_valarian View Post
    In a script to access a plugin memory card, I received help and wrote a script. It used a sync command after unmounting the memory card.

    Code:
    umount /mnt
    
    #flush buffers to make sure all the data is written to the SD card
    sync
    In the scanvirus script, I mount and unmount drives in the scanning process. It can include flash drives. Do need the sync command after unmounting a drive?
    Hi,

    After unmounting? no, before unmounting maybe.
    "Unfortunately time is always against us" -- [Morpheus]

    .:https://github.com/Jetchisel:.

  3. #3
    Join Date
    Jun 2008
    Location
    Groningen, Netherlands
    Posts
    20,925
    Blog Entries
    14

    Default Re: unmounting drives, sync command needed

    Quote Originally Posted by lord_valarian View Post
    In a script to access a plugin memory card, I received help and wrote a script. It used a sync command after unmounting the memory card.

    Code:
    umount /mnt
    
    #flush buffers to make sure all the data is written to the SD card
    sync
    In the scanvirus script, I mount and unmount drives in the scanning process. It can include flash drives. Do need the sync command after unmounting a drive?
    This is wrong, completely wrong. The sync command is to make sure that all data are written to the SD card. It shoud be like
    Code:
    sync
    umount /mnt
    ° Appreciate my reply? Click the star and let me know why.

    ° Perfection is not gonna happen. No way.

    http://en.opensuse.org/User:Knurpht
    http://nl.opensuse.org/Gebruiker:Knurpht

  4. #4

    Default Re: unmounting drives, sync command needed

    Hi,

    You can probably wait for sync to finish before doing the umount commands. I haven't tested it so

    Code:
    sync && umount blah.. blah...
    Or use a loop

    Code:
    until sync; do
       blah...blah...
    done
    "Unfortunately time is always against us" -- [Morpheus]

    .:https://github.com/Jetchisel:.

  5. #5
    Join Date
    Jun 2008
    Location
    Groningen, Netherlands
    Posts
    20,925
    Blog Entries
    14

    Default Re: unmounting drives, sync command needed

    Quote Originally Posted by jetchisel View Post
    Hi,

    You can probably wait for sync to finish before doing the umount commands. I haven't tested it so

    Code:
    sync && umount blah.. blah...
    Or use a loop

    Code:
    until sync; do
       blah...blah...
    done
    You don't have to check, the next command won't be executed until sync finishes. So
    Code:
    sync;umount blah blah
    works fine as well.
    ° Appreciate my reply? Click the star and let me know why.

    ° Perfection is not gonna happen. No way.

    http://en.opensuse.org/User:Knurpht
    http://nl.opensuse.org/Gebruiker:Knurpht

  6. #6

    Default Re: unmounting drives, sync command needed

    Hi,

    Yes the order of the commands should take care of the execution since sync comes first but you can probably add some message to the screen while sync is not done yet.

    Code:
    until sync; do
      printf 'Still wainting for sync to finish.%s\n'
    done
    You can play with it by negating the exit status of sync. It should give you the message...

    Code:
    until ! sync; do 
      printf '"I am Groot"%s ' 
    sleep 5
    done
    "Unfortunately time is always against us" -- [Morpheus]

    .:https://github.com/Jetchisel:.

  7. #7

    Default Re: unmounting drives, sync command needed

    Hi,

    Yes the order of the commands should take care of the execution since sync comes first but you can probably add some message to the screen while sync is not done yet.

    Code:
    until sync; do
      printf 'Still wainting for sync to finish.%s\n'
    done
    You can play with it by negating the exit status of sync. It should give you the message...

    Code:
    until ! sync; do 
      printf '"I am Groot"%s ' 
    sleep 5
    done
    Or using a while loop.

    Code:
    while sync; do 
      printf 'I am Groot.%s '
    done
    "Unfortunately time is always against us" -- [Morpheus]

    .:https://github.com/Jetchisel:.

  8. #8

    Default Re: unmounting drives, sync command needed

    Code:
        #if drive mounted, unmount it
        #printf "Device_Mounted_Flag = %s   Device_Label= %s\n" $1 $2
        if [ "$1" = 'true' ];then
            #flush buffers to make sure all the data is written to drive
            sync
    
            command_output_unmount=$(udisksctl unmount -b "$2");unmount_error=$?
            printf "%s\n" ${command_output_unmount%.}    
        fi
    I read the sync help file. Do I need to add the drive system to the command?


    sync --help
    Usage: sync [OPTION] [FILE]...
    Synchronize cached writes to persistent storage

    If one or more files are specified, sync only them,
    or their containing file systems.

    -d, --data sync only file data, no unneeded metadata
    -f, --file-system sync the file systems that contain the files
    --help display this help and exit
    --version output version information and exit

  9. #9

    Default Re: unmounting drives, sync command needed

    It looks like you can specify files and have it sync just that filesystem;
    you do not NEED to do this, but it may be better if you want your script
    to run faster since then you will only sync the one soon-to-be-unmounted
    filesystem instead of all filesystems of the computer.

    On another note, I do not think sync will have that much to do unless you
    are writing data to the filesystem about to be unmounted. Also, I do not
    think umount will return until the implicit flushing of caches happens
    anyway, but verify that is the case.

    --
    Good luck.

    If you find this post helpful and are logged into the web interface,
    show your appreciation and click on the star below.

    If you want to send me a private message, please let me know in the
    forum as I do not use the web interface often.

  10. #10

    Default Re: unmounting drives, sync command needed

    Quote Originally Posted by ab View Post
    It looks like you can specify files and have it sync just that filesystem;
    you do not NEED to do this, but it may be better if you want your script
    to run faster since then you will only sync the one soon-to-be-unmounted
    filesystem instead of all filesystems of the computer.

    On another note, I do not think sync will have that much to do unless you
    are writing data to the filesystem about to be unmounted. Also, I do not
    think umount will return until the implicit flushing of caches happens
    anyway, but verify that is the case.

    --
    Good luck.

    If you find this post helpful and are logged into the web interface,
    show your appreciation and click on the star below.

    If you want to send me a private message, please let me know in the
    forum as I do not use the web interface often.
    The scan includes flash drives. So to play it safe, I'll use it. Is this correct usage?

    Code:
        #if drive mounted, unmount it
        #printf "Device_Mounted_Flag = %s   Device_Label= %s\n" $1 $2
        if [ "$1" = 'true' ];then
            #flush buffers to make sure all the data is written to drive
            sync -f "$2"
    
            command_output_unmount=$(udisksctl unmount -b "$2");unmount_error=$?
            printf "%s\n" ${command_output_unmount%.}    
        fi

Page 1 of 2 12 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •