18

Is there a way to sync only one partition instead of all partitions?

Something like "sync /dev/sdc1".

imz -- Ivan Zakharyaschev
  • 15,113
  • 15
  • 61
  • 123
HandyGandy
  • 2,201
  • 3
  • 23
  • 30

6 Answers6

11

you can remount with sync option and then remount it back with async:

mount -o remount,sync /mountpoint
mount -o remount,async /mountpoint

Using remount option will not mess with processes using remounted filesystem.

Michał Šrajer
  • 2,808
  • 17
  • 17
  • 2
    Why do you think that 2 remounts are necessary? In at least 2.6.32 kernel do_remount_sb performs sync_filesystem which is the same function that is called in syncfs system call introduced in https://lwn.net/Articles/433384/. – Yuriy Nazarov Mar 01 '16 at 17:38
5

There is a standard function to synchronize data (and metadata) of one file: fsync. There is no standard or common shell command to access it, but you can use perl's sync method in IO::Handle:

perl -MIO::File -e 'new IO::File($ARGV[0], "r+")->sync()' filename

There is no standard or common function or shell command to synchronize just one partition.

On recent Linux systems, there is the syncfs system call (introduced in kernel 2.6.39, and exposed since glibc 2.14). I don't think this system call is exposed in coreutils or util-linux yet.

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
4

It is now possible with sync -f:

sync -f /mount/point

Excerpt from sync(1):

       -f, --file-system
              sync the file systems that contain the files
Artefact2
  • 281
  • 3
  • 6
3

Mounting the partition with the sync option may be a solution.

llua
  • 6,760
  • 24
  • 30
2

If you mean the sync utility that flushes data in memory to disk, then the answer is no. This is due to the fact that sync is generally used during a shutdown or reboot procedure, where it's advisable to get data written safely to disk, and the real target of the operation is memory, not the disks, and getting that buffered data out of RAM to somewhere safe. The disks are just where the data ends up.

Tim Kennedy
  • 19,369
  • 4
  • 38
  • 58
1

If btrfs:

btrfs filesystem sync /path/under/mountpoint
Tom Hale
  • 28,728
  • 32
  • 139
  • 229