0

I have x86 based box running FreeBSD 10.1. I have made it dual boot with Red hat Linux as other OS. Now I'm migrating a UFS partition 'A' on a FreeBSD (10.1) to ext2 based partition on Linux. I'm using partition 'B' as temporary storage.

I am following below procedure.

  1. In FreeBSD: I format 'B' as ext2 and move data from 'A' to 'B' using rsync. Reboot the box.
  2. Box comes up with Linux. I now format 'A' as ext2 in Linux , mount B as ext2 and move data from 'B' to 'A' using rsync

Issue: Many times mount of 'B' in Linux fails and suggest to run fsck. When I run fsck in non-interactive mode it fails and suggest to run in manually. I cannot 'fsck' run manually as box are remotely located. Secondly I'm worried if fsck may lead to data loss.

Queries:

  1. Why linux is asking me to run fschk? What I'm doing wrong?
  2. How safe is running fsck on a partition? My box will not able to come up cleanly in case files are removed in the operation.
  3. Is there any way to log all operation done under fsck that I can use for debugging

Operation done on FreeBSD:

#format raw partition as ext2 
mkfs.ext2  /dev/mfid0s1f

#mount newly formated partition as backup
mkdir -p /backup
mount /dev/mfid0s1f /backup 

#move data for UFS partition mounted as 'data' to ext2 partition 
rsync -a /data/*  /backup 

#reboot the box 
reboot

Operation done in Linux (via rc.local):

case 1: I try to mount 'backup' without fsck

mkdir -p /backup
mount /dev/sda8  /backup 
mount fail with suggestion to run fsck. 

case 2: I add non-interective fsck

mkdir -p /backup
e2fsck -p /dev/sda8 
fail with : /dev/sda8: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY
Kusalananda
  • 333,661
  • That could smell as a hardware failure, or some overlapping partitions. But it smells bad. I would recommend instead backup the data (perhaps as a .tar.bz2 archive on some external, maybe FAT32, media; or remotely) – Basile Starynkevitch Sep 16 '17 at 13:27
  • @BasileStarynkevitch thanks for your input. I'm not suspecting HW issue. If i format same partition as ext2 in Linux and move data I do not observe any such error. – Satpal Parmar Sep 16 '17 at 13:32
  • BTW, the question is unclear. You should give in it every command that you have run (under BSD and under Linux) and show exactly the disk partitionning and the mounted file systems. The first paragraph is suspicious. fsck is safe and reliable (but what you did probably is not). Don't suspect fsck but your own actions – Basile Starynkevitch Sep 16 '17 at 13:32
  • You may need to take a few days to learn more about OSes and filesystems. Read http://pages.cs.wisc.edu/~remzi/OSTEP/ ; you look confused and it does not appear you are fully understanding what is happening and what have you done. You certainly need to improve your question a lot (and add much more details in it, perhaps doubling the length of your question) – Basile Starynkevitch Sep 16 '17 at 13:39
  • 2
    Just a little side issue, why on earth are you formatting as ext2 (rather than, say, ext4) in 2017? – Chris Davies Sep 16 '17 at 13:40
  • @roaima this is from BSD ext2 page "In FreeBSD ext2, ext3 and ext4 are not different filesystems: ext2 is the base filesystem and some features from ext3 and ext4 are supported. All features in FreeBSD's implementation follow UFS semantics and this can sometimes impose important differences"

    I'm doing OS migration. Linux have ext4 native support so make sense to use ext4. but BSD is lacking in that department.

    – Satpal Parmar Sep 16 '17 at 13:49
  • The steps a) & B) in your second paragraph are not detailed enough. You should give the exact commands (and also show your disk partitionning), e.g. I ran foobar /dev/zwxy on Linux then rebooted BSD on the same computer then ran geedo /xyz on BSD. On Linux look also for output of dmesg and for recent lines in some /var/log/*.log files – Basile Starynkevitch Sep 16 '17 at 13:49
  • 1
    The question makes no mention of unmounting the EXT partition before rebooting FreeBSD. – JdeBP Sep 16 '17 at 14:02
  • 3
    Are you saying this is a dual boot server? Nowhere does that get made clear. In one breath you talk about UFS on FreeBSD and then you talk about ext2 on Linux. Coupled with all of that you throw in a reference to rsync. Please go back to your question and make it quite clear what exactly you are doing (or trying to do). – Chris Davies Sep 16 '17 at 14:30
  • @JdeBP I'm assuming when we issue 'reboot' all partition are unmounted by OS gracefully. Correct me if this assumption is wrong. – Satpal Parmar Sep 16 '17 at 15:48
  • @BasileStarynkevitch Will add more logs soon. My office network is under maintenance. – Satpal Parmar Sep 16 '17 at 15:49
  • You need to give all the exact commands you did (not only logs) – Basile Starynkevitch Sep 16 '17 at 15:56
  • 1
    You forgot sync and umount /backup on the BSD side, before the reboot – Basile Starynkevitch Sep 16 '17 at 17:07

2 Answers2

4

Why OS is asking to run fsck?

As some point in the past the filesystem was not unmounted cleanly. The system needs you to run fsck to clear up the inconsistencies.

What I'm doing wrong? I use rsync to move data.

Conceptually you're doing nothing wrong that I can see, except that you should run fsck (see above). It would be good to see your rsync command here, too.

How safe is running fsck? My box will not able to come up cleanly in case files are removed

The filesystem is in an inconsistent state. That might be simply that the filesystem wasn't marked as clean but is otherwise fine. At the other extreme the entire filesystem might be corrupted and you could theoretically lose everything. Most times the fsck only cleans out files that have already been deleted but haven't yet been removed from the filesystem.

Is there any way to log all operation done under fsck?

There are a number of options available to you. One is to use the command in its dry run mode (see man fsck and man e2fsck):

fsck -n /dev/mfid0p7

I would strongly recommend you do not use the automatic recovery flag, -p until you are happy with the fixes it is going to make.

Chris Davies
  • 116,213
  • 16
  • 160
  • 287
  • Thanks for your response. So we are not suspecting ext2 implementation incompatibilities as root cause of behavior. My migration was based on assumption that an 'ext2' partition is ext2 partition respective of which OS create or mount it. After above behavior I had doubts on my assumptions. – Satpal Parmar Sep 17 '17 at 02:38
  • @SatpalPatmar does FreeBSD require an explicit unmount of filesystems before a reboot? If so this could easily be the problem – Chris Davies Sep 17 '17 at 06:57
  • I'm not sure about that so I tried both ways I see no impact of mount/unmount. I even tried sysync;sync,syc before un-mounting. No impact again. – Satpal Parmar Sep 17 '17 at 11:56
2

a) Why OS is asking for fsck run. What I'm doing wrong?

fsck stands for "file system consistency check".

On most systems, fsck is run at boot time if certain conditions are detected. Usually, these conditions are:

  • A file system is marked as "dirty" — its written state is inconsistent with data that was scheduled to be written.
  • A file system has been mounted a set number of times without being checked.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

b) How safe is running fsck? My box will not able to come up cleanly in case files are removed.

Well it depends, if you enter yes when prompted to delete a wrong inode or block, you will lose data. That is why using the -p option might not be ideal.

Do not run fsck on a mounted filesystem! If you run fsck on a filesystem that is currently mounted, you will (at best) receive an error message, and (at worst) corrupt your filesystem data.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

c) Is there any way to log all operation done under fsck?

For the fsck check at boot time, you can check /var/log/boot.log Maybe your OS also has a /var/log/fsck not every Linux flavor has it.