17. August 2016

Linux Software Raid: Enlarge Raid Array of Hetzner EX41

Filed under: Linux,Server Administration — Tags: , , , , , , , , — Christopher Kramer @ 21:15

Recently, I ordered an EX41 server at Hetzner, which by default comes with two 4 TB HDDs in a software RAID1. I chose the minimal Debian Jessie Image. From Hetzner’s EX40, which has two 2 TB drives in a Software RAID1, I was used to find the whole drive formatted as one partition by Hetzner. But with the EX41, it turned out that the 4 TB were split: The root partition / was 2 TB of size and 1.7 TB were allocated to /home. As the application that should run on this server needs more than 2 TB space in one folder, I repartitioned the server. If somebody else has a similar issue, here is how it can be done:

1. Edit /etc/fstab and remove or comment (by placing a # at the beginning) the line that mounts /home from /dev/md3
2. Reboot into the Rescue system or some other system that is not on the same drive. (The Hetzner rescue system boots from network. On a local system, you would boot a linux from CD or USB.)
3. Check the Raid status and setup:
cat /proc/mdstat

md3 : active raid1 sda4[0] sdb4[1]
1777751872 blocks super 1.2 [2/2] [UU]
bitmap: 0/14 pages [0KB], 65536KB chunk

md2 : active raid1 sda3[0] sdb3[1]
2111700992 blocks super 1.2 [2/2] [UU]
bitmap: 0/16 pages [0KB], 65536KB chunk

md1 : active raid1 sda2[0] sdb2[1]
523712 blocks super 1.2 [2/2] [UU]

md0 : active raid1 sda1[0] sdb1[1]
16760832 blocks super 1.2 [2/2] [UU]

So here md3 is the raid array that we want to get rid of together with its partitions sda4 and sdb4. md2 the raid array that we want to grow in size.

4. First let’s get rid of the md3:
mdadm --stop /dev/md3
parted /dev/sda rm 4
parted /dev/sdb rm 4
5. Resize the partitions of md2 (sda3 and sdb3):

parted /dev/sda
(parted) resize 3
(END?) 4000GB
(parted) quit

parted /dev/sdb
(parted) resize 3
(END?) 4000GB
(parted) quit

Note: Tomas pointed out in the comments that the resize-command was removed and replaced with resizepart in current versions of parted. So the command is now:

parted /dev/sda
(parted) resizepart 3 4000GB
(parted) quit

(then do the same for sdb)

6. Let the raid array md2 grow:
mdadm --grow /dev/md2 --size=max
7. Check the raid status:
cat /proc/mdstat
Personalities : [raid1]
md2 : active raid1 sda3[0] sdb3[1]
3888815376 blocks super 1.2 [2/2] [UU]
[===================>.]  resync = 97.8% (3807048128/3888815376) finish=13.3min speed=101952K/sec
bitmap: 1/15 pages [4KB], 131072KB chunk
8. Wait until the resync finished (took a few hours for 2 TB):
cat /proc/mdstat
Personalities : [raid1]
md2 : active raid1 sda3[0] sdb3[1]
3888815376 blocks super 1.2 [2/2] [UU]
bitmap: 0/15 pages [0KB], 131072KB chunk
9. Check the filesystem:
e2fsck -fv /dev/md2
10. Resize the filesystem:
resize2fs /dev/md2
11. Reboot into your normal system and you are done:
reboot
12. Check the free disk space:
df -h

It should give the new size of / (3.6 TB) and a lot more free space 🙂

Hope this helps somebody with the same or similar issue.

Recommendation

Try my Open Source PHP visitor analytics script CrazyStat.

23. April 2013

Enlarge dynamic and fixed VHD virtual hard drives

Filed under: Windows — Tags: , , , , , , , , — Christopher Kramer @ 23:42

If you use Virtual PC or built-in Windows backup for example, you probably use virtual hard drives stored in vhd-files.

I already blogged once about how you can mount such a vhd file easily in Windows.

But there is one big problem with vhd files: When you create them, you often don’t really know how big the file should be. You can use a dynamic vhd to solve this partly (at the cost of performance), but still you need to give a maximum size.

And then the time will come when you realize your vhd needs to be bigger then you specified it. So here is how you can enlarge vhds – no matter whether they are fix sized or dynamic.

Enlarge vhd file using diskpart

You can enlarge the vhd file in diskpart. Start diskpart, e.g. with [Windows-Key]+[R], type “diskpart” and hit [enter]. UAC will prompt you for permission (say “Yes”). So now select your virtual disk using the following command:

select vdisk file="C:\path\to\vdisk.vhd"

Now enlarge the disk using this command:

expand vdisk maximum=10000

In this example, 10000 means that the new total size of the disk is 10 000 MB (adjust the number to your needs).

So now your virtual hard drive grew larger. But the partition inside still has the old size. So you need to enlarge the partition as well.

Enlarge the partition in the virtual disk using Disk management

The easiest way to do this is to use Windows Disk Management, which is part of Computer Management . The fastest way to get there in Windows 7 is to click the Windows icon and enter “Disk Management” and start the appearing “Windows Disc Management” (Windows UAC will again ask you for permission, say “Yes”). Or, also for other Windows version, [Windows]+[R] and type “diskmgmt.msc” and hit enter.

Open the VHD with “Action” / “Attach VHD”. Choose the file, make sure “readonly” is not checked and click “OK”.

Then you will see the VHD just like your normal drives in the graphical overview. There you will see the partition in blue (or dark green, if it is a logical one) and the empty space in light green. Right-click the partition and choose “Extend Volume”. The tool  will propose to use all the empty space so you can just accept that and that’s it. Finally, right click the VHD drive and select “Detach VHD”. Make sure you don’t select the option to delete the VHD file after detaching!

Enlarge the partition in the virtual disk using diskpart

You can also achieve the same thing in diskpart (i.e. on the console, not using the GUI).

Open diskpart, and mount the VHD using:

select vdisk file="C:\path\to\vdisk.vhd"
attach vdisk

Then do

list volume
select volume=<No of volume>
extend size=100

Instead of <No of volume>, you need to enter the number of the volume (see output of “list volume”).

In this example, the partition gets enlarged by 100 MB. Here you need to specify the relative amount of space that gets added.

Finally, detach the vdisk:

detach vdisk