Kamis, 30 April 2015

Citrix XenServer - Tips & Trik (The disk size cannot be altered as the disk is already being updated or in use by a running VM)

Pada saat saya akan me-resize ukuran hardisk virtual dari VM CentOS 6.x di host XenServer 6.2 melalui XenCenter, saya tidak bisa melakukannya karena menu untuk me-resize ukuran disk-nya berstatus disable dan diatasnya ada pesan "The disk size cannot be altered as the disk is already being updated or in use by a running VM". Maka saya terpaksa me-resize hardisk virtual VM CentOS tersebut melalui command line dengan menggunakan xe command. Ukuran disk dari vm tersebut awalnya adalah sekitar 21 GB (virtual-size ( RO): 21474836480), dan partisi yang terpakai adalah sekitar 7 GB. Saya ingin memperbesar kapasitasnya hingga berukuran 170 GB, karena saya akan menginstall aplikasi Owncloud Server di OS CentOS tersebut. Kebetulan OS CentOS tersebut menggunakan partisi LVM sehingga saya dapa dengan mudah meng-extend ukuran kapasitasnya.
Adapun cara untuk me-resize hardisk virtual sebuah vm di host xenserver 6.2 melalui command line adalah sebagai berikut (gunakan fitur "tab complete" untuk mempermudah dalam menuliskan perintah xe command yang tersedia).

[root@xenserver-master ~]# xe vm-disk-list vm=
CentOS\ 6.4\ Minimal                                         Copy\ of\ Windows\ Server\ 2008\ R2\ \(64-bit\)\ -\ Master 
Control\ domain\ on\ host:\ xenserver-master                 Copy\ of\ Windows\ Server\ 2008\ R2\ x64\ -\ Slave 
Control\ domain\ on\ host:\ xenserver-slave                  PostgreSQL 
Copy\ of\ CentOS\ 6.4\ Minimal                               Windows\ Server\ 2008\ R2\ \(64-bit\)\ -\ Master 
Copy\ of\ PostgreSQL                                         Windows\ Server\ 2008\ R2\ x64\ -\ Slave\ -\ 2 

[root@xenserver-master ~]# xe vm-disk-list vm=CentOS\ 6.4\ Minimal v
vbd-params=  vdi-params=  version=     vm=          

[root@xenserver-master ~]# xe vm-disk-list vm=CentOS\ 6.4\ Minimal

Disk 0 VBD:
uuid ( RO)             : b63fd66a-3d3c-4b38-8036-6f28e4f50b42
    vm-name-label ( RO): CentOS 6.4 Minimal
       userdevice ( RW): 1

Disk 0 VDI:
uuid ( RO)             : d400af9d-bb76-4af2-94e1-15c8ba472b66
       name-label ( RW): TempLVM
    sr-name-label ( RO): Backup Storage
     virtual-size ( RO): 23622320128

Disk 1 VBD:
uuid ( RO)             : 8e3559dc-df90-755e-fdf7-95792fcb18ea
    vm-name-label ( RO): CentOS 6.4 Minimal
       userdevice ( RW): 0

Disk 1 VDI:
uuid ( RO)             : a6df414f-59cc-4f0c-8a97-8d594194aedd
       name-label ( RW): CentOS 6.4 Minimal 0
    sr-name-label ( RO): Local storage
     virtual-size ( RO): 21474836480

[root@xenserver-master ~]# xe vdi-resize uuid=a6df414f-59cc-4f0c-8a97-8d594194aedd disk-size=171798691840
[root@xenserver-master ~]# xe vm-disk-list vm=CentOS\ 6.4\ Minimal

Disk 0 VBD:
uuid ( RO)             : b63fd66a-3d3c-4b38-8036-6f28e4f50b42
    vm-name-label ( RO): CentOS 6.4 Minimal
       userdevice ( RW): 1

Disk 0 VDI:
uuid ( RO)             : d400af9d-bb76-4af2-94e1-15c8ba472b66
       name-label ( RW): TempLVM
    sr-name-label ( RO): Backup Storage
     virtual-size ( RO): 23622320128

Disk 1 VBD:
uuid ( RO)             : 8e3559dc-df90-755e-fdf7-95792fcb18ea
    vm-name-label ( RO): CentOS 6.4 Minimal
       userdevice ( RW): 0

Disk 1 VDI:
uuid ( RO)             : a6df414f-59cc-4f0c-8a97-8d594194aedd
       name-label ( RW): CentOS 6.4 Minimal 0
    sr-name-label ( RO): Local storage
     virtual-size ( RO): 171798691840

Nah, cukup mudah bukan ?. Lihatlah sekarang ukuran hardisk virtual vm CentOS 6.4 Minimal sudah menjadi 170 GB (virtual-size ( RO): 171798691840).
Sampai disini tugas kita telah selesai. Langkah selanjutnya yang harus dilakukan adalah memperbesar ukuran partisi dari OS CentOS 6.4 Minimal itu sendiri. Untuk melakukan hal ini saya telah membahasnya pada tutorial yang telah lalu dan dapat anda baca disini.
Walaupun begitu saya tetap akan memperlihatkan proses memperbesar kapasitas hardisk didalam OS tersebut melalui baris-baris perintah dibawah ini.

[root@CentOS-6 ~]# fdisk /dev/xvdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xa95dc7bc.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2871, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2871, default 2871): 
Using default value 2871

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): l 

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 1  FAT12           39  Plan 9          82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      3c  PartitionMagic  83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       40  Venix 80286     84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      41  PPC PReP Boot   85  Linux extended  c7  Syrinx         
 5  Extended        42  SFS             86  NTFS volume set da  Non-FS data    
 6  FAT16           4d  QNX4.x          87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS       4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility   
 8  AIX             4f  QNX4.x 3rd part 8e  Linux LVM       df  BootIt         
 9  AIX bootable    50  OnTrack DM      93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       52  CP/M            9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs        
 e  W95 FAT16 (LBA) 54  OnTrackDM6      a5  FreeBSD         ee  GPT            
 f  W95 Ext'd (LBA) 55  EZ-Drive        a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            56  Golden Bow      a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    5c  Priam Edisk     a8  Darwin UFS      f1  SpeedStor      
12  Compaq diagnost 61  SpeedStor       a9  NetBSD          f4  SpeedStor      
14  Hidden FAT16 <3 63  GNU HURD or Sys ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    64  Novell Netware  af  HFS / HFS+      fb  VMware VMFS    
17  Hidden HPFS/NTF 65  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
18  AST SmartSleep  70  DiskSecure Mult b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 75  PC/IX           bb  Boot Wizard hid fe  LANstep        
1c  Hidden W95 FAT3 80  Old Minix       be  Solaris boot    ff  BBT            
1e  Hidden W95 FAT1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

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

Calling ioctl() to re-read partition table.
Syncing disks.


[root@CentOS-6 ~]# pvcreate /dev/xvdb
xvdb   xvdb1  

[root@CentOS-6 ~]# pvcreate /dev/xvdb1
  Physical volume "/dev/xvdb1" successfully created

[root@CentOS-6 ~]# pvs
  PV         VG       Fmt  Attr PSize  PFree 
  /dev/xvda2 VolGroup lvm2 a--   7.51g     0 
  /dev/xvdb1          lvm2 a--  21.99g 21.99g

[root@CentOS-6 ~]# vgs
  VG       #PV #LV #SN Attr   VSize VFree
  VolGroup   1   2   0 wz--n- 7.51g    0 

[root@CentOS-6 ~]# vgextend VolGroup /dev/xvd
xvda   xvda1  xvda2  xvdb   xvdb1  

[root@CentOS-6 ~]# vgextend VolGroup /dev/xvdb1
  Volume group "VolGroup" successfully extended

[root@CentOS-6 ~]# vgs
  VG       #PV #LV #SN Attr   VSize  VFree 
  VolGroup   2   2   0 wz--n- 29.50g 21.99g

[root@CentOS-6 ~]# pvmove /dev/xvda2 /dev/xvdb1
  /dev/xvda2: Moved: 0.1%
  /dev/xvda2: Moved: 7.3%
  /dev/xvda2: Moved: 14.6%
  /dev/xvda2: Moved: 22.4%
  /dev/xvda2: Moved: 29.9%
  /dev/xvda2: Moved: 37.2%
  /dev/xvda2: Moved: 45.0%
  /dev/xvda2: Moved: 52.2%
  /dev/xvda2: Moved: 59.1%
  /dev/xvda2: Moved: 66.4%
  /dev/xvda2: Moved: 73.5%
  /dev/xvda2: Moved: 73.8%
  /dev/xvda2: Moved: 81.6%
  /dev/xvda2: Moved: 89.5%
  /dev/xvda2: Moved: 96.7%
  /dev/xvda2: Moved: 100.0%

[root@CentOS-6 ~]# pvs -o+pv_used
  PV         VG       Fmt  Attr PSize  PFree  Used 
  /dev/xvda2 VolGroup lvm2 a--   7.51g  7.51g    0 
  /dev/xvdb1 VolGroup lvm2 a--  21.99g 14.48g 7.51g

[root@CentOS-6 ~]# vgreduce VolGroup /dev/xvda2
  Removed "/dev/xvda2" from volume group "VolGroup"

[root@CentOS-6 ~]# pvremove /dev/xvda2
  Labels on physical volume "/dev/xvda2" successfully wiped

[root@CentOS-6 ~]# pvs
  PV         VG       Fmt  Attr PSize  PFree 
  /dev/xvdb1 VolGroup lvm2 a--  21.99g 14.48g

[root@CentOS-6 ~]# reboot

[root@CentOS-6 ~]# fdisk -l
Disk /dev/xvda: 171.8 GB, 171798691840 bytes
255 heads, 63 sectors/track, 20886 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00057c4a

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2              64        1045     7875584   8e  Linux LVM

Disk /dev/xvdb: 23.6 GB, 23622320128 bytes
255 heads, 63 sectors/track, 2871 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa95dc7bc

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1        2871    23061276   8e  Linux LVM

Disk /dev/mapper/VolGroup-lv_root: 5947 MB, 5947523072 bytes
255 heads, 63 sectors/track, 723 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/VolGroup-lv_swap: 2113 MB, 2113929216 bytes
255 heads, 63 sectors/track, 257 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

[root@CentOS-6 ~]# fdisk /dev/xvda
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): p

Disk /dev/xvda: 171.8 GB, 171798691840 bytes
255 heads, 63 sectors/track, 20886 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00057c4a

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2              64        1045     7875584   8e  Linux LVM

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

Command (m for help): p

Disk /dev/xvda: 171.8 GB, 171798691840 bytes
255 heads, 63 sectors/track, 20886 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00057c4a

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (64-20886, default 64): 
Using default value 64
Last cylinder, +cylinders or +size{K,M,G} (64-20886, default 20886): 
Using default value 20886

Command (m for help): p

Disk /dev/xvda: 171.8 GB, 171798691840 bytes
255 heads, 63 sectors/track, 20886 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00057c4a

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2              64       20886   167253771   83  Linux

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/xvda: 171.8 GB, 171798691840 bytes
255 heads, 63 sectors/track, 20886 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00057c4a

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2              64       20886   167253771   8e  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@CentOS-6 ~]# reboot


[root@CentOS-6 ~]# fdisk -l
Disk /dev/xvda: 171.8 GB, 171798691840 bytes
255 heads, 63 sectors/track, 20886 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00057c4a

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2              64       20886   167253771   8e  Linux LVM

Disk /dev/xvdb: 23.6 GB, 23622320128 bytes
255 heads, 63 sectors/track, 2871 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xa95dc7bc

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1        2871    23061276   8e  Linux LVM

Disk /dev/mapper/VolGroup-lv_root: 5947 MB, 5947523072 bytes
255 heads, 63 sectors/track, 723 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/VolGroup-lv_swap: 2113 MB, 2113929216 bytes
255 heads, 63 sectors/track, 257 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

[root@CentOS-6 ~]# pvs
  PV         VG       Fmt  Attr PSize  PFree 
  /dev/xvdb1 VolGroup lvm2 a--  21.99g 14.48g

[root@CentOS-6 ~]# pvcreate /dev/xvda2
  Physical volume "/dev/xvda2" successfully created

[root@CentOS-6 ~]# pvs
  PV         VG       Fmt  Attr PSize   PFree  
  /dev/xvda2          lvm2 a--  159.51g 159.51g
  /dev/xvdb1 VolGroup lvm2 a--   21.99g  14.48g


[root@CentOS-6 ~]# vgextend VolGroup /dev/xvda2
  Volume group "VolGroup" successfully extended

[root@CentOS-6 ~]# vgs
  VG       #PV #LV #SN Attr   VSize   VFree  
  VolGroup   2   2   0 wz--n- 181.49g 173.98g

[root@CentOS-6 ~]# pvs
  PV         VG       Fmt  Attr PSize   PFree  
  /dev/xvda2 VolGroup lvm2 a--  159.50g 159.50g
  /dev/xvdb1 VolGroup lvm2 a--   21.99g  14.48g

[root@CentOS-6 ~]# pvs -o+pv_used
  PV         VG       Fmt  Attr PSize   PFree   Used 
  /dev/xvda2 VolGroup lvm2 a--  159.50g 159.50g    0 
  /dev/xvdb1 VolGroup lvm2 a--   21.99g  14.48g 7.51g

[root@CentOS-6 ~]# pvmove /dev/xvdb1 /dev/xvda2
  /dev/xvdb1: Moved: 0.1%
  /dev/xvdb1: Moved: 10.5%
  /dev/xvdb1: Moved: 18.9%
  /dev/xvdb1: Moved: 27.1%
  /dev/xvdb1: Moved: 35.6%
  /dev/xvdb1: Moved: 43.7%
  /dev/xvdb1: Moved: 51.6%
  /dev/xvdb1: Moved: 60.1%
  /dev/xvdb1: Moved: 68.0%
  /dev/xvdb1: Moved: 73.8%
  /dev/xvdb1: Moved: 81.8%
  /dev/xvdb1: Moved: 90.0%
  /dev/xvdb1: Moved: 97.9%
  /dev/xvdb1: Moved: 100.0%

[root@CentOS-6 ~]# pvs -o+pv_used
  PV         VG       Fmt  Attr PSize   PFree   Used 
  /dev/xvda2 VolGroup lvm2 a--  159.50g 152.00g 7.51g
  /dev/xvdb1 VolGroup lvm2 a--   21.99g  21.99g    0

[root@CentOS-6 ~]# vgreduce VolGroup /dev/xvdb1
  Removed "/dev/xvdb1" from volume group "VolGroup"

[root@CentOS-6 ~]# pvs
  PV         VG       Fmt  Attr PSize   PFree  
  /dev/xvda2 VolGroup lvm2 a--  159.50g 152.00g
  /dev/xvdb1          lvm2 a--   21.99g  21.99g

[root@CentOS-6 ~]# pvremove /dev/xvdb1
  Labels on physical volume "/dev/xvdb1" successfully wiped

[root@CentOS-6 ~]# pvs
  PV         VG       Fmt  Attr PSize   PFree  
  /dev/xvda2 VolGroup lvm2 a--  159.50g 152.00g

[root@CentOS-6 ~]# shutdown -h now

Demikian tutorial kali ini. Mudah-mudahan bermanfaat. Amin.

Tidak ada komentar:

Posting Komentar