On Fri, 17 Mar 2023, Nicolas George wrote:

Nicolas George (12023-03-17):
It is not vagueness, it is genericness: /dev/something is anything and
contains anything, and I want a solution that works for anything.

Just to be clear: I KNOW that what I am asking, the ability to
synchronize an existing block device onto another over the network with
only minimal downtime before and after, is possible, because I would be
capable of implementing it if I had a few hundreds hours on my hands and
nothing better to do with them.

What I am really asking is if the tool to do it already exists in some
way. Because I do not have a few hundreds hours on my hands, and if I
had, I would spend them finishing AVWriter, writing my TODO list
manager, implementing a re-connecting SOCKS proxy and a server for user
applications over websockets (and re-reading Tolkien and Mistborn and
Terre d'Ange).


Yes. It's possible. Took me about 5 minutes to work out the steps. All
of which are already mentioned upthread.

This is a very quick hacked together proof of concept script. Requires root to
run and you're on your own if it totally trashes something.

#!/bin/bash

md=/dev/md123

dd if=/dev/zero bs=1k count=10k of=dsk.1
dd if=/dev/zero bs=1k count=10k of=dsk.2

d1=$( losetup -f )
losetup ${d1} dsk.1

d2=$( losetup -f )
losetup ${d2} dsk.2

mke2fs -j ${d1}

echo "Mounting ${d1}"
mount ${d1} /mnt/fred
dd if=/dev/random of=/mnt/fred/signature bs=1k count=10k
ls -al /mnt/fred
umount /mnt/fred

mdadm --build ${md} --level=raid1 --raid-devices=2 ${d1} missing

echo "Mounting single disk raid"
mount ${md} /mnt/fred
ls -al /mnt/fred

mdadm ${md} --add ${d2}

sleep 10
echo "Done sleeping - sync had better be done!"

mdadm ${md} --fail ${d2}
mdadm ${md} --remove ${d2}

echo "Mounting ${d2}"
mount ${d2} /mnt/root
ls -al /mnt/root

diff /mnt/fred/signature /mnt/root/signature && echo "Comparison passed"

umount /mnt/root

umount /mnt/fred
mdadm --stop ${md}

losetup -d ${d1}
losetup -d ${d2}

exit 0

And here is the output:
# ./test.sh
10240+0 records in
10240+0 records out
10485760 bytes (10 MB, 10 MiB) copied, 0.0588102 s, 178 MB/s
10240+0 records in
10240+0 records out
10485760 bytes (10 MB, 10 MiB) copied, 0.0588907 s, 178 MB/s
mke2fs 1.44.5 (15-Dec-2018)
Discarding device blocks: done
Creating filesystem with 10240 1k blocks and 2560 inodes
Filesystem UUID: a5fc6516-d7ec-488e-a9be-6d01fc153c54
Superblock backups stored on blocks:
        8193

Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done

Mounting /dev/loop1
dd: error writing '/mnt/fred/signature': No space left on device
8755+0 records in
8754+0 records out
8964096 bytes (9.0 MB, 8.5 MiB) copied, 0.080614 s, 111 MB/s
total 8804
drwxr-xr-x  3 root root    1024 Mar 17 22:39 .
drwxr-xr-x 20 root root    1024 Oct  9 17:11 ..
drwx------  2 root root   12288 Mar 17 22:39 lost+found
-rw-r--r--  1 root root 8964096 Mar 17 22:39 signature
mdadm: array /dev/md123 built and started.
Mounting single disk raid
total 8804
drwxr-xr-x  3 root root    1024 Mar 17 22:39 .
drwxr-xr-x 20 root root    1024 Oct  9 17:11 ..
drwx------  2 root root   12288 Mar 17 22:39 lost+found
-rw-r--r--  1 root root 8964096 Mar 17 22:39 signature
mdadm: hot added /dev/loop2
Done sleeping - sync had better be done!
mdadm: set /dev/loop2 faulty in /dev/md123
mdadm: hot removed /dev/loop2 from /dev/md123
Mounting /dev/loop2
total 8804
drwxr-xr-x  3 root root    1024 Mar 17 22:39 .
drwxr-xr-x 20 root root    1024 Oct  9 17:11 ..
drwx------  2 root root   12288 Mar 17 22:39 lost+found
-rw-r--r--  1 root root 8964096 Mar 17 22:39 signature
Comparison passed
mdadm: stopped /dev/md123



So I have a full disk, I build it into an array and remount it. I then
add a spare disk, let the sync complete, fail and remove the disk and
then compare the random data file still on the mounted raid with the
file on the failed disk.

It depends on the sync completing in 10 seconds - otherwise you won't
get that "Comparison passed" - but given that this is 10MB on an SSD it
takes a fraction of a second to sync.

Tim.

Reply via email to