Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] Shrink linear RAID array
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
nick_gentoo
n00b
n00b


Joined: 07 Jan 2019
Posts: 74

PostPosted: Mon Feb 11, 2019 6:23 am    Post subject: [SOLVED] Shrink linear RAID array Reply with quote

This is the first time I am trying to handle anything RAID.
I plan to repurpose a disk from an older embedded NAS. The drive is configured as a linear RAID array (well, a 1-partition array). I would like remove the RAID array and to keep the data on it. Given that it's ~30% full, I would like to know if it is possible to do this in-place, without copying the data somewhere else first, with a sequence like this:
  • shrink the array (?)
  • create a partition in the new free space
  • move the data to the new partition
  • delete the array
  • expand the new partition to fill the drive
After reading some things about it, I started by shrinking the filesystem inside the array. Now I am trying to shrink the array itself, but
Code:
mdadm --grow /dev/md127 --size=1000G
mdadm: Cannot set device size in this type of array.

Is this even possible, or should it be done another way?

LE: I do have a backup of the data, so wiping the full disk is not a problem in case nothing else works, but I'm also using the chance to try/learn something new.


Last edited by nick_gentoo on Thu Feb 14, 2019 6:02 am; edited 2 times in total
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 44182
Location: 56N 3W

PostPosted: Tue Feb 12, 2019 9:16 pm    Post subject: Reply with quote

nick_gentoo,

There are several layers here.

There is the filesystem, which you have already shrunk.
There is the raid metadata, whicd you need to change to be able to free space.
There is the underlying partition(s) holding the raid, which you also need to shrink.

What does
Code:
mdadm -E /dev/sd...
for the underlying partition tell ?

If the raid metadata is ver=0.9 its trivial to remove the raid and keep the data.
The raid metadata follows after the user data and the filesystem start is where it would be were raid not present.
You remove the metadata and the remaining filesystem just works.

With ver=1.2 metadata, the metadata is before the users space, so you either keep the raid or rewrite the filesystem to move it down the drive.

Anyway, that mdadm command will tell all.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
nick_gentoo
n00b
n00b


Joined: 07 Jan 2019
Posts: 74

PostPosted: Tue Feb 12, 2019 10:13 pm    Post subject: Reply with quote

Neddy, thank you! I think I already have an idea now about how to do it.

I spent a little time to understand the different layers when I started to look into this, and I think I understand (most of) it now. But the mdadm man page is long and I did not look in detail at everything.

So, mdadm -E shows
Code:
Version : 0.90.00

Searching a bit more after finding about the metadata, it looks like
Code:
mdadm --zero-superblock
is the way to do it - is this right?
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 44182
Location: 56N 3W

PostPosted: Tue Feb 12, 2019 10:54 pm    Post subject: Reply with quote

nick_gentoo,

Yes, that's it an long as the
Code:
entire mdadm -E ...
shows that only a single block device is in the raid set.
That's mostly why i wanted to see it.

If you mess up and your data vanishes because removing the raid superblock removes the pointers to it, you will need all of the mdadm -E output to recreate the raid superblock.
Keep a copy, even if you don't post it :)

Note that its not an error to donate several block devices on the same spindle to a raid set.
Yep, you can even make a raid5 with three partitions on the same drive. mdadm will shout at you but do it and it operates.
If you have a linear raid made up of several partitions on the same drive, mdadm --zero-superblock, will destroy the pointers to your data.
Then you need mdadm --create <define every parameter> to rewrite the raid metadata.

You can test safely. Stop the raid. Then
Code:
mount -o ro /dev/sd... /mnt/someplace
will mount the filesystem without using raid. sd.. is whatever the underlying block device for the raid is.
Its read only in case something horrible happens.
If all is well, all your data will be there.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
nick_gentoo
n00b
n00b


Joined: 07 Jan 2019
Posts: 74

PostPosted: Wed Feb 13, 2019 6:23 am    Post subject: Reply with quote

There is nothing secret about the mdadm output, I just assumed that it wouldn't bring other relevant info. But assumption is the mother of...various things, so here it is
Code:
mdadm -E /dev/sda2

/dev/sda2:
          Magic : a92b4efc
        Version : 0.90.00
           UUID : 90b3e611:ee383fd4:2c92bc03:ae677930
  Creation Time : Thu Nov 29 19:47:46 2012
     Raid Level : linear
   Raid Devices : 1
  Total Devices : 1
Preferred Minor : 0

    Update Time : Thu Nov 29 19:47:46 2012
          State : active
 Active Devices : 1
Working Devices : 1
 Failed Devices : 0
  Spare Devices : 0
       Checksum : a481ea1a - correct
         Events : 1

       Rounding : 64K

      Number   Major   Minor   RaidDevice State
this     0       8        2        0      active sync   /dev/sda2

   0     0       8        2        0      active sync   /dev/sda2

Trying now to stop the raid and mount the underlying partition, I get this
Code:
# mdadm --stop /dev/md127
mdadm: stopped /dev/md127
# mount -o ro /dev/sda2 /mnt/test/
mount: /mnt/test: unknown filesystem type 'linux_raid_member'.

From your explanation I understand why this should work, and this seems to be the kind of error people have when trying to mount separately one disk of a higher-level array. What could be the problem here?

Edit: ...and I found why. Even with the array stopped, mount probably sees its metadata first, before looking for the filesystem. So it works when the filesystem is also specified
Code:
mount -t ext4 -o ro /dev/sda2 /mnt/test/

Then I saw something interesting. I use GParted for the partitioning operations. In this case it sees the RAID array even after it was stopped, and does not allow any move/resize operations on the underlying partition. However, parted run from the command line only sees the sda2 device (even with the array running) and I suppose it would allow a resize.


Last edited by nick_gentoo on Wed Feb 13, 2019 6:42 pm; edited 1 time in total
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 44182
Location: 56N 3W

PostPosted: Wed Feb 13, 2019 6:39 pm    Post subject: Reply with quote

nick_gentoo,

Mount has got cleverer. It didn't always check for raid members.

Go ahead an destroy the raid superblock, if you haven't already.
You know its safe now.

If the partition table is tagged as type 0xED, so that raid auto assembly is trigged at boot, you may want to change that to 0x82/0x83.
One Is Linux, the other is swap. I forget which is which.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 14379

PostPosted: Thu Feb 14, 2019 2:18 am    Post subject: Reply with quote

82 is Linux swap or Solaris data. 83 is Linux filesystem.

https://en.wikipedia.org/wiki/Partition_type#PID_82h
Back to top
View user's profile Send private message
nick_gentoo
n00b
n00b


Joined: 07 Jan 2019
Posts: 74

PostPosted: Thu Feb 14, 2019 6:12 am    Post subject: Reply with quote

And it worked, the filesystem can be mounted after a final
Code:
mdadm --zero-superblock /dev/sda2
Thank you for the help!

Now I'm also curious about what could I have done if the metadata was not version 0.90 - shift the whole filesystem within the partition with dd?
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 44182
Location: 56N 3W

PostPosted: Thu Feb 14, 2019 7:13 pm    Post subject: Reply with quote

nick_gentoo,

If you are a purist, back up the data from the filesystem, delete both the raid and filesystem.
Recreate the filesystem, then restore the data.

A pragmatist would delete the partition from the partition table, which is totally harmless to the data, then rewrite the partition table entry with the same end sector but the start sector moved forward to point to the start of the filesystem, abandoning the raid metadata at the front of the partition.
Discovering the size of the raid metadata is left as an exercise for the reader.

Its safe to test this with the offset= option to mount. See man mount, so trial and error won't take long.
You don't actually need a partition table to mount the filesystems in the partition table, offset= lets you pass a byte offset from the start of the device.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
nick_gentoo
n00b
n00b


Joined: 07 Jan 2019
Posts: 74

PostPosted: Thu Feb 14, 2019 9:14 pm    Post subject: Reply with quote

I was really amazed to learn about the offset= option!
This and only updating the partition table sounds much simpler than what I had in mind.
I had used dd before for various things and when the only tool you know is a hammer... But now I have a bigger toolbox :)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum