Re: How to resize RAID-1 partitions (mdraid)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sam Varshavchik wrote:

> The disk partitions are as follows:
> 
>   Device /dev/sda1 /boot  100 megabytes
> /dev/sda2 /     20 gigabytes
> /dev/sda3 swap - 6 gigs
> /dev/sda4 Extended partition
> /dev/sda5 /home -- remaining space, large
> 
> The layout of /dev/sdb is the same, and each partition on /dev/sda is in
> a RAID-1 array with its peer on /dev/sdb.
> 
> All partitions, except for /dev/sda4, have their types set to "Linux
> raid autodetect" in the partition table.
> 
> That small /boot is getting to be a pain, when updating Fedora. I
> originally wanted to shrink /home by 400-500 megabytes, getting some
> free space appear before it, shifting the remain partitions over, then
> adding the free space at the end of /boot.
> 
> But I just realized that I can simply shrink the swap partition by half
> a gig, or so, at its beginning, and move / up.
> 
> So, what I think I need to do is:
> 
> 1) Drop the swap partition
> 
> 2) Use mdadm --grow to reduce the size of /dev/md2 (RAID-1 joining
> /dev/sda3 and /dev/sdb3) by about a gigabyte
> 
> 3) Change the size of this partition in the partition table, make it
> smaller by about half a gig.
> 
> 4) Move the partition physically so that it ends where it used to end.
> 
> Can parted do 3 & 4? It's not clear to me what parted does with swap
> partitions, whether it just refuses to touch them, or just treats them
> as an opaque blob. I think it's better to move the partition together
> with its data. Even though this is swap, there's a RAID signature in
> there, and it'll probably be easier to just move the partition, as is,
> rather than me having to figure out how to completely drop and then
> create a new RAID-1 partition.
> 
> 5) Use mdadm --grow --size=max, to extend the size of the partition to
> whatever mdadm thinks it should be now, then mkswap-ing an empty swap
> partition on the raid device
> 
> 6) Move /dev/sd[ab]2 up. Parted can obviously do it.
> 
> 7) Change the size of the /dev/sd[ab]1 partitions.
> 
> 8) Use mdadm --grow --size=max to grow /dev/md0 to absorb the larger
> size of the underlying partitions.
> 
> 9) Use parted to grow /boot to the larger size of the /dev/md0 array.
> 
> What I don't understand is how to change the size of an existing
> partition without touching its contents. All the actual ext3 partitions
> are on the virtual /dev/mdX devices. Logically, they are not on the
> underlying partitions. parted's docs seem to suggest that parted will
> want to move the data in the partition around, when it resizes an
> existing partition. I think, if I understand its concepts correctly,
> that I need to do that on /dev/md, not on the /dev/sd partitions.
> However, it goes without saying that if I'm simply moving a partition on
> a disk, without changing its size, I need to obviously move the data in
> the partition, as is, accordingly.

I never used parted, so if I had to achieve what you want I'd try something
completely different.

Boot with some sort of rescue disk so you are not running from the disks.

Break the RAID eliminating the sdb partitions to be modified:
(md1 and md2 is my guess at the names)

mdadm /dev/md1 --fail /dev/sdb1
mdadm /dev/md2 --fail /dev/sdb2
mdadm /dev/md1 --remove /dev/sdb1
mdadm /dev/md2 --remove /dev/sdb2
mdadm /dev/md1 --grow -n 1
mdadm /dev/md2 --grow -n 1

So you now have md1 and md2 are a 1-disk RAID1, while md5 is still running
on two disks.

You now fdisk /dev/sdb: delete all the partitions and immediately recreate
them with the new sizes. Be sure that sdb4 and sdb5 are recreated with _exactly_
the same positions they had before. Do not use "fd" as type for sdb1 and sdb2,
for now. Now save the changes. The kernel will refuse to load the new partitions
in memory as your md5 is still using sda5 and sdb5.

So you reboot.

Now you have again md1 (degraded) md2 (degraded) and md5 (2 disks!) available.
Create two new degraded RAID devices:

mdadm --create /dev/md11 -l 1 -n 1 /dev/sdb1
mdadm --create /dev/md12 -l 1 -n 1 /dev/sdb2

(mdadm will also want "-f" because n=1 is unusal)

Now you can mkfs /dev/md11 and /dev/md12 and cp from /dev/md1 and /dev/md2
with proper options (I'm not sure if -a is enough for selinux labels, extattr...).
(alternatively: dd from md1 to md11, resizefs md11 to full; resizefs /dev/md2
to be smaller than md12, dd from md2 to md12, resizefs md12 to full)
[I don't like the alternative because you are touching md12 which is your "good"
copy; the cp will not take much more time than the dd and you will get a
free defragmentation]

Now mkswap /dev/sdb3.

At this point your system is almost perfectly able to run by
mounting md11 md12 and md5. If we switch sdb1 and sdb2 to type "fd" and reboot.
There is a complication with the md1 and md2 names which have changed, so
we avoid booting for now (mdadm --update could be used to change minor numbers).

After you are sure that md11 md12 and md5 correctfully contain your data,
you destroy and recreate the partitions on sda, just as we did for sdb.

The kernel refuses to load the new partitions table, so you reboot.

After reboot, md5 is still going with 2 disks, but md11 and md12 have to be
grown to 2 disks (--grow -n 2) and sda1 added to md11 and sda2 to md12.
Wait for the reconstruction to finish.

There is still the md11 md12 names you may want to fix. Do it now with
mdadm --update or just change your /etc/fstab and grub config to use
the new names.


It is less difficult that it seems and it will not take much time
because we avoided all copies and resyncs for sda5 and sdb5.

-- 
   Roberto Ragusa    mail at robertoragusa.it
-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux