2

I have an ext4 filesystem on an USB stick and after using it for some time I would like to move the journal to some other blocks, so that the stick lives longer. The journal is described by inode 8, but how to I reallocate its blocks to a different place?

Is it possible to do that at file system creation time?

2

Check man mke2fs. Pay close attention to the -J / location section and the -E / packed_meta_blocks section.

You said you were using a USB stick. I'm assuming it can be formatted without consequence. Did you backup your data?

  1. Format the disk with a default command and get data on how the USB stick is put together.
  2. Format the disk with a altered command and get data on how the USB stick looks with the location moved.
  3. Moving the journal on an in-use disk.

You did backup you data?

Part 1. Default journal for reference

  1. Insert USB stick.
  2. In a terminal window, use sudo or su and supply the password.
  3. Use blkid " to find your " /dev/sdXX label.
  4. Command mke2fs -t ext4 /dev/sdXX for a default format.
  5. Now to pull out data about the drive.
  6. Command tune2fs -l /dev/sdXX. Find the line "Journal inode". Write this number down. It is usually 8.
  7. Command debugfs /dev/sdXX

    1. Command stat <8>. The "8" comes from the "Journal inode" line. The command needs to be entered exactly with the <,>.

      What do you see? The third line lists the size of the journal. Write this down. My machine came in at 33554432 (~32Mb). The 13th line lists the extents used for the journal. Write this down. My machine came in at 196608 - 204799. 196608 time 4k per page equals 786M.

    2. Command q then quit.
  8. Remove USB stick

Part 2. Moving the journal

  1. Same as above.
  2. Same as above.
  3. Same as above.
  4. command mke2fs -J location=600M /dev/sdXX. This should move the default journal to a point starting at the 600M mark.
  5. As above.
  6. As above.
  7. As above.
    1. The journal size should be the same. The first journal extent has moved to 153600 on my machine. 153600 times 4k per page equals ~614M.
    2. As above.
  8. As above.

Part 3. Moving the journal on an in-use disk

  1. Backup your data?
  2. Unmount the partition. umount /dev/sdXX.
  3. Remove old journal. tune2fs -O ^has_journal /dev/sdXX.
  4. Install new journal. tune2fs -J location=XX[M,G] /dev/sdXX. Specify units. The journal can be moved to a mega, giga location.
  5. e2fsck -fv /dev/sdXX just to be safe.
  6. Reboot the machine. You did backup didn't you?

You can change the journal size and location with mke2fs -J size=XX,location=YY[M,G,P,T] /dev/sdXX. The size notation is always in MB.

Where did this come from? "Trial and Error" course from the School of Hard Knocks.

| improve 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.