Sunday, 19 June 2016

Extending space to existing disk in VM

login as: root

oracle@192.168.86.128's password:

Last login: Sat Jun 25 09:39:36 2016

[root@localhost ~]# fdisk /dev/sda

Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.


Command (m for help): n

Partition type:

   p   primary (2 primary, 0 extended, 2 free)

   e   extended

Select (default p): p

Partition number (3,4, default 3):

First sector (41943040-62914559, default 41943040):

Using default value 41943040

Last sector, +sectors or +size{K,M,G} (41943040-62914559, default 62914559):

Using default value 62914559

Partition 3 of type Linux and of size 10 GiB is set




Command (m for help):
p




Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0x000b2714




   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *        2048     2050047     1024000   83  Linux

/dev/sda2         2050048    41943039    19946496   8e  Linux LVM

/dev/sda3        41943040    62914559    10485760   83  Linux




Command (m for help):
t

Partition number (1-3, default 3):

Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'




Command (m for help):
w

The partition table has been altered!




Calling ioctl() to re-read partition table.




WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table. The new table will be used at

the next reboot or after you run partprobe(8) or kpartx(8)

Syncing disks.

[root@localhost ~]# reboot


[root@localhost ~]#
fdisk -l




Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0x000b2714




   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *        2048     2050047     1024000   83  Linux

/dev/sda2         2050048    41943039    19946496   8e  Linux LVM

/dev/sda3        41943040    62914559    10485760   8e  Linux LVM




Disk /dev/mapper/ol-swap: 3145 MB, 3145728000 bytes, 6144000 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes







Disk /dev/mapper/ol-root: 17.3 GB, 17276338176 bytes, 33742848 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes




[root@localhost ~]#
pvcreate /dev/sda3

WARNING: xfs signature detected on /dev/sda3 at offset 0. Wipe it? [y/n] y

  Wiping xfs signature on /dev/sda3.

  Physical volume "/dev/sda3" successfully created

[root@localhost ~]# vgdisplay

  --- Volume group ---

  VG Name               ol

  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.02 GiB

  PE Size               4.00 MiB

  Total PE              4869

  Alloc PE / Size       4869 / 19.02 GiB

  Free  PE / Size       0 / 0

  VG UUID               Ay0nlL-BUuA-ltwR-GzYz-5NUl-ooBM-qBRNA6




[root@localhost ~]#
pvscan

  PV /dev/sda2   VG ol              lvm2 [19.02 GiB / 0    free]

  PV /dev/sda3                      lvm2 [10.00 GiB]

  Total: 2 [29.02 GiB] / in use: 1 [19.02 GiB] / in no VG: 1 [10.00 GiB]

[root@localhost ~]# vgextend ol /dev/sda3

  Volume group "ol" successfully extended

[root@localhost ~]# pvscan

  PV /dev/sda2   VG ol   lvm2 [19.02 GiB / 0    free]

  PV /dev/sda3   VG ol   lvm2 [10.00 GiB / 10.00 GiB free]

  Total: 2 [29.02 GiB] / in use: 2 [29.02 GiB] / in no VG: 0 [0   ]

[root@localhost ~]# lvdisplay

  --- Logical volume ---

  LV Path                /dev/ol/swap

  LV Name                swap

  VG Name                ol

  LV UUID                A3qVoi-7ZI3-K6EN-ioa3-f1J3-n8ND-0yR3Xn

  LV Write Access        read/write

  LV Creation host, time localhost, 2015-01-02 15:22:08 -0500

  LV Status              available

  # open                 2

  LV Size                2.93 GiB

  Current LE             750

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

  Block device           252:0




  --- Logical volume ---

  LV Path                /dev/ol/root

  LV Name                root

  VG Name                ol

  LV UUID                0anOak-0QeZ-qmE2-QVyL-Bji9-lMzg-5I2S3k

  LV Write Access        read/write

  LV Creation host, time localhost, 2015-01-02 15:22:08 -0500

  LV Status              available

  # open                 1

  LV Size                16.09 GiB

  Current LE             4119

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  - currently set to     256

  Block device           252:1




[root@localhost ~]#
lvextend /dev/ol/root /dev/sda3

  Extending logical volume root to 26.09 GiB

  Logical volume root successfully resized

[root@localhost ~]# df -h

Filesystem           Size  Used Avail Use% Mounted on

/dev/mapper/ol-root   17G   11G  6.0G  63% /

devtmpfs             857M     0  857M   0% /dev

tmpfs                866M   80K  866M   1% /dev/shm

tmpfs                866M  9.0M  857M   2% /run

tmpfs                866M     0  866M   0% /sys/fs/cgroup

/dev/sda1            997M  153M  844M  16% /boot

[root@localhost ~]# resize2fs /dev/ol/root

resize2fs 1.42.9 (28-Dec-2013)

resize2fs: Bad magic number in super-block while trying to open /dev/ol/root

Couldn't find valid filesystem superblock.


[root@localhost ~]# xfs_growfs /dev/mapper/ol-root

meta-data=/dev/mapper/ol-root    isize=256    agcount=4, agsize=1054464 blks

         =                       sectsz=512   attr=2, projid32bit=1

         =                       crc=0

data     =                       bsize=4096   blocks=4217856, imaxpct=25

         =                       sunit=0      swidth=0 blks

naming   =version 2              bsize=4096   ascii-ci=0 ftype=0

log      =internal               bsize=4096   blocks=2560, version=2

         =                       sectsz=512   sunit=0 blks, lazy-count=1

realtime =none                   extsz=4096   blocks=0, rtextents=0

data blocks changed from 4217856 to 6838272

[root@localhost ~]# df -h

Filesystem           Size  Used Avail Use% Mounted on

/dev/mapper/ol-root   27G   11G   16G  39% /

devtmpfs             857M     0  857M   0% /dev

tmpfs                866M   80K  866M   1% /dev/shm

tmpfs                866M  9.0M  857M   2% /run

tmpfs                866M     0  866M   0% /sys/fs/cgroup

/dev/sda1            997M  153M  844M  16% /boot

1 comment:

  1. nice document. i was followed step by step, file system space was increased.

    ReplyDelete