Showing posts with label RIP. Show all posts
Showing posts with label RIP. Show all posts

How to backup Windows NTFS partitions before upgrading

Jephe Wu - http://linuxtechres.blogspot.com

Objective: Upgrade Windows 2000 sp4 standalone server to Windows 2003 server standard edition, in case of failure, we are still able to restore back to Windows 2000 server
Environment: Windows 2000 sp4 server, Dell PowerEdge 2450 server, 10G basic NTFS partition for C drive with 5G free space
Tools needed for backup NTFS partition: RIP(Recovery Is Possible) CD 12.3 non-X edition - http://www.tux.org/pub/people/kent-robotti/looplinux/rip/


Steps:
1. boot up with RIP non-X 12.3 CD, choose the second option which is without keyborad mapping,login as root without password.
If you need to do it remotely,start up ssh by running /usr/sbin/sshd, then 'passwd root' to give root password

2. connect a external 300G hard disk with USB cable, we are going to backup C drive to external hard disk

3. mount external hard disk ntfs partition as read/write under RIP Linux
mount.ntfs-3g /dev/sdc1 /mnt/usb
ntfsclone -s - /dev/sda2 | gzip -c | cat > /mnt/usb/jephe.sda2.gz

4. backup mbr of /dev/sda
dd if=/dev/sda count=1 bs=512 of=/mnt/usb/jephe.dd.mbr

5. in case of failure for upgrade, you can restore mbr and C drive back
dd if=/mnt/usb/jephe.dd.mbr of=/dev/sda
gzip -dc /mnt/usb/jephe.sda2.gz | ntfsclone -r - -O /dev/sda2


6. If you need to backup C drive and MBR to network server through ssh connection, please refer to article
Cloning Windows server - using RIP and ntfsclone
at http://linuxtechres.blogspot.com/2007/07/cloning-windows-server-using-rip-and.html

7. While Windows 2000 server is running, as an administrator in the I386 directory on the Windows 2003 CD run Winnt32.exe and follow the prompts.

Use RIP CD to fix the grub issue after RHEL 5 hard power shutdown

Jephe Wu -  http://linuxtechres.blogspot.com

Scenario: HP Proliant DL360G5 server running RHEL 5 and 32bit Oracle 11g database (11.1), after yum update and some Oracle impdp/expdp operations, the server hangs, we have to press power button to shut it down, after power it on again, the GRUB stops at 'loading grub stage 2'.

Steps:

1. use RIP(Rescue Is Possible - http://www.tux.org/pub/people/kent-robotti/looplinux/rip/) to reboot server.
2. re-generate grub
# vgdisplay -v
# lvdisplay -v (find out the root LVM partition name)
# vgchange -a y
# mount /dev/VolGroup00/LogVol00 /mnt/hd
# cd /mnt/hd; chroot .
# mount /dev/cciss/c0d0p0 boot
# cd /dev
# MAKEDEV cciss
# grub-install hd0


3. finishing job
# cd /mnt/hd
# umount boot
# exit
# umount /mnt/hd
# reboot



Use RIP CD and MBRFix to easily fix the Windows MBR issue

Jephe Wu - http://linuxtechres.blogspot.com

Whenever your Windows MBR got corrupted or after restoring the back image, you have to fix the MBR issue. With RIP(Recovery Is Possible - http://www.tux.org/pub/people/kent-robotti/looplinux/rip/) and MBRFix - http://www.sysint.no/nedlasting/mbrfix.htm, It becomes very easy job to get it done.


Environment:
Let's say your Windows server MBR is corrupted or you just restored a Windows partition using ntfsclone (http://linuxtechres.blogspot.com/2007/07/cloning-windows-server-using-rip-and.html). Now you need to update MBR to boot up Windows automatically.

It's especially useful when you cannot boot up to Windows console to run 'fdisk /mbr' due to whatever reason.


Steps:

1. boot up with RIP CD (non-X version is enough, we just need to boot it up and use 'Boot partition #1 on first hard drive' option to boot up Windows normally)

2. Windows MBRfix program at http://www.sysint.no/nedlasting/mbrfix.htm

3. Run command below to fix MBR issue.
c:\> MbrFix /drive 0 fixmbr /yes

4. eject out RIP CD, reboot Windows to verify it.

that's it.

resize (enlarge) the Windows ntfs partition using RIP and ntfsresize


Jephe Wu - http://linuxtechres.blogspot.com

  1. Environment
HP DL360G5 server with 2x146G hard disk, Windows 2003 server R2 service pack 1, the first partition is 10G, we need to resize to 40G.


2. how to do it
use RIP (Recovery Is Possible) cdrom which you can download it from http://www.tux.org/pub/people/kent-robotti/looplinux/rip/ to boot up HP server, then use fdisk to enlarge the partition size first, after that, use ntfsresize program to resize the file system size to 40g.

3. steps

a. backup your important data just in case.

b. reboot server from RIP CD, login in as root without password, run commands below:

ifconfig eth0 10.0.0.145 up
/usr/sbin/sshd
passwd root

note : passwd root to change root password so that you can ssh to this server 10.0.0.145 remotely, use your network environment IP instead.

c. ssh into HP server remotely
, run command below to enlarge partition size:

fdisk -l /dev/cciss/c0d0 > fdisk-backup # backup the current partition table first
fdisk /dev/cciss/c0d0 # to delete the the first partition which is ntfs, then create a new partition with 40g size, then give the partition id as number '7' (compare it with your fdisk-backup file generated in previous step), taggle it as active partition to make it bootable (otherwise you cannot boot up windows anyway)

save the partition, exit

d. resize

ntfsresize -n -s 40g /dev/cciss/c0d0p1

above command just tests first, if it's okay. run it once more time without -n parameter to do the real writing.

ntfsresize -s 40g /dev/cciss/c0d0p1

reboot

How to use ntfsresize from the command line

Jephe Wu http://linuxtechres.blogspot.com/


In order to resize Windows ntfs partition for whatever reason(e.g. shrink it for installing Linux in free space for multi boot), you should get ntfsresize tool. I recommend you download RIP(Recovery Is Possible) rescue CD(non-X version is enough).

The following is the step by step guide. Actually, the original article is from http://mlf.linux.rulez.org/mlf/ezaz/ntfsresize.html but I couldn't access it anymore, so I also copy it on my blog for easier access for other people.

I'm not responsible for any data loss it could cause.

1. get RIP CD, boot up your Windows server with it, you might want to choose the second GRUB options to skip keyboard map

2. check your Windows ntfs partition first


# fdisk -l /dev/hda

Disk /dev/hda: 255 heads, 63 sectors, 2480 cylinders
Units = cylinders of 16065 * 512 bytes

Device Boot    Start       End    Blocks   Id  System
/dev/hda1   *         1      2479  19912536    7  HPFS/NTFS    
Only one partition, it's /dev/hda1 and NTFS, also marked as bootable

3. Find out where you could resize

# ./ntfsresize --info /dev/hda1
ntfsresize v1.9.4
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 20390432768 bytes (20391 MB)                  
Current device size: 20390436864 bytes (20391 MB)
Checking filesystem consistency ...
100.00 percent completed
Accounting clusters ...
Space in use       : 7851 MB (38.5%)
Collecting shrinkage constrains ...
Estimating smallest shrunken size supported ...
You might resize at 7850958848 bytes or 7851 MB (freeing 12540 MB).


So we could free over 12 GB disk space using NTFS.

4. Make an ntfsresize test run, using the --no-action option

# ./ntfsresize --no-action --size 11000M /dev/hda1
ntfsresize v1.9.4
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 20390432768 bytes (20391 MB)                  
Current device size: 20390436864 bytes (20391 MB)
New volume size    : 10999996416 bytes (11000 MB)
Checking filesystem consistency ...
100.00 percent completed
Accounting clusters ...
Space in use       : 7851 MB (38.5%)
Collecting shrinkage constrains ...
Needed relocations : 265947 (1090 MB)
Schedule chkdsk NTFS consistency check at Windows boot time ...
Resetting $LogFile ... (this might take a while)
Relocating needed data ...
100.00 percent completed
Updating $BadClust file ...
Updating $Bitmap file ...
Updating Boot record ...

The read-only test run ended successfully.


Everything looks good, let's go on

5. Resize NTFS
#
# ./ntfsresize --size 11000M /dev/hda1
ntfsresize v1.9.4
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 20390432768 bytes (20391 MB)
Current device size: 20390436864 bytes (20391 MB)
New volume size    : 10999996416 bytes (11000 MB)
Checking filesystem consistency ...
100.00 percent completed
Accounting clusters ...
Space in use       : 7851 MB (38.5%)
Collecting shrinkage constrains ...
Needed relocations : 265947 (1090 MB)
WARNING: Every sanity check passed and only the DANGEROUS operations left.
Please make sure all your important data had been backed up in case of an
unexpected failure!
Are you sure you want to proceed (y/[n])? y
Schedule chkdsk NTFS consistency check at Windows boot time ...
Resetting $LogFile ... (this might take a while)
Relocating needed data ...
100.00 percent completed
Updating $BadClust file ...
Updating $Bitmap file ...
Updating Boot record ...
Syncing device ...
NTFS had been successfully resized on device '/dev/hda1'.
You can go on to resize the device e.g. with 'fdisk'.
IMPORTANT: When recreating the partition, make sure you
1)  create it with the same starting disk cylinder
2)  create it with the same partition type (usually 7, HPFS/NTFS)
3)  do not make it smaller than the new NTFS filesystem size
4)  set the bootable flag for the partition if it existed before
Otherwise you may lose your data or can't boot your computer from the disk!


6. Optionally you could check your NTFS integrity
#
./ntfsresize --info --force /dev/hda1
ntfsresize v1.9.4
NTFS volume version: 3.1
Cluster size       : 4096 bytes
Current volume size: 10999992320 bytes (11000 MB)                  
Current device size: 20390436864 bytes (20391 MB)
Checking filesystem consistency ...
100.00 percent completed
Accounting clusters ...
Space in use       : 7851 MB (71.3%)
Collecting shrinkage constrains ...
Estimating smallest shrunken size supported ...
You might resize at 7850958848 bytes or 7851 MB (freeing 3149 MB).


Notice that the volume (NTFS) size indeed became 11000 MB but
the device (partition) size is still 20399 MB
7. Repartition the disk
  • do backup first


# sfdisk -d /dev/hda > hda.pt                # saves the partition table
# dd if=/dev/hda of=hda.mbr bs=512 count=1   # saves the MBR



  • Follow the steps below in order.
    • List the partition table. If you should see the correct partition types (NTFS),
    • Temporarily delete the entry for the 1st partition. This is an in-memory operation only.
    • Recreate the 1st partition entry at the same starting cylinder (sector) and using a larger size than above. This is very important because partitioning tools, fdisk included, may round down slightly the provided value to cylinder boundary. This would cause unbootable Windows. The theoretical maximum cylinder size currently is less than 140 MB hence this extra size should be always enough. We also use 11140 MB, it must be safe.
    • Set the partition type to NTFS (type 7).
    • Mark it bootable if it was also marked before.
    • Print the partition table again to check everything is right.
    • Commit the whole process by writing it to disk.
    # fdisk /dev/hda
    
    Command (m for help): p
    
    Disk /dev/hda: 255 heads, 63 sectors, 2480 cylinders
    Units = cylinders of 16065 * 512 bytes
    
    Device Boot    Start       End    Blocks   Id  System
    /dev/hda1   *         1      2479  19912536    7  HPFS/NTFS
    
    Command (m for help): d
    Partition number (1-4): 1
    
    Command (m for help): n
    Command action
    e   extended
    p   primary partition (1-4)
    p
    Partition number (1-4): 1
    First cylinder (1-2480, default 1): 1
    Last cylinder or +size or +sizeM or +sizeK (1-2480, default 2480): +11140M
    
    Command (m for help): t
    Partition number (1-4): 1
    Hex code (type L to list codes): 7
    Changed system type of partition 1 to 7 (HPFS/NTFS)
    
    Command (m for help): a
    Partition number (1-4): 1
    
    Command (m for help): p
    
    Disk /dev/hda: 255 heads, 63 sectors, 2480 cylinders
    Units = cylinders of 16065 * 512 bytes
    
    Device Boot    Start       End    Blocks   Id  System
    /dev/hda1   *         1      1355  10884006    7  HPFS/NTFS
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.
  • Next step is also optional but strongly recommended. We check again, using ntfsresize, if we can still access our NTFS. For this purpose one must use both the --info and --force options again.
    # ./ntfsresize --info --force /dev/hda1
    ntfsresize v1.9.4
    NTFS volume version: 3.1
    Cluster size       : 4096 bytes
    Current volume size: 10999992320 bytes (11000 MB)                  
    Current device size: 11145222144 bytes (11146 MB)
    Checking filesystem consistency ...
    100.00 percent completed
    Accounting clusters ...
    Space in use       : 7851 MB (71.3%)
    Collecting shrinkage constrains ...
    Estimating smallest shrunken size supported ...
    You might resize at 7850958848 bytes or 7851 MB (freeing 3149 MB).

    Excellent, still no error.
If you got error, you might need to give a bit more partition size for above fdisk operation.
  • Reboot to Windows to check everything is right (e.g. pressing [Ctrl]-[Alt]-[Del]). Don't get scared when during the boot process Windows will check the filesystem. It was scheduled by ntfsresize for extra safety. If the partition is a system partition then Windows will restart automatically after the filesystem check.
Now you should have unallocated disk space that all Linux distribution installations must be able to handle.

Use Linux to reset Windows server administrator password

Jephe Wu http://linuxtechres.blogspot.com


It's possible you might forget your Windows server administrator password or it's locked after you tried too many times. But don't worry, there's a nice tool 'chntpw' which can help you to reset and unlock it. The following example was tested on Windows 2003 server.

1. download the Linux rescue CD - RIP(Recovery Is Possible)
note: to reduce download time. Non-X version is enough.
2. reboot your Windows server with this CD, you might want to choose option 2 to skip keyboard map
3. login as root without password
4. run the following commands to mount Windows 2003 server partition as read-write
cd /mnt

mount -t ntfs-3g /dev/sda1 win -o force
(assuming your Windows partition is /dev/sda1, you can use fdisk command to find out)
note: to make sure you mounted Windows partition as read/write, you can try to run command
touch /mnt/win/testfile to confirm it won't give you any error.

cd win/WIN2K03/system32/config

chntpw SAM

then follow the screen instruction
first, answer y to reset/unlock the counters
then enter * to blank password
finally, enter y all the way to finish

5. finishing up
cd /mnt
sync
umount win
reboot

Note:
1. you can use chntpw SAM -l to list all Windows users
2. use chntpw SAM -u user1 to unlock/reset user1 password
3. http://www.tuxera.com/community/ntfs-3g-download/  (NTFS 3G website)




Cloning Windows server - using RIP and ntfsclone

Jephe Wu http://linuxtechres.blogspot.com


RIP(Recovery Is Possible) CD can also be used for cloning Windows NTFS partition. If the source and destination servers have the same kind of hardwares, you can use the RIP and ntfsclone which comes with RIP CD to clone Windows NTFS partition.

Use ntfsclone to clone Windows server through network

on the source server(HP DL360)
1) properly shutdown your Windows. Boot from RIP CD, choice the second bootup option which loads everything in memory and skip keyboard map
2) ifconfig eth0 192.168.0.1 up (you can set any ip address, I use 192.168.0.1 here)
4) passwd root (to change root password for remote ssh login later)
5) /usr/sbin/sshd (startup ssh daemon)
6) check ntfs partition information with commands below: (optional)
ntfsinfo -m -v /dev/cciss/c0d0p1 | less
ntfsinfo -i -v /dev/cciss/c0d0p1 | less
7) you might need to use command 'ntfsfix' to fix some basic problems such as Windows didn't shutdown properly before cloning.
ntfsfix /dev/cciss/c0d0p1

on the destination server:
1) boot from RIP CD too, same as what you did on the source
2) use 'fdisk' to make new partition(the size must be equal or greater than the server) (use id 7 (hpfs/ntfs).
you can also use 'sfdisk' to clone the partition table over like below if you'd like to have the exact same partition size.
ifconfig eth0 192.168.0.2 up
ssh 192.168.0.1 'sfdisk -d /dev/cciss/c0d0' | sfdisk /dev/cciss/c0d0
3) clone over the MBR code first(excluding partition table info)
ssh 192.168.0.1 'dd if=/dev/cciss/c0d0 count=1 bs=446' | dd of=/dev/cciss/c0d0
It might doesn't bootup properly if the destination server has the different kind of hard disk, you can try step 5 then to install MBR.
4) clone the ntfs partition content over
ssh 192.168.0.1 'ntfsclone -s -o - /dev/cciss/c0d0p1' | ntfsclone -r - -O /dev/cciss/c0d0p1
reboot
5) in case it doesn't boot up. try to boot from windows CD to recovery console mode to run 'fixmbr' to install the proper MBR

Note: if it doesn't boot up, in order to find out it's due to MBR or ntfsclone issue, you can boot with the RIP CD, then choose 'Boot MBR on first hard disk' option to check if Windows can boot up properly.

note: you can also use RIP and MBRFix program to easily fix the MBR, please refer my another article at http://linuxtechres.blogspot.com/2008/09/use-rip-cd-and-mbrfix-to-easily-fix.html

Use ntfsclone to backup Windows ntfs partition
If you want to do backup for the source Windows ntfs partition, you can do the following on the source after booting up with RIP CD

a. backup partition table
sfdisk -d /dev/cciss/c0d0 | ssh remoteserver 'cat > /path/to/c0d0_sfdisk-d'
for restore, use
ssh remoteserver 'cat /path/to/c0d0_sfdisk-d' | sfdisk /dev/cciss/c0d0

b. backup MBR
dd if=/dev/cciss/c0d0 count=1 bs=512 | ssh remoteserver 'dd of=/path/to/mbr_dd'
for restore, use
ssh remoteserver 'dd if=/path/to/mbr_dd' | dd of=/dev/cciss/c0d0

c. backup ntfs partition /dev/cciss/c0d0p1
ntfsclone -s -o - /dev/cciss/c0d0p1 |gzip -c | ssh remoteserver 'cat > /path/to/c0d0p1_ntfsclone.gz'
for restore, use
ssh remoteserver 'gzip -dc
/path/to/c0d0p1_ntfsclone.gz' | ntfsclone -r - -O /dev/cciss/c0d0p1



note: If the original hard disk is bad, you might want to use the parameters below during backup.

--force --ignore-fs-check



References:
a. http://edoceo.com/exemplar/ntfsclone-transfer-windows

Cloning a Linux server - use dd

Jephe Wu http://linuxtechres.blogspot.com

One of the benefits of using Linux is that you don't have to install it every time, you can ALWAYS clone it despite the destination server hardware is the same as the source ones or not. There're two situations as follows:

1) exactly same hardwares.
2) different hardwares

For each situation, there're different ways to clone the servers. Today, I'll introduce how to clone server by using command dd.

In order to use dd. Generally, the destination server will be having the same kind of server model as the source, or at least the same kind of network card and hard disk.

dd will clone everything from source to destination, sector by sector. dd doesn't care about what kind of OS, it can apply to Windows too. The advantage is that you only need to use one command, the disadvantage is that it might take a bit longer since it will copy every sector of your hard disk, even there's no data on those sectors. If the time is not important to you, and the hardware is the almost same, it might be the best choice for you to clone servers.

The following is the steps I use.

a. keep the minimum application running on the source if possible.
Shutdown those services as long as you can. The idea here is to prevent anything from writing things to the hard disk during cloning process. However, according to my experience, it works well even if you don't shutdown anything, just keep the source server running as normal while cloning.

b. use RIP(Recovery is possible) CD to boot up the destination server.
You can download RIP CD from here. The smaller non-X version is enough, around 37M. Burn it to CD, boot up the destination server.

Normally, I choose the second GRUB bootup option for RIP so that I can eject out the CD after boot up, everything will be in memory only.

c. after booting up RIP, login as root(no password is needed), running the following commands to set up IP address:
ifconfig eth0 ip_address_here up (IP address here should be the same network segment as the source)

d. run the following commands to clone:
ssh source_server_ip 'dd if=/dev/sda' | dd of=/dev/sda

note: if the hard disk is HP hardware raid, it might be /dev/cciss/c0d0. Just replace it with yours.

Now you have to wait until it finish.

Note: the dd won't give you any process report as long as the things go well. However, you can use the command

pkill -USR1 ^dd$

to get the progress report, for more info, you can refer to this excellent article at
http://www.redhatmagazine.com/2007/08/16/tips-from-an-rhce-how-can-i-make-dd-give-me-a-progress-report/
(How to make dd to give me progress report)

If you want to check remotely if it finish or not. Then you can run the following commands after setting up ip on destination server and before doing actual cloning:

passwd root (to change root password)
/usr/sbin/sshd (to start sshd daemon for remote login)

You can also boot up the source using RIP CD, then use the above commands to change root password for the source and start sshd daemon for you login from the destination server.

That's it. I'll introduce other methods for cloning servers for same kind of hardwares later.