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
   

Friday, August 22, 2014

Install Google chrome in Fedora20

[1]   http://www.if-not-true-then-false.com/2010/install-google-chrome-with-yum-on-fedora-red-hat-rhel/

cat << EOF > /etc/yum.repos.d/google-chrome.repo
[google-chrome]
name=google-chrome - \$basearch
baseurl=http://dl.google.com/linux/chrome/rpm/stable/\$basearch
enabled=1
gpgcheck=1
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
EOF

#yum install google-chrome-stable

-Start chrome
$google-chrome


Install GNOME Weather in Fedora 20


[1] http://askubuntu.com/questions/302590/how-to-install-a-clock-or-weather-application-with-gnome-3-8
[2] http://fedoraftw.com/enjoy-weather-data-fedora-20-polished-gnome-weather


-Install gnome-weather with root account

# yum install gnome-weather

...........
  Installing : gnome-weather-3.10.1-1.fc20.x86_64                           1/1
  Verifying  : gnome-weather-3.10.1-1.fc20.x86_64                           1/1

Installed:
  gnome-weather.x86_64 0:3.10.1-1.fc20                                         

Complete!


-Start gnome-weather

$gnome-weather



Wednesday, June 11, 2014

Enable SSH service in Fedora20 in command line


[root@fedora20 SandBoxPython]# systemctl enable sshd.service
ln -s '/usr/lib/systemd/system/sshd.service' '/etc/systemd/system/multi-user.target.wants/sshd.service'
[root@fedora20 SandBoxPython]# systemctl restart sshd.service

Thursday, June 5, 2014

Trace route command line under both windows and Linux

>tracert hostnameOrIP

$traceroute hostnameOrIp


C:\Users\QuentinYang>tracert 10.10.10.56

Tracing route to ENG-QUENTIN [10.10.10.56]
over a maximum of 30 hops:

  1    35 ms    33 ms    33 ms  JUPITER [10.10.10.66]
  2    34 ms    36 ms    39 ms  ENG-QUENTIN [10.10.10.56]

Trace complete.


[q.yang@fedora20 ~]$ traceroute 10.10.10.56
traceroute to 10.10.10.56 (10.10.10.56), 30 hops max, 60 byte packets
 1  10.10.10.66 (10.10.10.66)  47.483 ms  49.967 ms  49.689 ms
 2  10.10.10.56 (10.10.10.56)  52.431 ms  52.185 ms  54.700 ms


quentin@ubuntu:~$ traceroute 10.10.10.56
traceroute to 10.10.10.56 (10.10.10.56), 30 hops max, 60 byte packets
 1  ubuntu (10.1.1.11)  3000.618 ms !H  3000.615 ms !H  3000.547 ms !H

Connecting to VPN under Ubuntu 10.10 (pptp approach tested working in Fedora20 as well)

[1] http://ubuforums.org/showthread.php?t=1307345unt
[2] http://www.cyberciti.biz/tips/howto-configure-ubuntu-fedora-linux-pptp-client.html
[3] https://www.centos.org/forums/viewtopic.php?f=16&t=52407
[4] https://forums.opensuse.org/showthread.php/507157-NetworkManager-pptp-doesn-t-work-after-lastest-update

3 common vpn clients in Linux (pptp, vpnc, openconnect)



I have seen problems reported that were related to using 3.18.x kernels, and 'nf_conntrack_pptp' module not being loaded. 


modprobe nf_conntrack_pptp

Solved the issue. 

you could automate the loading of this module at boot by adding a .conf file in /etc/modules-load.d/ directory eg /etc/modules-load.d/pptp.conf using your favourite editor as root. As an example
Code:
sudo nano  /etc/modules-load.d/pptp.conf
Code:
# Load nf_conntrack_pptp module at boot
nf_conntrack_pptp
More information about loading modules at boot here:

http://www.freedesktop.org/software/...es-load.d.html    [4]



Here's a synopsis of my VPN setups. I have proven this to work on both x86 and x64 for all 3 VPN types.

Important note/disclaimer: I tested these configurations on VMware Workstation 7 VM's and a Dell Vostro 220. All installations were fresh installs, not upgrades. Also, please notice that I detail what type of firewall/VPN I am connecting to for each VPN type. There are so many variations on these VPN implementations that it is extremely difficult to generalize a known-good configuration for each.

1. Install various VPN components
a. PPTP  (worked on fedora 20 connecting to GSN vpn)
  • pptp-linux
  • network-manager-pptp
  • network-manager-pptp-gnome    (add vpn button stop being gray out after installing this) 
b. VPNC
  • vpnc
  • network-manager-vpnc
c. OpenConnect
  • openconnect
  • network-manager-openconnect

2. Reboot

3. PPTP VPN Configuration - This setup works for connecting to ISA 2004/2006 PPTP VPNs. It should work for connecting to MS PPTP VPN implementations in general. I can't speak for other PPTP VPN implementations.

a. Create new PPTP connection
  • VPN Tab Settings
  • Set Connection name
  • Set Gateway
  • Set username (for domain-based user accounts, use domain\username)
  • DO NOT SET PASSWORD
  • DO NOT SET NT DOMAIN
  • PPTP Advanced Options (Advanced button)
  • uncheck all auth methods EXCEPT MSCHAPv2
  • check "Use Point-to-Point encryption (MPPE)"
    • leave Security set at "All Available (Default)"
    • trying to force encryption level causes this option to become unset
  • check "Allow stateful inspection"
  • uncheck "Allow BSD Data Compression"
  • uncheck "Allow Deflate Data Compression"
  • uncheck "Use TCP Header Compression"
  • uncheck "Send PPP Echo Packets" (although connection works either checked or unchecked)
  • save configuration

b. Initial Connection attempt
  • enter password in login box
  • DO NOT check either password save box at this time
  • once connection establishes, verify remote connectivity - ping, rdp, ssh, etc.
  • disconnect VPN session

c. 2nd connection attempt
  • enter password in login box
  • check both password save option boxes
  • once again verify remote connectivity
  • disconnect VPN session

d. Subsequent connection attempts
  • VPN session should automatically connect using saved auth credentials
4. VPNC VPN Configuration - This setup works connecting to an ASA5510 - software version 8.2(1). I didn't have any other Cisco devices to test against.

a. Create new VPNC connection
  • set connection name
  • set Gateway
  • set Group Name
  • set User Password to "Saved" and enter password
  • set Group Password to "Saved" and enter password
  • set username
  • set domain (if applicable)
  • leave Encryption Method at "Secure (Default)"
  • set NAT traversal to "NAT-T"
  • save configuration

b. Initial Connection attempt
  • open VPNC connection
  • if prompted, select "Always Allow" if you want connection to be automatic
  • verify remote connectivity - ping, rdp, ssh, etc.
  • disconnect VPN session
c. Subsequent connection attempts
  • open VPNC connection - session should automatically connect

5. OpenConnect VPN Configuration - This setup works connecting to an ASA5510 - software version 8.2(1). I didn't have any other Cisco devices to test against.

a. Create new OpenConnect connection
  • set connection name
  • set Gateway
  • set Authentication type to "Password/SecurID"
  • no need to set username, OpenConnect won't store it yet
  • save configuration

b. Initial connection attempt
  • open VPN connection
  • check "Automatically start connecting next time"
  • click Close
  • you will get the "No Valid VPN Secrets" VPN failure message

c. 2nd connection attempt
  • open VPN connection
  • accept certificate (if prompted)
  • change Group (if necessary)
  • enter username (may need to be domain\username)
  • enter password
  • click Login
  • if VPN connection fails, see note below
  • verify remote connectivity - ping, rdp, ssh, etc.
  • disconnect session

d. Subsequent connection attempts
  • open VPN connection
  • enter password
  • session should connect

Note: If you get the "Login Failed" message, cancel and wait 15-30 minutes before attempting to connect again. Also, I ended up having to use the NT style domain\username pair for authentication, even though a Cisco AnyConnect client connecting to the same ASA only requires username.

More Detail: OpenConnect has been brutal to get connected. I got failed attempt after failed attempt. When I checked the NPS (IAS) log and the Security Event log on the W2K8 domain controller, I could see my user account authenticating properly via RADIUS from the ASA. Yet the OpenConnect client came back with a "Login Failed" message. I'm not an ASA expert, so I have no idea what to check in the ASA configuration to troubleshoot this problem, other than the basic AAA configuration. But I believe the problem lies in the ASA configuration because when I get the OpenConnect "Login Failed" message, the AnyConnect client from my Windows laptop fails as well. I think it may be a ridiculously short timeout or max failure setting. Whatever the issue is, I have to wait for some length of time (~15-30 minutes) for whatever the problem is to reset.

However, once I finally get the OpenConnect client to successfully connect, it worked from then on. (Just don't mess with the connection configuration, or you will get to go thru this whole process again.)

-----------------------------

P.S. Please leave me feedback for what worked and didn't work for you. Also, if you can, please post a short description documenting what firewall/VPN device you were connecting to and any modifications you may have made to the VPN connection configuration. Maybe we can make this a thread for known-good configurations.

Thanks.
Last edited by sweisler; November 7th, 2009 at 04:20 AM.

Friday, May 30, 2014

Added Google Map Into Your Web Page and Blog


[1] https://developers.google.com/maps/tutorials/fundamentals/adding-a-google-map
[2] http://www.w3schools.com/googleapi/google_maps_basic.asp
[3]https://support.google.com/maps/answer/3544418








Copy pasted link directly from Google map.

Tuesday, May 6, 2014

Syntax and common practices in different Programming Languages

[1] http://en.wikipedia.org/wiki/Include_guard



#include guard  [1]
---------------------------------------------------------------
Common way is to put 'include guard' to stop include header files twice. But when naming is conflict with other macros defined in other modules. It become an issue. So some C and C++ implementations provide a non-standard #pragma once directive; The Objective-C language (which is a superset of C) introduced an #import directive, which works exactly like #include, except that it includes each file only once, thus obviating the need for #include guards

Wednesday, January 15, 2014

why participating in open source projects

Ref [1]
http://www.techworld.com.au/article/535206/15_hot_programming_trends_-_15_going_cold/?fp=4&fpid=6

Hot: GitHub
Not: Résumés
Sure, you could learn something by reading a puffed-up list of accomplishments that include vice president of the junior high chess club. But reading someone's actual code is so much richer and more instructive. Do they write good comments? Do they waste too much time breaking things into tiny classes that do little? Is there a real architecture with room for expansion? All these questions can be answered by a glimpse at some code.
This is why participating in open source projects is becoming more and more important for finding a job. Sharing the code from a proprietary project is hard, but open source code can go everywhere.