Fix time sync
net stop w32time
w32tm /unregister
w32tm /register
net start w32time
net time /setsntp:time.windows.com
w32tm /config /syncfromflags:MANUAL /manualpeerlist:time.windows.com,0x8
w32tm /resync /rediscover
LVM partition resize
1. Create a snapshot of the virtual disk. This snapshot can be used to restore the original configuration in the event that something goes wrong.
2. As in the first example, the operating system still sees the virtual disk as 10 GB.
[root@lvm ~]# fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 16 128488+ 83 Linux
/dev/sda2 17 1305 10353892+ 8e Linux LVM
[root@lvm ~]#
3. Reboot the system.
[root@lvm ~]# shutdown -fr now
Broadcast message from root (pts/0) (Fri Oct 29 15:19:22 2010):
The system is going down for reboot NOW!
[root@lvm ~]#
4. Verify that the system sees the resized virtual disk.
[root@lvm ~]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 16 128488+ 83 Linux
/dev/sda2 17 1305 10353892+ 8e Linux LVM
[root@lvm ~]#
5. This system uses the Logical Volume Manager (LVM) to manage its swap space and most of its filesystems (there is a small boot partition that must exist outside of LVM due to technical limitations).
[root@lvm ~]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 16 128488+ 83 Linux
/dev/sda2 17 1305 10353892+ 8e Linux LVM
[root@lvm ~]#
[root@lvm ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rootvg-rootlv
3.8G 435M 3.2G 13% /
/dev/mapper/rootvg-varlv
992M 76M 866M 8% /var
/dev/mapper/rootvg-usrlv
3.9G 908M 2.8G 25% /usr
/dev/sda1 122M 19M 97M 17% /boot
tmpfs 250M 0 250M 0% /dev/shm
[root@lvm ~]#
[root@lvm ~]# swapon -s
Filename Type Size Used Priority
/dev/mapper/rootvg-swaplv partition 1048568 0 -1
[root@lvm ~]#
6. The first step is to increase the size of the LVM partition, so that LVM will have access to the additional space on the disk. This is similar to expanding the root partition in the other examples.
[root@lvm ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 16 128488+ 83 Linux
/dev/sda2 17 1305 10353892+ 8e Linux LVM
Command (m for help): d
Partition number (1-4): 2
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (17-2610, default 17): (enter)
Using default value 17
Last cylinder or +size or +sizeM or +sizeK (17-2610, default 2610): (enter)
Using default value 2610
Command (m for help): p
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 16 128488+ 83 Linux
/dev/sda2 17 2610 20836305 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/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 16 128488+ 83 Linux
/dev/sda2 17 2610 20836305 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.
Syncing disks.
[root@lvm ~]#
7. Reboot the system to force the Linux kernel to re-read the partition table.
[root@lvm ~]# shutdown -fr now
Broadcast message from root (pts/0) (Fri Oct 29 15:35:50 2010):
The system is going down for reboot NOW!
[root@lvm ~]#
8. The LVM partition is visible to LVM through an object called a “physical volume” (PV), which is broken up into chunks called “physical extents” (PE). A physical volume is roughly analogous to a physical hard drive, a virtual disk on a VM, or a LUN on a SAN device. Physical extents are an allocation unit similar to disk blocks, sectors, or cylinders. Note that the physical volume corresponding to the LVM partition is still listed as 10 GB, and that it has no free physical extents.
[root@lvm ~]# pvdisplay
/dev/hdc: open failed: No medium found
--- Physical volume ---
PV Name /dev/sda2
VG Name rootvg
PV Size 9.87 GB / not usable 31.22 MB
Allocatable yes (but full)
PE Size (KByte) 32768
Total PE 315
Free PE 0
Allocated PE 315
PV UUID PAhkcj-CclU-4SVB-jODE-hSqp-vqlf-rnbxyA
[root@lvm ~]#
9. Expand the physical volume.
[root@lvm ~]# pvresize /dev/sda2
/dev/hdc: open failed: No medium found
Physical volume "/dev/sda2" changed
1 physical volume(s) resized / 0 physical volume(s) not resized
[root@lvm ~]#
10. Verify that the physical volume has been resized, and that it has free PE.
[root@lvm ~]# pvdisplay
/dev/hdc: open failed: No medium found
--- Physical volume ---
PV Name /dev/sda2
VG Name rootvg
PV Size 19.87 GB / not usable 27.77 MB
Allocatable yes
PE Size (KByte) 32768
Total PE 635
Free PE 320
Allocated PE 315
PV UUID PAhkcj-CclU-4SVB-jODE-hSqp-vqlf-rnbxyA
[root@lvm ~]#
11. The root filesystem exists on a logical volume (LV). A logical volume is similar to a partition. The name of the logical volume for the root partition can be obtained by looking at /etc/fstab.
[root@lvm ~]# cat /etc/fstab
/dev/rootvg/rootlv / ext3 defaults 1 1
/dev/rootvg/varlv /var ext3 defaults 1 2
/dev/rootvg/usrlv /usr ext3 defaults 1 2
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/rootvg/swaplv swap swap defaults 0 0
[root@lvm ~]#
12. Note the current size of the logical volume.
[root@lvm ~]# lvdisplay /dev/rootvg/rootlv
/dev/hdc: open failed: No medium found
--- Logical volume ---
LV Name /dev/rootvg/rootlv
VG Name rootvg
LV UUID sv0zI0-RuTf-fm2I-JZdR-vYMg-kZdz-dzHbJN
LV Write Access read/write
LV Status available
# open 1
LV Size 3.84 GB
Current LE 123
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
[root@lvm ~]#
13. Expand the logical volume.
[root@lvm ~]# lvresize -l +100%FREE /dev/rootvg/rootlv
/dev/hdc: open failed: No medium found
Extending logical volume rootlv to 13.84 GB
Logical volume rootlv successfully resized
[root@lvm ~]#
14. Verify that the logical volume has been expanded.
[root@lvm ~]# lvdisplay /dev/rootvg/rootlv
/dev/hdc: open failed: No medium found
--- Logical volume ---
LV Name /dev/rootvg/rootlv
VG Name rootvg
LV UUID sv0zI0-RuTf-fm2I-JZdR-vYMg-kZdz-dzHbJN
LV Write Access read/write
LV Status available
# open 1
LV Size 13.84 GB
Current LE 443
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
[root@lvm ~]#
15. When doing an online resize of the root filesystem, use the name of the logical volume.
[root@lvm ~]# resize2fs /dev/mapper/rootvg-rootlv
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/mapper/rootvg-rootlv is mounted on /; on-line resizing required
Performing an on-line resize of /dev/mapper/rootvg-rootlv to 3629056 (4k) blocks.
The filesystem on /dev/mapper/rootvg-rootlv is now 3629056 blocks long.
Change SQL name
view sql name
select @@servername
Change name
sp_dropserver 'old_name'
go
sp_addserver 'new_name','local'
go
then restart sql
found info here:
http://coderjournal.com/2008/02/how-to-change-instance-name-of-sql-server/
Reset Mysql root password on windows
reseting a mysql password on windows
1. stop mysql
2. Open a command prompt by selecting Start> run> typing in cmd
3. Changed directory to C:\program files\mysql\MySQL Server 5.1_orig\bin by running
cd "C:\program files\mysql\MySQL Server 5.1_orig\bin"
4. Started mysql from the command line with:
mysqld --defaults-file="C:\Program Files\MySQL\MySQL Server 5.1\my.ini" --skip-grant-tables
5. Opened a 2nd command prompt
6. Changed directory to C:\program files\mysql\MySQL Server 5.1_orig\bin
7. log into mysql by typing
mysql
8. select the database
USE mysql
9. update the password
UPDATE user SET password=(' ') WHERE user='root';
10. exit mysql
11. kill the mysql service running in the first command prompt with
taskkill /F /IM mysqld.exe
12. Start mysql normally
13. from the command prompt or the mysql command line client connect to mysql
mysql -uroot -p
just hit enter for the password
14. update permissions
GRANT all on *.* to root@'localhost' identified BY 'newpassword';
GRANT all on *.* to root@'%' identified BY 'newpassword';
flush PRIVILEGES;
15. exited out of mysql
16. tested new password with
mysql -uroot -p
this time entering the password specified.
MySql Upgrade on Windows
A quick way to upgrade mysql on a windows server without using an installer
1. download the mysql-noinstall 32/64 bit version from mysql
2. stop mysql
3. Extract the folder to c:\program files\mysql
4. Renam the MySQL Server 5.1 folder to MySQL Server 5.1_orig
5. rename the extracted folder to MySQL Server 5.1
6. copy C:\program files\mysql\MySQL Server 5.1_orig\data to C:\program files\mysql\MySQL Server 5.1\data
7. copy C:\program files\mysql\MySQL Server 5.1_orig\my.ini to C:\program files\mysql\MySQL Server 5.1\my.ini
8. Start mysql
9. Open a command prompt by selecting Start> run> typing in cmd
10. Change directory to C:\program files\mysql\MySQL Server 5.1_orig\bin by running
cd "C:\program files\mysql\MySQL Server 5.1_orig\bin"
11. upgrade mysql by running
mysql_upgrade
This syncs up the databases with the newly installed version.
Storegrid troubleshooting tips
partyly taken from
http://www.storegrid.com/forum/viewtopic.php?t=4608&sid=bcf279ac6a6d4e4f4687893715c60e3d
partly taken from
http://www.storegrid.com/forum/viewtopic.php?p=7516
to find out the problem with storegrid:
1) Stop StoreGrid if it is already running.
2) Open a command prompt and go to <STOREGRID_HOME> folder and start StoreGrid by executing the following command: "./bin/StoreGrid > sgoutput.txt"
to fix a corrupt database file
1. Stop StoreGrid
2. Open the terminal window and go to the location
"<StoreGrid_Installation_Dir>/lib/" and copy the 'sqlite.bin' file to /home/storegrid/Vembu/StoreGrid/data folder.
3. Access the Database base file (sgserver.db) from command line, by executing "./sqlite.bin sgserver.db".
4. Execute the command "pragma integrity_check;"
5. If the output is 'ok' then the database is not corrupted, if not then the database gets corrupted.
6. Quit sqlite application using ".q" command.
7. If sgserver.db is corrupted rename the sgserver.db file available in /home/storegrid/Vembu/StoreGrid/data/ folder to 'sgserver.db.corrupt'.
8. Access the Database base file (sgserver.db.bak) from command line, by executing "./sqlite.bin sgserver.db.bak". If the output is 'ok' then please proceed with step 9 and step 10.
9. Take a another copy of 'sgserver.db.bak' file and save it as 'sgserver.db.bak.ori'.
10. Copy the 'sgserver.db.bak' file available in /home/storegrid/Vembu/StoreGrid/data/ folder and save it as 'sgserver.db' in the same location.
the example I ran myself:
root@data]# ../lib/sqlite.bin sgclient.db
SQLite version 3.5.4
Enter ".help" for instructions
sqlite> pragma integrity_check;
SQL error: malformed database schema
replace database with backup
[root@data]# mv sgclient.db
sgclient.db sgclient.db.bak
[root@data]# mv sgclient.db sgclient.db_bad
[root@data]# cp -p sgclient.db.bak sgclient.db
start database & verify its running
[root@data]# /etc/init.d/storegrid start
Starting StoreGrid!
[root@data]# /etc/init.d/storegrid status
StoreGrid is running as pid 28613 pts/0 00:00:01 StoreGrid
Resize partition without losing data
find the device name
fdisk -l
unmount the partition
umount /dev/sde1
run a filesystem check
fsck -n /dev/sde1
remove the journal from the partition
tune2fs -O ^has_journal /dev/sde1
use the fdisk utility on the drive
fdisk /dev/sde
type P to view the paritions
type d to delete the current partition table, if there are more than one type the # of the partition you're deleting. this will not remove any data
type n to create a new paritional table
type p for primary partition then the number of the partition
for the first and last cylinder do the lowest/highest number if you're using all of the space
type a to readd the bootable flag then the # of the partition
type w to write to the server and exit fdisk
check the partition
e2fsck -f /dev/sde1
resize the partition to include the new space
resize2fs /dev/sde1
check the files again
fsck -n /dev/sde1
create a new journal for the partition
tune2fs -j /dev/sda1
mount the drive
mount /dev/sde1
verify the space
df -h
or
fdisk -l
If you're doing this to a doing this to a drive with system files on instead of unmounting and mounting you will reboot into a knopix recovery disk and perform the operations from there.
Migrate from IIS7 to IIS7
log into the originating server, open a command prompt and run:
cd %windir%\system32\inetsrv
appcmd add backup backupname
Then copy over %windir%\system32\inetsrv\backup\backupname from the originating server to the server you're migrating too.
on the ending server open up a command prompt and run:
cd %windir%\system32\inetsrv
appcmd restore backupname
Then update any IPs/file paths in IIS.
Migrating SQL users
This is from http://support.microsoft.com/kb/918992/
Migrating SQL Logins from Server to Server
Okay, So chances are if you are reading this, you want to migrate an entire instance of SQL. That is pretty simple. You just want to detach all databases, and copy over the MDF and LDF users. But what about the Logins? ... Yea ... The logins AND Passwords.
Thats where this KB comes in handy.
SQL 2005 -> 2005
To transfer the logins and the passwords from the instance of SQL Server on server A to the instance of SQL Server on server B, follow these steps:
- 1. On server A, start SQL Server Management Studio, and then connect to the instance of SQL Server from which you moved the database.
- 2. Open a new Query Editor window, and then run the following script.
USE master
GO
IF OBJECT_ID ('sp_hexadecimal') IS NOT NULL
DROP PROCEDURE sp_hexadecimal
GO
CREATE PROCEDURE sp_hexadecimal
@binvalue varbinary(256),
@hexvalue varchar (514) OUTPUT
AS
DECLARE @charvalue varchar (514)
DECLARE @i int
DECLARE @length int
DECLARE @hexstring char(16)
SELECT @charvalue = '0x'
SELECT @i = 1
SELECT @length = DATALENGTH (@binvalue)
SELECT @hexstring = '0123456789ABCDEF'
WHILE (@i <= @length)
BEGIN
DECLARE @tempint int
DECLARE @firstint int
DECLARE @secondint int
SELECT @tempint = CONVERT(int, SUBSTRING(@binvalue,@i,1))
SELECT @firstint = FLOOR(@tempint/16)
SELECT @secondint = @tempint - (@firstint*16)
SELECT @charvalue = @charvalue +
SUBSTRING(@hexstring, @firstint+1, 1) +
SUBSTRING(@hexstring, @secondint+1, 1)
SELECT @i = @i + 1
END
SELECT @hexvalue = @charvalue
GO
IF OBJECT_ID ('sp_help_revlogin') IS NOT NULL
DROP PROCEDURE sp_help_revlogin
GO
CREATE PROCEDURE sp_help_revlogin @login_name sysname = NULL AS
DECLARE @name sysname
DECLARE @type varchar (1)
DECLARE @hasaccess int
DECLARE @denylogin int
DECLARE @is_disabled int
DECLARE @PWD_varbinary varbinary (256)
DECLARE @PWD_string varchar (514)
DECLARE @SID_varbinary varbinary (85)
DECLARE @SID_string varchar (514)
DECLARE @tmpstr varchar (1024)
DECLARE @is_policy_checked varchar (3)
DECLARE @is_expiration_checked varchar (3)
DECLARE @defaultdb sysname
IF (@login_name IS NULL)
DECLARE login_curs CURSOR FOR
SELECT p.sid, p.name, p.type, p.is_disabled, p.default_database_name, l.hasaccess, l.denylogin FROM
sys.server_principals p LEFT JOIN sys.syslogins l
ON ( l.name = p.name ) WHERE p.type IN ( 'S', 'G', 'U' ) AND p.name <> 'sa'
ELSE
DECLARE login_curs CURSOR FOR
SELECT p.sid, p.name, p.type, p.is_disabled, p.default_database_name, l.hasaccess, l.denylogin FROM
sys.server_principals p LEFT JOIN sys.syslogins l
ON ( l.name = p.name ) WHERE p.type IN ( 'S', 'G', 'U' ) AND p.name = @login_name
OPEN login_curs
FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @type, @is_disabled, @defaultdb, @hasaccess, @denylogin
IF (@@fetch_status = -1)
BEGIN
PRINT 'No login(s) found.'
CLOSE login_curs
DEALLOCATE login_curs
RETURN -1
END
SET @tmpstr = '/* sp_help_revlogin script '
PRINT @tmpstr
SET @tmpstr = '** Generated ' + CONVERT (varchar, GETDATE()) + ' on ' + @@SERVERNAME + ' */'
PRINT @tmpstr
PRINT ''
WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status <> -2)
BEGIN
PRINT ''
SET @tmpstr = '-- Login: ' + @name
PRINT @tmpstr
IF (@type IN ( 'G', 'U'))
BEGIN -- NT authenticated account/group
SET @tmpstr = 'CREATE LOGIN ' + QUOTENAME( @name ) + ' FROM WINDOWS WITH DEFAULT_DATABASE = [' + @defaultdb + ']'
END
ELSE BEGIN -- SQL Server authentication
-- obtain password and sid
SET @PWD_varbinary = CAST( LOGINPROPERTY( @name, 'PasswordHash' ) AS varbinary (256) )
EXEC sp_hexadecimal @PWD_varbinary, @PWD_string OUT
EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT
-- obtain password policy state
SELECT @is_policy_checked = CASE is_policy_checked WHEN 1 THEN 'ON' WHEN 0 THEN 'OFF' ELSE NULL END FROM sys.sql_logins WHERE name = @name
SELECT @is_expiration_checked = CASE is_expiration_checked WHEN 1 THEN 'ON' WHEN 0 THEN 'OFF' ELSE NULL END FROM sys.sql_logins WHERE name = @name
SET @tmpstr = 'CREATE LOGIN ' + QUOTENAME( @name ) + ' WITH PASSWORD = ' + @PWD_string + ' HASHED, SID = ' + @SID_string + ', DEFAULT_DATABASE = [' + @defaultdb + ']'
IF ( @is_policy_checked IS NOT NULL )
BEGIN
SET @tmpstr = @tmpstr + ', CHECK_POLICY = ' + @is_policy_checked
END
IF ( @is_expiration_checked IS NOT NULL )
BEGIN
SET @tmpstr = @tmpstr + ', CHECK_EXPIRATION = ' + @is_expiration_checked
END
END
IF (@denylogin = 1)
BEGIN -- login is denied access
SET @tmpstr = @tmpstr + '; DENY CONNECT SQL TO ' + QUOTENAME( @name )
END
ELSE IF (@hasaccess = 0)
BEGIN -- login exists but does not have access
SET @tmpstr = @tmpstr + '; REVOKE CONNECT SQL TO ' + QUOTENAME( @name )
END
IF (@is_disabled = 1)
BEGIN -- login is disabled
SET @tmpstr = @tmpstr + '; ALTER LOGIN ' + QUOTENAME( @name ) + ' DISABLE'
END
PRINT @tmpstr
END
FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @type, @is_disabled, @defaultdb, @hasaccess, @denylogin
END
CLOSE login_curs
DEALLOCATE login_curs
RETURN 0
GO
Note This script creates two stored procedures in the master database. The two stored procedures are named the sp_hexadecimal stored procedure and the sp_help_revlogin stored procedure.
- 3. Run the following statement.
EXEC sp_help_revlogin
The output script that is generated by the sp_help_revlogin stored procedure is the login script. This login script creates the logins that have the original Security Identifier (SID) and the original password.
- 4. On server B, start SQL Server Management Studio, and then connect to the instance of SQL Server to which you moved the database. Important Before you go to step 5, review the information in the "Remarks" section.
- 5. Open a new Query Editor window, and then run the output script that is generated in step 3.
Cloning a VM without VC
taken from:
http://blogs.sun.com/danielc/entry/a_little_script_to_clone and http://hsukumar.wordpress.com/2008/05/14/esx-clone-without-virtual-center/
1. Log into the ESX server using the vmware infrastructure client and turn off the server you want to clone. 2. SSH into the server, sudo to root
3. run: /clone.sh <origina> <clone> example: /clone.sh "App Server 1" "App Server 2"
4. Once the clone process finishs go back to the Vmware infrastructure client and create a new VM.
5. Select Custom configuration then browse through the options setting anything you'd like until you get to Select a disk. Browse to the vmdk that you cloned and select it, then select finish.
6. Power on the VM, log in and change the IP
The script:
SOURCEVM=$1
TARGETVM=$2
DATASTORE=/vmfs/volumes/MY-VM-STORE
mkdir $DATASTORE/"$2"
vmkfstools -i $DATASTORE/"$1"/"$1".vmdk $DATASTORE/"$2"/"$2".vmdk