Linux software RAID question

Notice: Page may contain affiliate links for which we may earn a small commission through services like Amazon Affiliates or Skimlinks.

voodooFX

Active Member
Jan 26, 2014
247
52
28
I have a software raid 1

Code:
root@storage:~# mdadm --detail /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Sun May  3 11:51:50 2015
     Raid Level : raid1
     Array Size : 468718592 (447.00 GiB 479.97 GB)
  Used Dev Size : 468718592 (447.00 GiB 479.97 GB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

  Intent Bitmap : Internal

    Update Time : Wed May  6 19:47:42 2015
          State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
  Spare Devices : 0

           Name : storage:0  (local to host storage)
           UUID : a585311b:b4238657:8f7f3e85:aef94019
         Events : 399

    Number   Major   Minor   RaidDevice State
       0       8        1        0      active sync   /dev/sda1
       1       8       17        1      active sync   /dev/sdb1
where I have created a ext4 partition during the install process.
now I need to wipe this partition and use the "device" md0 as block device backstore on LIO.

question: how can I wipe out the ext4 partition on md0?
 

TuxDude

Well-Known Member
Sep 17, 2011
616
338
63
You probably don't need to wipe it out - just make sure it isn't mounted or otherwize in use and give md0 to LIO.

If you do need to wipe it out, just write zero's over top of the partition table (first bit of the device). Again first make sure it isn't mounted/in use then 'dd if=/dev/zero of=/dev/md0 bs=1M count=10' will zero the first 10MB of the device, which is enough to overwrite MBRs, partition tables, small utility partitions (eg couple MB EFI), and the super-blocks or other important bits at the start of the first real filesystem. Increase the count if you want to zero even more (or leave the count option off completely to zero the entire device) but 10MB is usually more than enough and finishes very fast.

Note that using DD to wipe out partitions/filesystems/etc does NOT notify the kernel about the change, so you might still see devices referencing the partition (eg. if you use DD to zero /dev/sda the kernel will still think /dev/sda1, /dev/sda2, etc. exist). Easiest method to deal with that is just reboot.
 

voodooFX

Active Member
Jan 26, 2014
247
52
28
Hi TuxDude.

The volume is already unmounted but since I never did this before I was wondering if it will be sort of "dirty" work doing just the unmount; I mean, since the ext4 partition is not really removed, what if I try to remount it after some time I gave the dev to LIO as backstore? It will work? I will get corruption? Mount error?
Zeroing (part of) the device is a good idea (thanks) but is there an official way to manage filesystems on mdX devices? What if I would like to create another fs, for example xfs or a logical volume?
 

TuxDude

Well-Known Member
Sep 17, 2011
616
338
63
The volume is already unmounted but since I never did this before I was wondering if it will be sort of "dirty" work doing just the unmount; I mean, since the ext4 partition is not really removed, what if I try to remount it after some time I gave the dev to LIO as backstore? It will work? I will get corruption? Mount error?
Depends what was done to it while it was used as a LIO backstore. If it was presented back out as eg. an iSCSI device to another linux box, that other box would see and be able to mount the ext4 filesystem on that device - later if you stopped LIO you could mount it locally again, containing all of the changes that were made to it. On the other hand if you used LIO to present it to a windows box, and from there you wrote an NTFS filesystem onto it, your chances of ever mounting it as ext4 again are slim to none. LIO itself isn't going to do anything with the data on the device.

Zeroing (part of) the device is a good idea (thanks) but is there an official way to manage filesystems on mdX devices? What if I would like to create another fs, for example xfs or a logical volume?
A MD device is no different than any other block device, say a regular HDD. Have you ever had to do anything special to replace an ext4 filesystem with xfs on a regular HD? Nope, you just format the device with the new one, overwriting whatever used to be there. Same thing on a MD device - make sure its not in use, and over-write whatever happens to be there with whatever new thing you want. Whether that is overwriting ext4 with LVM2 Physical Volume metadata, or overwriting zero's with an xfs filesystem, doesn't matter. Whether it is a local SATA disk, a local MD device, or a LVM volume built on top of a MD array built out of remote iSCSI devices also doesn't matter.

The only thing that sometimes matters is notifying the kernel that partition tables have changed. That can be done with a reboot, or by running 'partprobe'. My preference is to simply not use a partition table most of the time and not have to deal with that issue at all. I partition my boot drive (typically into a small UEFI/Grub utility partition, a 1GB ext2 /boot that is not mounted by default, and the remainder mounted at /) and usually never touch that partition table again, and then for all additional data drives I just use the raw devices (so /dev/sdb instead of /dev/sdb1) - if I need to carve things up or stuff like that I make the raw device an LVM PV, and use LVM instead of partition tables to do my carving (or spanning, striping, etc. that LVM can do but partition tables can't)
 
  • Like
Reactions: voodooFX

voodooFX

Active Member
Jan 26, 2014
247
52
28
OK now I'ts clear!
LIO is just passing through the device, then will be the initiator to format it (in my case esxi will format the device as VMFS).

Thank you very much Tux :)