Friday, November 7, 2014

Expand Ubuntu Drive Size Running in VM Player

Ref
[1] http://superuser.com/questions/795699/how-to-extend-the-primary-partition-for-ubuntu-server-running-in-vmware-player
[2] http://www.in8sworld.net/blog/archives/3912
[3] http://blog.pluralsight.com/resize-vmware-linux-drives
[4] http://askubuntu.com/questions/429576/increase-ubuntu-partition-size-under-virtual-machine
[5] http://askubuntu.com/questions/294889/how-to-expand-the-ext4-primary-partition-size-in-a-vmware-player-virtual-disk
[6] http://xmodulo.com/how-to-change-the-boot-order-of-guest-vm-on-vmware-player.html  F2 into VM guest BIOS
[7] http://unix.stackexchange.com/questions/108199/centos-cant-use-new-extented-space-on-system-disc
[8] http://gparted-forum.surf4.info/viewtopic.php?id=16987

Adding following line into *.vmx file if too short to hit F2 key
--------------------
bios.bootDelay = "<number_of_milliseconds>"
bios.forceSetupOnce = "TRUE"

Command line option (run after boot VMWare from GParted disc or iso)
----------------------
--Start fdisk and display current partition---
# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).
Command (m for help): p
Device Boot         Start         End      Blocks   Id  System
/dev/sda1            2048    39845887    19921920   83  Linux
/dev/sda2       207607995   209712509     1052257+   5  Extended
/dev/sda5       207611904   209712509     1050303   82  Linux swap / Solaris

--Delete /dev/sda1-----
Command (m for help): d
Partition number (1,2,5, default 5): 1
Partition 1 is deleted

--Create new primary partition----
Command (m for help): n
Partition type:
   p   primary (0 primary, 1 extended, 3 free)
   l   logical (numbered from 5)
Select (default p): p
Partition number (1,3,4, default 1): 1
First sector (2048-209715199, default 2048):    <==== This MUST be the same as in the original partition table!
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-207607994, default 207607994):  <== Use the default, will be maximum it can do
Using default value 207607994
Partition 1 of type Linux and of size 99 GiB is set

--Write new partition-----
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

--Check file system consistence----
# e2fsck -f /dev/sda1
e2fsck 1.42.9 (28-Dec-2013)
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
/dev/sda1: 11/1245184 files (0.0% non-contiguous), 122210/4980480 blocks

--Resize partition----
# resize2fs /dev/sda1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/sda1 to 25950743 (4k) blocks.


In my own practice, /dev/sda2 sectors straight after /dev/sda1/, so either change /dev/sda2/  and /dev/sda5/ start sectors, or just delete /dev/sda2 and /dev/sda5, then all unassigned sectors can be added to new /dev/sda1






Above is resizing 'primary partition'. Below is for resize partition on logical volume [7]
---------------------------------------------------
Baisc relationship among PhysicalVolume(PV), VolumeGroup(VG) and LogicalVolume(LV):
PV (/dev/sda2) -> VG (turnkey) -> LV (root)
Resize PV, then extend LV, then resize2fs /dev/VG/LV .....

---expand guest OS disk space from 20G to 200G
Using VMWare disk -> utilities -> Expand

---resize LVM in GParted GUI mode from 20G to 200G
Remember to partition->deactivate LVM2 PV before resizing. [8]

---run following commands after starting debian
root@trac ~# pvs
  PV         VG      Fmt  Attr PSize   PFree
  /dev/sda2  turnkey lvm2 a--  199.52g 182.02g
root@trac ~# lvs
  LV     VG      Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert
  root   turnkey -wi-ao--  17.00g
  swap_1 turnkey -wi-ao-- 512.00m
root@trac ~# vgs
  VG      #PV #LV #SN Attr   VSize   VFree
  turnkey   1   2   0 wz--n- 199.52g 182.02g

---before adding newly allocated space into LVM
root@trac ~# df -h
Filesystem                Size  Used Avail Use% Mounted on
rootfs                     17G  893M   16G   6% /
udev                       10M     0   10M   0% /dev
tmpfs                     101M  172K  101M   1% /run
/dev/mapper/turnkey-root   17G  893M   16G   6% /
tmpfs                     5.0M     0  5.0M   0% /run/lock
tmpfs                     201M     0  201M   0% /run/shm
/dev/sda1                 415M   19M  375M   5% /boot

---Run following commands
root@trac ~# pvresize /dev/sda2
root@trac ~# lvextend /dev/mapper/turnkey-root /dev/sda2
root@trac ~# resize2fs /dev/turnkey/root

---Afterwards, checking again. It's done.
root@trac ~# df -h
Filesystem                Size  Used Avail Use% Mounted on
rootfs                    196G  909M  186G   1% /
udev                       10M     0   10M   0% /dev
tmpfs                     101M  172K  101M   1% /run
/dev/mapper/turnkey-root  196G  909M  186G   1% /
tmpfs                     5.0M     0  5.0M   0% /run/lock
tmpfs                     201M     0  201M   0% /run/shm
/dev/sda1                 415M   19M  375M   5% /boot





root@trac ~# pvs
  PV         VG      Fmt  Attr PSize   PFree
  /dev/sda2  turnkey lvm2 a--  199.52g 182.02g
root@trac ~# lvs
  LV     VG      Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert
  root   turnkey -wi-ao--  17.00g
  swap_1 turnkey -wi-ao-- 512.00m
root@trac ~# vgs
  VG      #PV #LV #SN Attr   VSize   VFree
  turnkey   1   2   0 wz--n- 199.52g 182.02g
root@trac ~# df -h
Filesystem                Size  Used Avail Use% Mounted on
rootfs                     17G  893M   16G   6% /
udev                       10M     0   10M   0% /dev
tmpfs                     101M  172K  101M   1% /run
/dev/mapper/turnkey-root   17G  893M   16G   6% /
tmpfs                     5.0M     0  5.0M   0% /run/lock
tmpfs                     201M     0  201M   0% /run/shm
/dev/sda1                 415M   19M  375M   5% /boot
root@trac ~# pvresize /dev/sda2
  Physical volume "/dev/sda2" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized
root@trac ~# lvs
  LV     VG      Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert
  root   turnkey -wi-ao--  17.00g
  swap_1 turnkey -wi-ao-- 512.00m
root@trac ~# lvextend /dev/mapper/turnkey-root /dev/sda2
  Extending logical volume root to 199.02 GiB
  Logical volume root successfully resized
root@trac ~# lvs
  LV     VG      Attr     LSize   Pool Origin Data%  Move Log Copy%  Convert
  root   turnkey -wi-ao-- 199.02g
  swap_1 turnkey -wi-ao-- 512.00m
root@trac ~# resize2fs /dev/turnkey/root
resize2fs 1.42.5 (29-Jul-2012)
Filesystem at /dev/turnkey/root is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 13
Performing an on-line resize of /dev/turnkey/root to 52171776 (4k) blocks.
The filesystem on /dev/turnkey/root is now 52171776 blocks long.

root@trac ~# df -h
Filesystem                Size  Used Avail Use% Mounted on
rootfs                    196G  909M  186G   1% /
udev                       10M     0   10M   0% /dev
tmpfs                     101M  172K  101M   1% /run
/dev/mapper/turnkey-root  196G  909M  186G   1% /
tmpfs                     5.0M     0  5.0M   0% /run/lock
tmpfs                     201M     0  201M   0% /run/shm
/dev/sda1                 415M   19M  375M   5% /boot

#man lvextend
.....
Examples
       "lvextend -L +54 /dev/vg01/lvol10 /dev/sdk3" tries to extend the size of that logical volume by 54MB on physical volume /dev/sdk3.  This is only possible if
       /dev/sdk3 is a member of volume group vg01 and there are enough free physical extents in it.

       "lvextend /dev/vg01/lvol01 /dev/sdk3" tries to extend the size of that logical volume by the amount of free space on physical  volume  /dev/sdk3.   This  is
       equivalent to specifying "-l +100%PVS" on the command line.

       "lvextend -L+16M vg01/lvol01 /dev/sda:8-9 /dev/sdb:8-9"
       tries to extend a logical volume "vg01/lvol01" by 16MB using physical extents /dev/sda:8-9 and /dev/sdb:8-9 for allocation of extents.


Surprisingly fast when do it for fedora20 (Only a couple of seconds)
---------------------------------------------------------------------
1. Expand in VMWare on fedora20 disk space from 20G to 250G
2. GParted iso start up and resize LVM2 PV from 20G to 250G to include new unallocated new space from VMware expansion.
3. Restarted into Fedora20. run lvextend, and resize2fs. A few seconds for this on-line resizing. Done

[root@fedora20 q.yang]# lvextend /dev/mapper/fedora_192-root /dev/sda2
Extending logical volume root to 247.51 GiB Logical volume root successfully resized [root@fedora20 q.yang]# resize2fs /dev/fedora_192/root resize2fs 1.42.12 (29-Aug-2014) Filesystem at /dev/fedora_192/root is mounted on /; on-line resizing required old_desc_blocks = 2, new_desc_blocks = 16 The filesystem on /dev/fedora_192/root is now 64882688 (4k) blocks long. [root@fedora20 q.yang]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 988M 0 988M 0% /dev tmpfs 997M 152K 997M 1% /dev/shm tmpfs 997M 884K 996M 1% /run tmpfs 997M 0 997M 0% /sys/fs/cgroup /dev/mapper/fedora_192-root 244G 16G 219G 7% / tmpfs 997M 32K 997M 1% /tmp /dev/sda1 477M 146M 302M 33% /boot /dev/sr0 229M 229M 0 100% /run/media/q.yang/GParted-live
   

No comments: