Resizing a logical volume on Oracle Enterprise Linux (OEL) 5.6


I was running OEL 5.6 as the guest OS on VMWare hosted in a Fedora machine.
The machine had a 20Gb virtual disk and I had initially allocated about 11Gb to the root system.
I know it is not within best practice, but I was doing some quick configuration tests with Oracle so I had decided to install software and database files in the root file system.
Well, a couple of oracle releases later I had run out of space in the file system.


So the scenario was:
  1. The VM had a 20Gb disk allocated, but
  2. The disks partitions were only about 12Gb big, divided in two logical volumes: lv00 mapped to the root file system and lv01 used by the swap file system.
  3. Its usually pretty easy to extend a file system. Just unmount it and run a couple of commands. But you can't unmount the root file system and keep the system going.

(?) So how to extend the logical volume and the file system?
  • Well, it turns out that this can be done without having to unmount the root file system for systems with a 2.6 kernel. You just need to use lvextend and resize2fs.

Here is some output of the initial scenario:
jdoe@quark # fdisk -l

Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          19      152586   83  Linux
/dev/sda2              20        2610    20812207+  8e  Linux LVM

Disk /dev/dm-0 doesn't contain a valid partition table

Disk /dev/dm-1: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/dm-1 doesn't contain a valid partition table

jdoe@quark # df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VG00-LV00
                       12G   11G     0 100% /
/dev/sda1             145M   20M  118M  15% /boot
tmpfs                 944M     0  944M   0% /dev/shm

The output of vgdisplay:
jdoe@quark # vgdisplay
--- Volume group ---
VG Name               VG00
System ID             
Format                lvm2
Metadata Areas        1
Metadata Sequence No  3
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                2
Open LV               2
Max PV                0
Cur PV                1
Act PV                1
VG Size               19.84 GB
PE Size               32.00 MB
Total PE              635
Alloc PE / Size       439 / 13.72 GB
Free  PE / Size       196 / 6.12 GB
VG UUID               y8WrXG-06ej-erEH-k3QV-fqvy-VJ8O-1hV4uT

The output of pvscan:
jdoe@quark # pvscan
PV /dev/sda2   VG VG00   lvm2 [19.84 GB / 6.12 GB free]
Total: 1 [19.84 GB] / in use: 1 [19.84 GB] / in no VG: 0 [0   ]

Solution:
  • Since the total disk space on /dev/sda was already allocated to the Volume group,
    what I needed to do was just to extend the logical volume to use the free space in the volume group.

jdoe@quark # lvextend -l+196 /dev/VG00/LV00
Extending logical volume LV00 to 17.84 GB
Logical volume LV00 successfully resized
jdoe@quark #
jdoe@quark # resize2fs /dev/VG00/LV00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VG00/LV00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VG00/LV00 to 4677632 (4k) blocks.
The filesystem on /dev/VG00/LV00 is now 4677632 blocks long.

And that did it.
Here are some printouts of the final scenario:
jdoe@quark # fdisk -l

Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          19      152586   83  Linux
/dev/sda2              20        2610    20812207+  8e  Linux LVM

jdoe@quark # df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VG00-LV00
                       18G   11G  5.7G  66% /
/dev/sda1             145M   20M  118M  15% /boot
tmpfs                 944M     0  944M   0% /dev/shm

jdoe@quark # vgdisplay
--- Volume group ---
VG Name               VG00
System ID             
Format                lvm2
Metadata Areas        1
Metadata Sequence No  4
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                2
Open LV               2
Max PV                0
Cur PV                1
Act PV                1
VG Size               19.84 GB
PE Size               32.00 MB
Total PE              635
Alloc PE / Size       635 / 19.84 GB
Free  PE / Size       0 / 0   
VG UUID               y8WrXG-06ej-erEH-k3QV-fqvy-VJ8O-1hV4uT

Mounting an NTFS filesystem on Oracle Enterprise Linux


To access an NTFS file system from Linux (OEL) you need either:
  • (a) need to have NTFS support compiled in the kernel or
  • (b) need to download and install packages that allow NTFS file systems to be mounted in userspace

Historically, few of the Linux distributors have ship with out-of-the-box support for NTFS file systems. As pointed out here, while there is a lot of public information about about MSDOS and VFAT, Microsoft has not published much details of NTFS, so the implementations vary in stability and features.

Initially you should check whether NTFS modules are already installed on your system.
$ ls -l /lib/modules/2.6.32-35-generic/kernel/fs/ | grep ntfs
drwxr-xr-x 2 root root  4096 2011-11-08 09:12 ntfs
In case no modules are found, you need to download and install NTFS packages.
  • NTFS-3G is an open source implementation of Microsoft's NTFS file system that includes read and write support.
  • NTFS-3G developers use the FUSE file system to facilitate development and to help with portability

Step 1: Download fuse and ntfs-3g
fuse: get it from http://www.atrpms.net/dist/el5/fuse/ or http://sourceforge.net/projects/fuse/files/fuse-2.X/
ntfs-3g: You can download it from http://pkgs.repoforge.org/fuse-ntfs-3g/

Step 2: Install fuse components
# yum install fuse
Loaded plugins: rhnplugin, security
This system is not registered with ULN.
ULN support will be disabled.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package fuse.i386 0:2.7.4-8.el5 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved
================================================================================================
Package            Arch             Version             Repository           Size
================================================================================================
Installing:
fuse               i386             2.7.4-8.el5         ol5_u6_base          84 k

Transaction Summary
================================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 84 k
Is this ok [y/N]: y
Downloading Packages:
fuse-2.7.4-8.el5.i386.rpm                                                  |  84 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: fuse    1/1 
Installed: fuse.i386 0:2.7.4-8.el5                                                                                                      

Complete!
#
  • If you can't perform a yum installation, you can try installing fuse from your OEL media or performing a manual installation with the package downloaded from forgesource, as described here.

Step 3: Install fuse-ntfs-3g
# rpm -Uvh fuse-ntfs-3g-2010.5.22-1.el5.rf.i386.rpm 
warning: fuse-ntfs-3g-2010.5.22-1.el5.rf.i386.rpm: Header V3 DSA signature: NOKEY, key ID 6b8d79e6
Preparing...                ########################################### [100%]
1:fuse-ntfs-3g           ########################################### [100%]

Step 4: Mount the NTFS file system.
  • Once installed, reconnect the device and OEL should recognize it automatically
# mount.ntfs-3g  

Oracle DBMS_FLASHBACK package




Oracle Flashback technology
Logical Flashback (do not depend on RMAN, rely on undo data)
Physical flashback
New on Oracle 11g:




Using DBMS_FLASHBACK package
  • Released with Oracle 9i
  • Provides the same functionality as Oracle Flashback Query (Oracle 10g)
  • Acts as a time machine:
    • 1. set time to a previous point in time.
    • 2. perform queries without the "AS OF" and "VERSIONS BETWEEN" clauses
    • 3 return time to the "present"

Requirements:
  • You need EXECUTE privilege on DBMS_FLASHBACK package
  • The UNDO_RETENTION parameter defines how far back in time an object can be flashbacked.
  • UNDO_RETENTION can be set in the init.ora or with:
  • ALTER SYSTEM SET UNDO_RETENTION = num_seconds;

Using the DBMS_FLASHBACK package:
  1. Specify a past time with DBMS_FLASHBACK.ENABLE_AT_TIME or DBMS_FLASHBACK.ENABLE_AT_SYSTEM_CHANGE_NUMBER.
  2. Perform regular queries (queries without flashback-feature syntax such as AS OF).
    Do not perform DDL or DML operations.
  3. Return to the present by invoking DBMS_FLASHBACK.DISABLE.
(a) Check current data in the emp table

SQL> select * from emp;

 EMPNO                  EMPNAME    SALARY                 
---------------------- ---------- ---------------------- 
2                      Mary       4000                   
1                      Jack       101140                 
100                    Joseph     900      

SQL> select current_scn, to_char(systimestamp, 'MM-DD-YY HH24:MI:SS') date_time
     from v$database;
CURRENT_SCN            DATE_TIME         
---------------------- ----------------- 
1432709                12-08-10 10:58:45  

(b) modify data in emp table

SQL> Insert into emp values (3, 'Mark', 5000);
SQL> commit;

SQL> Update emp set salary = 0 where empno=1;
SQL> commit;

SQL> Delete from emp where empno=2;
SQL> update emp set empname = 'Lenny' where empno=100;
SQL> commit;

SQL> select * from emp;

EMPNO                  EMPNAME    SALARY                 
---------------------- ---------- ---------------------- 
1                      Jack       0                      
100                    Lenny      900                    
3                      Mark       5000   

SQL> select current_scn, to_char(systimestamp, 'MM-DD-YY HH24:MI:SS') date_time
     from v$database;
CURRENT_SCN            DATE_TIME         
---------------------- ----------------- 
1432739                12-08-10 10:59:30 

To view and restore the original data, you can
(1) create a cursor to hold the original data
(2) go back in time with dbms_flashback.enable_at_system_change_number(n);
(3) Open and fetch the data in the cursor.
(4) return to the present with dbms_flashback.enable;
(5) Insert the data in the cursor in the restore table
(c) Create a table to restore original data

SQL> create table emp_restore
     as select * from emp where 1 = 0;


set serveroutput on
DECLARE
  cursor c_emp is 
     select * from emp;
  v_row c_emp%rowtype;
BEGIN
  dbms_output.put_line('enabling dbms_flashback..');
  dbms_flashback.enable_at_system_change_number(1432709);
  Open c_emp;
  dbms_output.put_line('disabling dbms_flashback..');  
  dbms_flashback.disable;
  
  loop 
    fetch c_emp into v_row;
    exit when c_emp%notfound;
    insert into emp_restore values
      (v_row.empno, 
       v_row.empname,
       v_row.salary);
  end loop;
  close c_emp;
  commit;
END;
/
enabling dbms_flashback..
disabling dbms_flashback..

SQL> select * from emp_restore; 

EMPNO                  EMPNAME    SALARY                 
---------------------- ---------- ---------------------- 
2                      Mary       4000                   
1                      Jack       101140                 
100                    Joseph     900