Ubuntu – resize partition when a VMware Virtual Machine.

Ubuntu: 12.04 LTS
VMware ESXi: 5.5

I wanted increase the store on one partition by 100GB to 250GB on a system and minimize down time. I was almost able to pull it off. I need one quick reboot to get the new size to show up.

With the system up, I used the vSphere client and modifed the size of the disk.

root@myhostname~:# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_myhostname_subdir-lv_subdir 148G 125G 16G 90% /mountpt/subdir

root@myhostname~:# mount | grep subdir
/dev/mapper/vg_myhostname_subdir-lv_subdir on /mountpt/subdir type ext4 (rw)

root@myhostname~:# fdisk -l

Disk /dev/sde: 161.1 GB, 161061273600 bytes
255 heads, 63 sectors/track, 19581 cylinders, total 314572800 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 identifier: 0x00000000

Disk /dev/sde doesn’t contain a valid partition table

Scan for new hardware or changes:

root@myhostname~:# echo “- – -” > /sys/class/scsi_host/host0/scan
root@myhostname~:# echo “- – -” > /sys/class/scsi_host/host1/scan
root@myhostname~:# echo “- – -” > /sys/class/scsi_host/host2/scan

Still didn’t show up with the new size:

root@myhostname~:# pvdisplay
— Physical volume —
PV Name /dev/sde
VG Name vg_myhostname_subdir
PV Size 150.00 GiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 38399
Free PE 0
Allocated PE 38399
PV UUID dkK9oP-XQq2-p2CM-BVBZ-pv0r-J9cP-Hnc0UB

I rebooted at this point.

root@myhostname:~# fdisk /dev/sde
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xeeb3e856.
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)

Command (m for help): p

Disk /dev/sde: 268.4 GB, 268435456000 bytes
255 heads, 63 sectors/track, 32635 cylinders, total 524288000 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 identifier: 0xeeb3e856

Device Boot Start End Blocks Id System

Command (m for help): quit

root@myhostname:~# pvdisplay
— Physical volume —
PV Name /dev/sde
VG Name vg_myhostname_subdir
PV Size 150.00 GiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 38399
Free PE 0
Allocated PE 38399
PV UUID dkK9oP-XQq2-p2CM-BVBZ-pv0r-J9cP-Hnc0UB

Resize physical volume to reflect the new size:

root@myhostname:~# pvresize /dev/sde
Physical volume “/dev/sde” changed
1 physical volume(s) resized / 0 physical volume(s) not resized

root@myhostname:~# pvdisplay /dev/sde
— Physical volume —
PV Name /dev/sde
VG Name vg_myhostname_subdir
PV Size 250.00 GiB / not usable 3.81 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 63999
Free PE 25600
Allocated PE 38399
PV UUID dkK9oP-XQq2-p2CM-BVBZ-pv0r-J9cP-Hnc0UB

Interestingly, the volume group updated with the new size:

root@myhostname:~# vgdisplay
— Volume group —
VG Name vg_myhostname_subdir
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 250.00 GiB
PE Size 4.00 MiB
Total PE 63999
Alloc PE / Size 38399 / 150.00 GiB
Free PE / Size 25600 / 100.00 GiB
VG UUID QNgKYt-ueHo-hq54-kvWB-HRcd-3Guq-yfBwhu

However, the logical volume did not:

root@myhostname:~# lvdisplay
— Logical volume —
LV Name /dev/vg_myhostname_subdir/lv_subdir
VG Name vg_myhostname_subdir
LV UUID D4xZEe-yAfH-pJoH-51Na-5l2B-Baqu-b37tOw
LV Write Access read/write
LV Status available
# open 1
LV Size 150.00 GiB
Current LE 38399
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 252:1

So, I had to extend it:

root@myhostname:~# lvextend /dev/vg_myhostname_subdir/lv_subdir /dev/sde
Extending logical volume lv_subdir to 250.00 GiB
Logical volume lv_subdir successfully resized

root@myhostname:~# lvdisplay
— Logical volume —
LV Name /dev/vg_myhostname_subdir/lv_subdir
VG Name vg_myhostname_subdir
LV UUID D4xZEe-yAfH-pJoH-51Na-5l2B-Baqu-b37tOw
LV Write Access read/write
LV Status available
# open 1
LV Size 250.00 GiB
Current LE 63999
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 252:1

Now, to resize the filesystem:

root@myhostname:~# resize2fs /dev/mapper/vg_myhostname_subdir-lv_subdir
resize2fs 1.42 (29-Nov-2011)
Filesystem at /dev/mapper/vg_myhostname_subdir-lv_subdir is mounted on /mountpt/subdir; on-line resizing required
old_desc_blocks = 10, new_desc_blocks = 16
The filesystem on /dev/mapper/vg_myhostname_subdir-lv_subdir is now 65534976 blocks long.

Success:

root@myhostname:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_myhostname_subdir-lv_subdir 247G 125G 110G 54% /mountpt/subdir

Auditpol – Windows Filtering Platform – Event ID: 5157

Enough is enough. I’ll turn it on when I need it or have infinitely resources to manage the logs when I have Filtering Platform logging enabled. In my case, I was getting a lot messages for event ID 5157 (“The Windows Filtering Platform has blocked a connection.”). For now, how do you turn this off in Windows Server 2012 R2?

To list all the categories:

C:\>auditpol /list /category
Category/Subcategory
Account Logon
Account Management
Detailed Tracking
DS Access
Logon/Logoff
Object Access
Policy Change
Privilege Use
System

To get a list of any sub-categories for a category:

auditpol /get /category:”Account Logon”
auditpol /get /category:”Account Management”
auditpol /get /category:”Detailed Tracking”
auditpol /get /category:”DS Access”
auditpol /get /category:”Logon/Logoff”
auditpol /get /category:”Object Access”
auditpol /get /category:”Policy Change”
auditpol /get /category:”Privilege Use”
auditpol /get /category:”System”

I have picked on the sub-categories under the “Object Access” category, because that is where the Filtering Platform settings exist. To see the current settings for a sub-category:

auditpol /get /subcategory:”Filtering Platform Packet Drop”
auditpol /get /subcategory:”Filtering Platform Connection”
auditpol /get /subcategory:”IPsec Driver”
auditpol /get /subcategory:”IPsec Main Mode”
auditpol /get /subcategory:”IPsec Quick Mode”
auditpol /get /subcategory:”IPsec Extended Mode”

Example:

C:\>auditpol /get /subcategory:”Filtering Platform Connection”
System audit policy
Category/Subcategory Setting
Object Access
Filtering Platform Connection Success and Failure

To disable all audit logging for some sub-categories:

auditpol /set /subcategory:”Filtering Platform Packet Drop” /success:disable /failure:disable
auditpol /set /subcategory:”Filtering Platform Connection” /success:disable /failure:disable
auditpol /set /subcategory:”IPsec Driver” /success:disable /failure:disable
auditpol /set /subcategory:”IPsec Main Mode” /success:disable /failure:disable
auditpol /set /subcategory:”IPsec Quick Mode” /success:disable /failure:disable
auditpol /set /subcategory:”IPsec Extended Mode” /success:disable /failure:disable

C:\>auditpol /get /subcategory:”Filtering Platform Connection”
System audit policy
Category/Subcategory Setting
Object Access
Filtering Platform Connection No Auditing

Or to enable all audit logging for some sub-categories:

auditpol /set /subcategory:”Filtering Platform Packet Drop” /success:enable /failure:enable
auditpol /set /subcategory:”Filtering Platform Connection” /success:enable /failure:enable
auditpol /set /subcategory:”IPsec Driver” /success:enable /failure:enable
auditpol /set /subcategory:”IPsec Main Mode” /success:enable /failure:enable
auditpol /set /subcategory:”IPsec Quick Mode” /success:enable /failure:enable
auditpol /set /subcategory:”IPsec Extended Mode” /success:enable /failure:enable

Static NAT/PAT (one-to-one) Cisco ASA 8.2

Outside IP: aaa.bbb.ccc.ddd
Inside IP: www.xxx.yyy.zzz
Port: pppp
Identifier for access-list: NAME

This is a simple one to one NAT example. Traffic will go from aaa.bbb.ccc.ddd port pppp to www.xxx.yyy.zzz.

c-asa01(config)# static (inside,outside) aaa.bbb.ccc.ddd www.xxx.yyy.zzz
c-asa01(config)# access-list NAME permit tcp any host aaa.bbb.ccc.ddd eq pppp
c-asa01(config)# access-group NAME in interface outside

Or if you want to NAT and PAT:

Outside IP: aaa.bbb.ccc.ddd
Inside IP: www.xxx.yyy.zzz
Outside Port: pppp
Inside Port: qqqq
Identifier for access-list: NAME

c-asa01(config)# static (inside,outside) tcp aaa.bbb.ccc.ddd pppp www.xxx.yyy.zzz qqqq
c-asa01(config)# access-list NAME permit tcp any host aaa.bbb.ccc.ddd eq pppp
c-asa01(config)# access-group NAME in interface outside

Unable to extend a volume in Windows 2003.

Environment: VMware ESXi 5.5.x, Windows 2003 VM, Windows 2012 R2 VM.

I needed to expand the system disk of a Windows 2003 VMware virtual machine. I was able to easily extend the disk using vSphere, and Windows displayed the new size. However, I was unable to extend the filesystem using DISKPART. I would receive the following message, when I tried:
“Diskpart failed to extend the volume. Please make sure the volume is valid for extending.”

To get around this, I shutdown my Windows 2003 server. Then added the virtual disk to a Windows 2012 R2 VM. I opened up the Disk Management console via Computer Management. Made the newly added disk Online by right mousing clicking on the disk name (on the left) and selecting Online. Then, I right mouse clicked on the logical disk, in my case the C: drive, and selected Expand. Then, I took the disk offline, but right mouse clicking on the disk name (on the left again) and selecting Offline. Next, I removed the disk from my Windows 2012 R2 VM WITHOUT deleting the file from disk.

Then, all I to do was boot my Windows 2003 VM, and let the chkdsk do its thing.

Exchange Server Saved Rules

Version: Exchange 2010

To list all the rules a mailbox has saved to the Exchange server:

[PS] C:\>Get-InboxRule -Mailbox mailboxname

Reset Internet Explorer settings from command line.

The group policy can block access to reset Internet Explorer which seems to need it much more than it should. To bypass this and reset the settings back to the default:

From a command prompt:

C:\> RunDll32.exe InetCpl.cpl,ResetIEtoDefaults

This will pop up the Reset Internet Explorer Settings window. Click Reset to reset everything except you personal settings. Obviously, you can check the “Delete personal settings” box if you want to delete you personal settings as well.

Exchange Search Mailbox

In order to search a mailbox, the account you are using must be a member of the “Discovery Management” role group.

To check:
[PS] >Get-RoleGroupMember “Discovery Management”

To add somebody to a role:
When you add somebody as follows, you will prompted for the member. For example, Administrator.
[PS] >Add-RoleGroupMember “Discovery Management”

If you are doing this as Administrator and are adding the Administrator account, you will need to restart your EMS (Exchange Management Shell).

Once you have added the role, you will be able to use the Search-Mailbox cmdlet. There are many search options. Below is a simple example searching the subject of a mailbox. The way this works is that the search results are sent to a target mailbox and folder.

[PS] C:\> Get-Mailbox alias | Search-Mailbox -SearchQuery {Subject:”searchfor“} -TargetMailbox mailbox -TargetFolder “foldername

Example:
[PS] C:\> Get-Mailbox jim | Search-Mailbox -SearchQuery {Subject:”work rules“} -TargetMailbox mailadmin -TargetFolder “SearchJim

So, in this example, the mailbox jim will be searched for any message with “work rules” in the subject line. Any results, will be put in the mailadmin’s mailbox in a folder called SearchJim.

You can do the same thing for the body of the message:
-SearchQuery {Body:”somethinginthbody”}

Or a date range, except you have to specify sent or received:
-SearchQuery {Received:(1/1/2010..12/31/2010)}
-SearchQuery {Sent:(1/1/2010..12/31/2010)}

Or if you want to search for more than one criteria:
[PS] C:\> Get-Mailbox alias | Search-Mailbox -SearchQuery {Subject:”searchfor” AND Body:”searchsomethingelse” AND Sent:(01/01/2010..12/31/2010)} -TargetMailbox mailbox -TargetFolder “foldername

Moving mysql to a different partition – Ubuntu 12.04

I needed to move my MySQL databases to a different partition, since I was outgrowing the space. I created new space and used a mv command to move the files and preserve the permissions. I moved them to /mysql.

I set the permissions for the new directory:
chown mysql.mysql /mysql
chmod 700 /mysql
Then, I needed to modify the /etc/apparmor.d/tunables/alias file. Note: It is actually documented in the alias file for MySQL.

# vi /etc/apparmor.d/tunables/alias

alias /var/lib/mysql/ -> /mysql/,

# service apparmor restart
# service mysql start

Grant user permission to unlock Active Directory accounts.

OS: Windows 2012 R2

This is the command I used to grant a group permission to unlock accounts.

C:\> DSACLS “ou distinguished name” /i:s /G “group name“:rpwp;LockOutTime;user

Example:

C:\> DSACLS “OU=MyOU,DC=MYDOMAIN,DC=MYTLD” /i:s /G “MYDOMAIN\MYGROUP“:rpwp;LockOutTime;user

Timestamp and lftp

I was using lftp to get a file and do a local listing of the transferred file. The timestamp was days off when I used “local ls”. With some experimentation, I was able to find that if I pass the command a switch I could get the file creation time.

This is what I used:

lftp> local ls -cl

Return top

INFORMATION