3

I've an external 500GB HDD connected to my Laptop which runs Ubuntu 12.04. I've formatted the external drive with one ext4 partition which spans the entire disk.

My problem is that the disk makes noise every second, because writes occur to it. I'm not actively writing any file to the disk or use the disk otherwise. It's just mounted and should be idle.

Using iotop, I can see that with the disk plugged in, some jbd2 process writes to the disk. This jbd2 process does not do anything if the disk is not plugged in. The noise also immediately stops if I unmont the drive, but keep it plugged in.

iotop:

Total DISK READ:       0.00 B/s | Total DISK WRITE:    1838.15 K/s
  TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN     IO>    COMMAND                 
 3727 be/3 root        0.00 B/s    0.00 B/s  0.00 %  0.15 % [jbd2/sdb1-8]
    1 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % init
    2 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [kthreadd]
    3 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.00 % [ksoftirqd/0]
...

First of all, the noise drives me crazy. I work in a quiet environment and this allbeit very low noise is so disturbing somehow.

Second, I think that these continuous writes to the disk might cause it's lifetime to degrade. This would be especially important for SSD drives, where the noise isn't present, but the same behavior can be observed. Moreover, I think that writes to the disk should not be necessary, since no user process is accessing the disk and the operating system surely does not need to access an external HDD for its operation.

What causes these write accesses and how to stop them?

2

From the man mke2fs page and this link it appears that the defaults for formatting an ext4 filesystem are very lazy and leave a lot of the writing work to be finished after the drive is mounted for the first time, and every subsequent time until the work is finished. Most annoyingly, it will very slowly write to the drive every few seconds until it's done.

This could be especially bad for a flash drive (card/USB drive) that could have an extremely large block / page size, so writing just a few bytes actually writes to 256k, 512k, or a meg or more. And some flash drives could have an extremely low 1000 write cycles (or maybe 5000 or 10,000, possibly 100,000). Much lower than a hard drive, and even a hard drive would probably benefit more from doing all the writes at once, then being able to sit idle when it really should be idle. And I'm not sure how long it will keep slowly writing to the drive, some people say it could be a few minutes, or a few days. This seems like the worst way to "format" a flash drive.

Excerpt from the man page:

-E extended-options
      Set extended options for the filesystem.   Extended  options  are
      comma  separated, and may take an argument using the equals ('=')
      sign... The following extended options are supported:
...
 lazy_itable_init[= <0 to disable, 1 to enable>]
        If  enabled  and  the uninit_bg feature is enabled, the inode
        table will not be fully initialized by mke2fs.   This  speeds
        up  filesystem initialization noticeably, but it requires the
        kernel to finish initializing the  filesystem  in  the  back‐
        ground  when  the filesystem is first mounted.  If the option
        value is omitted, it defaults to 1 to enable lazy inode table
        zeroing.

 lazy_journal_init[= <0 to disable, 1 to enable>]
        If enabled, the journal inode will not be fully zeroed out by
        mke2fs.  This speeds up filesystem initialization noticeably,
        but  carries some small risk if the system crashes before the
        journal has been  overwritten  entirely  one  time.   If  the
        option  value  is  omitted,  it  defaults to 1 to enable lazy
        journal inode zeroing.

So, if you can initially format (or re-format) the filesystem, this should eliminate the lazy slow format and get it all done at once:

mkfs -t ext4 -E lazy_itable_init=0,lazy_journal_init=0 /dev/sdxN
  • Thanks :-) I didn't find a perfect solution, to immediately "finish" the format, but since it's a newly formatted drive just running a "non-lazy" format is good enough. I'm wondering why they would make the lazy format the default, it seems like a good option if you're in a real hurry to get a drive into service, or maybe it takes a very long time for a large drive... For a 32GB USB that only writes 10-15MB/sec it only took about 3min. Guessing, but maybe for a 1TB HD that writes 50MB/sec it could take 15-20min? – Xen2050 Nov 14 '15 at 17:23
3

There is a simple solution for you. Leave the disk connected to your PC for some hours and the noise will stop automatically. A rough estimation for the required time is 1.5h per 1TB of partition size.

This is because formatting to ext4 does not completely initialize the file system. A lot of the initialization work is delegated to jbd2, which is responsible for maintaining the journal of the file system.
When formatting, only the necessary information for using the disk is written. While you can already use the disk, jbd2 adds additional information. It's designed in this way so that formatting is quick. The write operations that you are observing after formatting do not affect the performance of the disk, i.e. when you copy files to the disk, the copy process will not be slower because of jbd2 also writing the journal.

jbd2 is designed to do its work in delayed intervals. Because most hard disks have built in power saving mechanisms, which can switch off the disk or park the heads, it is possible that the hard disk detects that it is idle, does some power saving operation like parking the heads, and immediately afterwards jbd2 accesses the disk again, causing it to move the heads again. This is the low noise which you are hearing.

If your hard disk's power saving mechanisms can be controlled (some HDDs support this, some don't), you can use the following command to disable the power saving mechanisms, thus silencing the disk durign the time that jbd2 makes initializations:

sudo hdparm -B 255 /dev/sdXY

where you have to replace sdXY by the path to your hard disk partition. If the command fails, your HDD does not support controlling the power saving mechanisms and you can't silence it. Then you have to wait as explained at the top of this answer.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.