MAC OS X, Linux, Windows and other IT Tips and Tricks

30 Jun 15 Uninstalling VMWare Player/Workstation in Linux

Reference: //
sudo vmware-installer -l
sudo vmware-installer -u PRODUCT-NAME

With the first command you can see what products you have. With the second you can choose which product uninstall.

22 May 15 Extending dynamically Linux RAMs in VMWare VM without rebooting

Need to raise the amount of RAM in a VMWare VM without rebooting.

– In VMWare interface: Raise the amount of RAM for the VM
– In the Linux VM: Run the following script:

# This script enables in system the unrecognized RAMs
deleteline () {
echo -ne $dellineup
### check preconditions ###
if ! type -P $modprobe > /dev/null; then
echo -e "'modprobe' package is not installed! \n z.B. apt-get install modprobe"
### check if there is any offline RAM ###
RAMOFFLINE=`grep offline /sys/devices/system/memory/*/state|wc -l`
if [ $RAMOFFLINE -gt 0 ]; then
echo "RAMs found that are not yet recognized by the system. Enable RAMs live recognition? (y/N)" ; read yesno ; deleteline
case "$yesno" in
echo -e "Recognition of unused RAMs will now be enabled"
modprobe acpiphp
modprobe acpi_memhotplug
for i in $(grep -l offline /sys/devices/system/memory/*/state);do echo online > $i;done
echo -e "\n\n"
free -m
echo -e "Process cancelled"
echo "No Unrecognized RAMs present."

Check the new amount of RAM:
free | grep Mem

XEN NOTE: With XEN environment it appears that the System/Kernel immediately recognizes the new amount of RAM dynamically without the need to run this above script.

22 May 15 Update the number of CPU dynamically in a VMWare VM

I’ve come across a situation where I needed to LIVE-raise the number of CPUs for a VMWAre Linux VM without having to reboot.

– In VMAre ris the number of CPUs
– In the Linux VM do the following:
– Save the following script into /root/bin/ directory
(It was take from this article: //
mkdir -p /root/bin
cd /root/bin
wget //

Content of script:
# William Lam
# //
# hot-add cpu to LINUX system using vSphere ESX(i) 4.0
# 08/09/2009
for CPU in $(ls /sys/devices/system/cpu/ | grep cpu | grep -v idle)
echo "Found cpu: \"${CPU_DIR}\" ..."
if [ -f "${CPU_STATE_FILE}" ]; then
STATE=$(cat "${CPU_STATE_FILE}" | grep 1)
if [ "${STATE}" == "1" ]; then
echo -e "\t${CPU} already online"
echo -e "\t${CPU} is new cpu, onlining cpu ..."
echo 1 > "${CPU_STATE_FILE}"
echo -e "\t${CPU} already configured prior to hot-add"

– Make the script runnable
chmod 755

– Run the script

Check the number of CPUs:
cat /proc/cpuinfo | grep ‘processor’
processor : 0
processor : 1
processor : 2
processor : 3

10 Apr 15 Hard disk resize and sync without rebooting

Sometimes I need to resize a virtual disk for a virtual machine without having to reboot the machine. For the kernel to recognize that a virtual disk has changed size. Here are the step to do that:

Unmount the concerned partition: Eg. /dev/sdb1
umount /dev/sdb1
Find out which SCSI devices are involved:
ls /sys/class/scsi_device/
Result example:
0:0:0:0 2:0:0:0 2:0:1:0
Provoke a re-sync of the kernel for all the SCSI devices
(unless you know exactly which one is concerned).
That also finds new disks if it’s the case.
echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/rescan
echo 1 > /sys/class/scsi_device/2\:0\:0\:0/device/rescan
echo 1 > /sys/class/scsi_device/2\:0\:1\:0/device/rescan

In case that doesn’t work you can tell the kernel to re-scan the already known disks only:
Find out how many ‘hostX’ there are:
ls /sys/class/scsi_host/
Result example:
host0 host1 host2
Now rescan every host listed above:
echo "- - -" > /sys/class/scsi_host/host0/scan
echo "- - -" > /sys/class/scsi_host/host1/scan
echo "- - -" > /sys/class/scsi_host/host2/scan

This should display a bigger size of the hard disk:
fdisk -l
Now the file system should be resized appropriately:
Steps to rezize the file system: eg. for /dev/sdb
fdisk /dev/sdb
– Delete the existing partition and create a new one with the needed size and quit.
– Check the partition integrity. eg. for /dev/sdb1
fsck.ext3 -f /dev/sdb1
– Resize the file system for that partition.
resize2fs /dev/sdb1
Result example:
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/sdb1 to 47184905 (4k) blocks.
The filesystem on /dev/sdb1 is now 47184905 blocks long.

Everything is ok.
You can now remount the partition to the original mount point.
mount -a

Example with a VMWARE VM and LVM involved

– In VMWare: Resize the HDD3 to 150GB
– Take a security snapshot (in cse things go wrong)
– Then executed the following commands:

df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 20G 2.6G 17G 14% /
197G 158G 30G 85% /data2

ls /sys/class/scsi_device/
0:0:0:0 2:0:0:0 2:0:1:0 2:0:3:0

# Ran the re-sense of the partitons at the kernel level # echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/rescan # echo 1 > /sys/class/scsi_device/2\:0\:0\:0/device/rescan # echo 1 > /sys/class/scsi_device/2\:0\:1\:0/device/rescan # echo 1 > /sys/class/scsi_device/2\:0\:3\:0/device/rescan

# Let have a look at which HDD we ween to work on.
fdisk -l | grep /dev
Disk /dev/dm-0 doesn't contain a valid partition table
Disk /dev/sda: 25.8 GB, 25769803776 bytes
/dev/sda1 * 1 2650 21286093+ 83 Linux
/dev/sda2 2651 3133 3879697+ 82 Linux swap / Solaris
Disk /dev/sdb: 107.4 GB, 107374182400 bytes
/dev/sdb1 1 13054 104856223+ 8e Linux LVM
Disk /dev/sdc: 161.1 GB, 161061273600 bytes
/dev/sdc1 1 6527 52428096 8e Linux LVM
/dev/sdc2 6528 13054 52428127+ 5 Extended
/dev/sdc5 6528 13054 52428096 8e Linux LVM
Disk /dev/dm-0: 214.7 GB, 214719004672 bytes

# We work on /dev/sdc then we create a new partition in it.
cfdisk /dev/sdc
Create a new Logical partition with the free space (/dev/sdc6)
Created new Partition /dev/sdc6 Size: 53686.41 MB
fdisk -l
Device Boot Start End Blocks Id System
/dev/sdc1 1 6527 52428096 8e Linux LVM
/dev/sdc2 6528 19581 104856255 5 Extended
/dev/sdc5 6528 13054 52428096 8e Linux LVM
/dev/sdc6 13055 19581 52428096 8e Linux LVM

# Install parted package to get the partprobe tool
apt-get install parted

# Provoke a new sync of partitions

# Get the name of the Volume group name.
--- Volume group ---

# Extend the Volume group with the /dev/sdc6
vgextend DBDATA /dev/sdc6
No physical volume label read from /dev/sdc6
Physical volume "/dev/sdc6" successfully created
Volume group "DBDATA" successfully extended

# Get the device name of logical partition
--- Logical volume ---
LV Name /dev/DBDATA/mysql

# Extend the logical partition of 50GB
lvextend -L+50G /dev/DBDATA/mysql
Extending logical volume mysql to 249.97 GiB
Logical volume mysql successfully resized

# Finally Resize the files system of the partiton
resize2fs /dev/DBDATA/mysql
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/DBDATA/mysql is mounted on /data2; on-line resizing required
old desc_blocks = 13, new_desc_blocks = 16
Performing an on-line resize of /dev/DBDATA/mysql to 65528832 (4k) blocks.
The filesystem on /dev/DBDATA/mysql is now 65528832 blocks long.

# Lets check out the result
--- Logical volume ---
LV Name /dev/DBDATA/mysql
LV Size 249.97 GiB

df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 20G 2.6G 17G 14% /
247G 160G 74G 69% /data2

The /dev/mapper/DBDATA-mysql got extended from 197G to 247G

Note: All went fine, then deleted the VMWare snapshot of the VM

Tada!!! Job successfully done.

20 Dec 13 Adding dynamicall a new Virtual Disk in Linux in VMWare

for i in $(ls /sys/class/scsi_host); do echo "- - -" > /sys/class/scsi_host/$i/scan ; done

25 Oct 13 Expanding a VMWare external volume

The task here is simply to raise the zize of a data volume attached to a VMWare virtual machine.

1. Stop the instance that is attached to the volume to be expanded.
2. Create a snapshot of the volume.
3. Create a new volume from the snapshot. There you have the possibility to raise the size of the volume.
4. Detach the old volume.
5. Attach the expanded volume.
6. Restart the VM instance.
7. Use the resize2fs command to resize the file system to the new size of the volume

If the data volume is already of LVM type then the following steps apply:
1. Expand Volume in VMWare interface
2. Restart VM instance
3. Create new partition with cfdisk as lvm (8e) -> cfdisk /dev/sdb (choose available Space and as Typ 8E LVM)
4. Add Partition to Volumegroup with vgextend -> vgextend {VGROUPNAME]} /dev/sdb1 (you can list all VGROUPs with vgdisplay)
5. Set new Size of mount with lvextend -> lvextend -L10GB /dev/{VGROUPNAME}/{VOLUME} (-L10G is the target size, list all Logical volumes with lvdisplay
6. Use the resize2fs command to resize the file system to the new size of the volume -> resize2fs /dev/{VGROUPNAME}/{VOLUME}