How To Resize LVM Software RAID1 Partitions (Shrink & Grow)
How To Resize LVM Software RAID1 Partitions (Shrink & Grow)Version 1.0 This article describes how you can shrink and grow existing software RAID1 partitions with LVM on top (if you don't use LVM, please read this guide instead: How To Resize RAID Partitions (Shrink & Grow) (Software RAID)). I have tested this with logical volumes that use ext3 as the file system. I will describe this procedure for an intact RAID array and also a degraded RAID array. I do not issue any guarantee that this will work for you!
1 Preliminary NoteA few days ago I found out that one of my servers had a degraded RAID1 array (/dev/md1, made up of /dev/sda5 and /dev/sdb5; /dev/sda5 had failed, /dev/sdb5 was still active): server1:~# cat /proc/mdstat I tried to fix it (using this tutorial), but unfortunately at the end of the sync process (with 99.9% complete), the sync stopped and started over again. As I found out, this happened because there were some defect sectors at the end of the (working) partition /dev/sdb5 - this was in /var/log/kern.log: Nov 22 18:51:06 server1 kernel: sdb: Current: sense key: Aborted Command So this was the worst case that could happen - /dev/sda dead and /dev/sdb about to die. To fix this, I imagined I could shrink /dev/md1 so that it leaves out the broken sectors at the end of /dev/sdb5, then add the new /dev/sda5 (from the replaced hard drive) to /dev/md1, let the sync finish, remove /dev/sdb5 from the array and replace /dev/sdb with a new hard drive, add the new /dev/sdb5 to /dev/md1, and grow /dev/md1 again. This is one of the use cases for the following procedures (I will describe the process for an intact array and a degraded array). I have used two small hard drives (5GB) for this tutorial - that way I didn't have to wait that long for the resyncing to finish. Of course, on real systems you will have much larger hard drives. Please note that /dev/md1 contains the volume group /dev/server1 with the logical volumes /dev/server1/root (which is the system partition, mount point /) and /dev/server1/swap_1 (swap). Because I have to resize my system partition (/dev/server1/root), I have to use a rescue system (e.g. Knoppix Live-CD) to resize the array. If the array you want to resize does not contain your system partition, you probably don't need to boot into a rescue system; but in either case, make sure that the logical volumes are unmounted!
2 Intact ArrayI will describe how to resize the array /dev/md1, made up of /dev/sda5 and /dev/sdb5. This is the current situation: cat /proc/mdstat server1:~# cat /proc/mdstat df -h server1:~# df -h pvdisplay server1:~# pvdisplay vgdisplay server1:~# vgdisplay lvdisplay server1:~# lvdisplay
2.1 Shrinking An Intact ArrayBoot into your rescue system and activate all needed modules: modprobe md Then activate your RAID arrays... cp /etc/mdadm/mdadm.conf /etc/mdadm/mdadm.conf_orig mdadm -A --scan ... and start LVM: /etc/init.d/lvm start Run e2fsck -f /dev/server1/root to check the file system. /dev/md1 has a size of 5GB; I want to shrink it to 4GB. First we have to shrink the file system on the logical volume /dev/server1/root with resize2fs; the file system is inside the logical volume /dev/server1/root, so the filesystem should be <= the logical volume (therefore I make the file system 2GB). The logical volumes (LV - we have two of them, /dev/server1/root and /dev/server1/swap_1) again are inside the physical volume (PV) /dev/md1 (therefore LV /dev/server1/root + LV /dev/server1/swap_1 <= PV; I make LV /dev/server1/root 2.5GB and delete /dev/server1/swap_1, see next paragraph) which is on the RAID array /dev/md1 that we want to shrink (so PV <= /dev/md1; I shrink the PV to 3GB). As /dev/server1/swap_1 is at the end of our hard drive, we can delete it, shrink the PV and then create /dev/server1/swap_1 again to make sure that /dev/server1/root fits into our PV. If the swap LV is not at the end of your hard drive in your case, there's no need to delete it - you must make sure that you shrink the last LV on the drive enough so that it fits into the PV. So I shrink /dev/server1/root's filesystem to 2GB (make sure you use a big enough value so that all your files and directories fit into it!): resize2fs /dev/server1/root 2G ... and the /dev/server1/root LV to 2.5GB: lvreduce -L2.5G /dev/server1/root Then I delete the /dev/server1/swap_1 LV (not necessary if swap is not at the end of your hard drive - in this case make sure you shrink the last LV on the drive so that it fits into the PV!)... lvremove /dev/server1/swap_1 ... and resize the PV to 3GB: pvresize --setphysicalvolumesize 3G /dev/md1 Now we shrink /dev/md1 to 4GB. The --size value must be in KiBytes (4 x 1024 x 1024 = 4194304); make sure it can be divided by 64: mdadm --grow /dev/md1 --size=4194304 Now I grow the PV to the largest possible value (if you don't specify a size, pvresize will use the largest possible value): pvresize /dev/md1 Now let's check the output of vgdisplay root@Knoppix:~# vgdisplay As you see, we have 383 free PE, so we can recreate the /dev/server1/swap_1 LV (which had 66 PE before we deleted it): lvcreate --name swap_1 -l 66 server1 mkswap /dev/server1/swap_1 Let's check vgdisplay again: root@Knoppix:~# vgdisplay We still have 317 free PE, so we can extend our /dev/server1/root LV: lvextend -l +317 /dev/server1/root Now we resize /dev/server1/root's filesystem to the largest possible value (if you don't specify a size, resize2fs will use the largest possible value)... resize2fs /dev/server1/root ... and run a file system check again: e2fsck -f /dev/server1/root That's it - you can now boot into the normal system again. After the reboot you should see that /dev/md1 is now smaller: cat /proc/mdstat server1:~# cat /proc/mdstat df -h server1:~# df -h pvdisplay server1:~# pvdisplay vgdisplay server1:~# vgdisplay lvdisplay server1:~# lvdisplay
|
www.seamlessenterprise.com
One number. One voicemail. Seize the lead. Sprint Mobile Integration.
www.seamlessenterprise.com
One Number. One Voicemail.
Make it easier for clients to reach you. Turn your desk phone and mobile phone into one with Sprint Mobile Integration.
www.seamlessenterprise.com
One number. One voicemail. Sprint Mobile Integration.
www.seamlessenterprise.com
AT&T Synaptic Compute as a Service. Boost your power on demand.
Trial: IBM Cognos Express Reporting, Analysis & Planning
Learn benefits of Simpana software.
View the Gartner Video




print: 

Recent comments
2 hours 43 min ago
3 hours 37 min ago
7 hours ago
12 hours 20 min ago
12 hours 43 min ago
20 hours 24 min ago
20 hours 36 min ago
20 hours 55 min ago
22 hours 43 min ago
1 day 1 hour ago