Tuesday, 16 December 2014

Resize root file system for vm on ODA Version 2.10


How to resize the root partition inside a VM image running on ODA (Oracle Database Appliance) 

In this article we are using the resize2fs program. It will resize ext2, ext3 file systems. 
This article is not applicable if you want resize an ext4 partition as resize4fs & e4fsck tools are needed 

In this example we have a small Oracle Enterprise Linux image 
# ls -slh /OVS/Repositories/odarepo2/VirtualMachines/oel_5.8/*.img 
15G -rw-r--r-- 1 root root 14G Jan 30 01:44 /OVS/Repositories/odarepo2/VirtualMachines/oel_5/oel_5.8.img 

Inside the image we have the following partitions: 
Device Boot Start End Blocks Id System 
/dev/xvda1 * 1 13 104391 83 Linux 
/dev/xvda2 14 1305 10377990 83 Linux 
/dev/xvda3 1306 1827 4192965 82 Linux swap / Solaris 

and We want to make /dev/xvda2 (/ root partition) bigger. 
Note1: the following steps are not applicable if you want make /dev/xvda1 (/boot partition) bigger as you will overwrite the root partition. 
Note2: enlarging root partition you will overwrite the next partition. In this case it's not a problem as it's the swap partition. 
Steps 
1. Make sure the VM is down 
# xm list 
Name ID Mem VCPUs State Time(s) 
Domain-0 0 2039 24 r----- 356182.2 
oakDom1 2 65536 16 r----- 378770.2 

note as from the above command your VM is not listed, if it's present you should stop it using xm 
2. Create a new sparse file 

To create a new file we need to have enough space on the shared repositories.

check if you have enough space in ASM

[root@oda_base1 ~]# su - grid
[grid@oda_base1 ~]$ . oraenv
ORACLE_SID = [grid] ? +ASM1
The Oracle base has been set to /u01/app/grid
[grid@oda_base1 ~]$ asmcmd
ASMCMD> lsdg
State    Type  Rebal  Sector  Block       AU  Total_MB  Free_MB  Req_mir_free_MB  Usable_file_MB  Offline_disks  Voting_files  Name
MOUNTED  HIGH  N         512   4096  4194304   7372800  4006144           737280         1089621              0             Y  DATA/
MOUNTED  HIGH  N         512   4096  4194304   9796800  7060676           979680         2026998              0             N  RECO/
MOUNTED  HIGH  N         512   4096  4194304    763120   762728           381560          127056              0             N  REDO/
ASMCMD>

Take existing snapshot of space available in shared repository.

[grid@oda_base1 ~]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda2             55G   19G   34G  36% /
/dev/xvda1            460M   24M  413M   6% /boot
/dev/xvdb1             92G   31G   57G  36% /u01
tmpfs                  32G  231M   32G   1% /dev/shm
/dev/asm/acfsvol-264   50G  7.5G   43G  15% /cloudfs
/dev/asm/oemvmrepo-264
                      200G   37G  164G  19% /u01/app/sharedrepo/oemvmrepo
/dev/asm/u02p9007-87  300G   38G  263G  13% /u02p9007
/dev/asm/u02p9008-87  300G   30G  271G  10% /u02p9008
/dev/asm/misp9008-87   50G  240M   50G   1% /misp9008
/dev/asm/misp9007-87   50G  242M   50G   1% /misp9007

Get details for shared repository:

[grid@oda_base1 ~]$ /sbin/advmutil volinfo /dev/asm/oemvmrepo-264
Device: /dev/asm/oemvmrepo-264
Interface Version: 1
Size (MB): 204800
Resize Increment (MB): 32
Redundancy: high
Stripe Columns: 4
Stripe Width (KB): 128
Disk Group: RECO
Volume: OEMVMREPO
Compatible.advm: 11.2.0.4.0

Extend the shared repository by 300G

[grid@oda_base1 ~]$
[grid@oda_base1 ~]$ /sbin/acfsutil size +300G /u01/app/sharedrepo/oemvmrepo
acfsutil size: new file system size: 536870912000 (512000MB)

Confirm the extended space is added to the file system:

[grid@oda_base1 ~]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda2             55G   19G   34G  36% /
/dev/xvda1            460M   24M  413M   6% /boot
/dev/xvdb1             92G   31G   57G  36% /u01
tmpfs                  32G  231M   32G   1% /dev/shm
/dev/asm/acfsvol-264   50G  7.5G   43G  15% /cloudfs
/dev/asm/oemvmrepo-264
                      500G   38G  463G   8% /u01/app/sharedrepo/oemvmrepo
/dev/asm/u02p9007-87  300G   38G  263G  13% /u02p9007
/dev/asm/u02p9008-87  300G   30G  271G  10% /u02p9008
/dev/asm/misp9008-87   50G  240M   50G   1% /misp9008
/dev/asm/misp9007-87   50G  242M   50G   1% /misp9007
[grid@oda_base1 ~]$
[grid@oda_base1 ~]$



Create a new sparse file (in this example 50G) 
cd /OVS/Repositories/odarepo2/VirtualMachines/oel_5.8/ 
dd if=/dev/zero of=NEW_oel_5.8.img bs=1 count=1024 seek=50GB 
# ls -lhs 
total 5.1G 
1.1M -rw-r--r-- 1 root root 50G Jan 30 02:21 NEW_oel_5.8.img 
5.1G -rw-r--r-- 1 root root 5.0G Jan 30 01:44 oel_5.8.img 
4.0K -rw-r--r-- 1 root root 496 Jan 30 01:23 vm.cfg 
3. Copy the old image on the new 
# dd if=oel_5.8.img of=NEW_oel_5.8.img conv=notrunc 

29360128+0 records in 
29360128+0 records out 
15032385536 bytes (15 GB) copied, 464.842 seconds, 32.3 MB/s 
# ls -slh /OVS/Repositories/odarepo2/VirtualMachines/oel_5.8/*.img 
15G -rw-r--r-- 1 root root 14G Jan 30 01:44 /OVS/Repositories/odarepo2/VirtualMachines/oel_5/oel_5.8.img 
11G -rw-r--r-- 1 root root 47G Jan 30 01:44 /OVS/Repositories/odarepo2/VirtualMachines/oel_5/NEW_oel_5.8.img 
4. Rename the new image 

You may take a backup of your old image 
cd /OVS/Repositories/odarepo2/VirtualMachines/oel_5.8 
mv oel_5.8.img oel_5.8.img_OLD 
mv NEW_oel_5.8.img oel_5.8.img 
5. Resize the fs 

You need to use "xm block-attach": 

modprobe xenblk 
xm block-attach 0 'file:/path/to/image/file' xvda w 

ie: 

# modprobe xenblk 
# xm block-attach 0 'file:/OVS/Repositories/odarepo2/VirtualMachines/oel_5.8/oel_5.8.img' xvda w 

This will create new device files /dev/xvda (the hole disk) and the partitions you have /dev/xvdaX where X is the partition number 
ie: 

# ls -l /dev/xvda* 
brw-r----- 1 root disk 202, 0 Jan 30 03:26 /dev/xvda 
brw-r----- 1 root disk 202, 1 Jan 30 03:26 /dev/xvda1 # in this example this is the boot partition 
brw-r----- 1 root disk 202, 2 Jan 30 03:26 /dev/xvda2 # in this example this is the root partition 
brw-r----- 1 root disk 202, 5 Jan 30 03:26 /dev/xvda5 # in this example this is the extended swap partition 

In this case the root partition is using Ext3 and it can not be resize but ext2 can. So we need to convert the partition ext3 to ext2. The conversion is basically done disabling journal on ext3. Remove the journal on ext3 doing: 
tune2fs -O ^has_journal /dev/xvdb2 

You can now use any partition editor you want to expand the first partition on /dev/xvda. 
For example using fdisk: 
# fdisk /dev/xvda 

The number of cylinders for this disk is set to 6527. 
There is nothing wrong with that, but this is larger than 1024, 
and could in certain setups cause problems with: 
1) software that runs at boot time (e.g., old versions of LILO) 
2) booting and partitioning software from other OSs 
(e.g., DOS FDISK, OS/2 FDISK) 

Command (m for help): p 

Disk /dev/xvda: 53.6 GB, 53687091200 bytes 
255 heads, 63 sectors/track, 6527 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes 

Device Boot Start End Blocks Id System 
/dev/xvda1 * 1 13 104391 83 Linux 
/dev/xvda2 14 1305 10377990 83 Linux 
/dev/xvda3 1306 1827 4192965 82 Linux swap / Solaris 

Command (m for help): d 
Partition number (1-4): 3 

Command (m for help): d 
Partition number (1-4): 2 

Command (m for help): n 
Command action 
e extended 
p primary partition (1-4) 

Partition number (1-4): 2 
First cylinder (14-6527, default 14): 
Using default value 14 
Last cylinder or +size or +sizeM or +sizeK (14-6078, default 6078): +46G 

Command (m for help): n 
Command action 
e extended 
p primary partition (1-4) 

Partition number (1-4): 3 
First cylinder (5608-6078, default 5608): 
Using default value 5608 
Last cylinder or +size or +sizeM or +sizeK (5608-6078, default 6078): 
Using default value 6078 

Command (m for help): p 

Disk /dev/xvda: 50.0 GB, 50000001024 bytes 
255 heads, 63 sectors/track, 6078 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes 

Device Boot Start End Blocks Id System 
/dev/xvda1 * 1 13 104391 83 Linux 
/dev/xvda2 14 5607 44933805 83 Linux 
/dev/xvda3 5608 6078 3783307+ 83 Linux 

Command (m for help): t 
Partition number (1-4): 3 
Hex code (type L to list codes): 82 
Changed system type of partition 3 to 82 (Linux swap / Solaris) 

Command (m for help): p 

Disk /dev/xvda: 50.0 GB, 50000001024 bytes 
255 heads, 63 sectors/track, 6078 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes 

Device Boot Start End Blocks Id System 
/dev/xvda1 * 1 13 104391 83 Linux 
/dev/xvda2 14 5607 44933805 83 Linux 
/dev/xvda3 5608 6078 3783307+ 82 Linux swap / Solaris 

Command (m for help): w 
The partition table has been altered! 

Calling ioctl() to re-read partition table. 
6. Resize the filesystem 

Now your disk image has new partition size, we need to resize the filesystem as well 

a. execute e2fsck required for resizefs 
# e2fsck -f /dev/xvda2 
e2fsck 1.39 (29-May-2006) 
Pass 1: Checking inodes, blocks, and sizes 
Pass 2: Checking directory structure 
Pass 3: Checking directory connectivity 
Pass 4: Checking reference counts 
Pass 5: Checking group summary information 
/: 133248/2490880 files (1.8% non-contiguous), 839840/2594497 blocks 

b. run resisefs 
# resize2fs /dev/xvda2 
resize2fs 1.39 (29-May-2006) 
Resizing the filesystem on /dev/xvda2 to 11233451(4k) blocks. 

The filesystem on /dev/xvda2 is now 11233451 blocks long. 

c. Turn on the ext3 journal 
tune2fs -j /dev/xvdb2 

d. When you are done, use "xm block-detach" to release the virtual disk: 
# xm block-detach 0 /dev/xvda 



You can now startup the VM with the resized disk. Once the VM is up & running you could verify the new disk size using the "df -h" command 


Optional step 
Check the new size within dom-0 

1. Mount the root partition of new disk image 

Due to disk partitions we need to skeep the blocks for the /boot partition: 
# file ./E1_X86_SYS_913.img 
./E1_X86_SYS_913.img: x86 boot sector; 
partition 1: ID=0x83, active, starthead 1, startsector 63, 208782 sectors; 
partition 2: ID=0x83, starthead 0, startsector 208845, 89867610 sectors; 
partition 3: ID=0x82, starthead 254, startsector 90076455, 7566615 sectors, code offset 0x48 

To mount a single partition, where X is the startsector of that partition, run: 
mount -o loop,offset=$((X*512)) /OVS/Repositories/odarepo2/VirtualMachines/oel_5.8/oel_5.8.img /mnt 

example: 
mount -o loop,offset=$((208845*512)) /OVS/Repositories/odarepo2/VirtualMachines/oel_5.8/oel_5.8.img /mnt 

2. Check the new size 
df -h 
# df -h 
Filesystem Size Used Avail Use% Mounted on 
/dev/md1 19G 1.2G 17G 7% / 
tmpfs 942M 0 942M 0% /dev/shm 
/dev/md3 519G 519G 0 100% /OVS 
/dev/md0 99M 35M 60M 37% /boot 
none 942M 144K 942M 1% /var/lib/xenstored 
/OVS/Repositories/odarepo2/VirtualMachines/oel_5.8/oel_5.8.img 
42G 3.0G 39G 7% /mnt 

3. Umount the filesystem 
umount /mnt 


Start the vm from oda_base using 

oakcli start vm

Verify you have the extended space using df -h


[root@VM1]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda2            285G   23G  248G   9% /
tmpfs                  32G     0   32G   0% /dev/shm
/dev/xvda1            487M   75M  387M  17% /boot


No comments:

Post a Comment