Paul’s Linux Blog

Just Another Uber-Geek

I have used partimage on occasion to backup my disk, however one of the issues that used to get me was after restoring an image to a new partition of a larger size the partition would show as the old size.

Here are the steps to resolve this issue.

WARNING: Before making any changes to disks you should back up your data first!

1) Boot you system with a LIVE CDROM or USB STICK using a rescue linux  such as Partition Magic.

2) Boot from the LIVE CD / USB device.

3) Open a terminal session, and type the following.

# df -h

Ensure no partitions are mounted if they are use the command below. (replace x with your partition number)

# umount /dev/sdax

4) Run a file system check to ensure it integrity before making any changes.

# fsck -n /dev/sda3

Output should like something like below.

/dev/sda3: clean, <SOMESIZE>>

5) Remove the journal from /dev/sdax, this will make it an ext2 partition and allow the resize commands to work their magic.

# tune2fs -O ^has_journal /dev/sdax

6) Run another file system check.

# e2fsck -f /dev/sdax

7) Resize the partition with resize2fs without options will use the max size of the disk / partition

# resize2fs /dev/sdax

8.) Now run another filesystem check.

# fsck -n /dev/sdax

9) Create journal on /dev/sdax, this will turn sdax from a ext2 to a ext3 partition again

# tune2fs -j /dev/sdax
10 ) To check it has worked mount the partition and check it's size as follows:
# mount /dev/sdax /mnt
# df -h

11) Reboot the system.

How to backup your MBR

There's not much fun in having to restore your MBR and findiong you can only do this by using the windows mbr recovery console or using the grub installer, an easier way is to make a backup of your mbr now so this does not happen to you. It's easy to do and takes less than a minute to backup and save off somewhere, I like to send it to my gspace account via email but everyone has there own way.

MBR backup

To backup your mbr you need to copy only the first few bytes containing the MBR and the partition table from your bootable disk, check which disk your PC boots from if you have more than 1.

dd if=/dev/sdx of=/path/to/image count=1 bs=512

MBR restore

to restore ensure you only set the dd "count=1 bs=446" to exclude the partition table from being written to disk.Unless you really want to, if it is identicle it won't be an issue.

dd if=/path/to/image of=/dev/sdx

Usually, you do not need to setup an email server under Linux desktop operating system. Most GUI email clients (such as Thunderbird) supports Gmail POP3 and IMAP configurations. But, how do you send mail via the standard or /usr/bin/mail user agents or a shell script? Programs such as sendmail / postfix / exim can be configured as a gmail smarthost but they are largely overkill for this use.
You can use gmail as a smart host to send all messages from your Linux / UNIX desktop systems. You need to use a simple program called ssmtp. It accepts a mail stream on standard input with recipients specified on the command line and synchronously forwards the message to the mail transfer agent of a mailhub for the mailhub MTA to process. Failed messages are placed in dead.letter in the sender's home directory.

Install ssmtp

Type the following command under CentOS / RHEL / Red Hat / Fedora Linux:
# yum install ssmtp
Type the following command under Debian / Ubuntu Linux:
# apt-get update && apt-get install ssmtp

Configure gmail as a smarthost

Open /etc/ssmtp/ssmtp.conf, enter:
# vi /etc/ssmtp/ssmtp.conf
Update file with the following settings:

 
AuthUser=vivek@gmail.com
AuthPass=Your-Gmail-Password
FromLineOverride=YES
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES

Also, make sure you disable Sendmail:
# service sendmail stop
# chkconfig sendmail off
# mkdir /root/.bakup
# mv /usr/sbin/sendmail /root/.bakup
# ln -s /usr/local/ssmtp/sbin/ssmtp /usr/sbin/sendmail

Now, you can use mail / mailx command to send email messages. You can also write a shell script to backup your files and email to somewhere else (see below). You can test settings using following syntax:
$ echo "This is a test" | mail -s "Test" vivek@nixcraft.co.in

A note about sSMTP

sSMTP works well for desktop systems, but it is not a replacement for Sendmail / Postfix / Exim / Qmail for email server environment. This software is perfect for a single user system.

Thanks to this great little script you no longer need to work out which program to use to uncompress multiple file archive formats.
Add this script to your .bashrc file and use as follows:
extract file.zip

 
extract () {
if [ -f $1 ] ; then
case $1 in
*.<span class="highlight" style="border: 1px solid gray; background: yellow none repeat scroll 0% 0%;">tar</span>.bz2)   <span class="highlight" style="border: 1px solid gray; background: yellow none repeat scroll 0% 0%;">tar</span> xvjf $1    ;;
*.<span class="highlight" style="border: 1px solid gray; background: yellow none repeat scroll 0% 0%;">tar</span>.gz)    <span class="highlight" style="border: 1px solid gray; background: yellow none repeat scroll 0% 0%;">tar</span> xvzf $1    ;;
*.<span class="highlight" style="border: 1px solid gray; background: yellow none repeat scroll 0% 0%;">tar</span>.xz)    <span class="highlight" style="border: 1px solid gray; background: yellow none repeat scroll 0% 0%;">tar</span> xvJf $1    ;;
*.bz2)       bunzip2 $1     ;;
*.rar)       unrar x $1     ;;
*.gz)        gunzip $1      ;;
*.<span class="highlight" style="border: 1px solid gray; background: yellow none repeat scroll 0% 0%;">tar</span>)       <span class="highlight" style="border: 1px solid gray; background: yellow none repeat scroll 0% 0%;">tar</span> xvf $1     ;;
*.tbz2)      <span class="highlight" style="border: 1px solid gray; background: yellow none repeat scroll 0% 0%;">tar</span> xvjf $1    ;;
*.tgz)       <span class="highlight" style="border: 1px solid gray; background: yellow none repeat scroll 0% 0%;">tar</span> xvzf $1    ;;
*.<span class="highlight" style="border: 1px solid gray; background: yellow none repeat scroll 0% 0%;">zip</span>)       unzip $1       ;;
*.Z)         uncompress $1  ;;
*.7z)        7z x $1        ;;
*.xz)        unxz $1        ;;
*.exe)       cabextract $1  ;;
*)           echo "\`$1': unrecognized file compression" ;;
esac
else
echo "\`$1' is not a valid file"
fi

At last I managed to get handbrake-gui on my pc big woohoo.

Not that excited hmm maybe not but I have tried many times to install handbrake, the only success I have had was on windows :( I have managed to get the Linux CLI version installed but could not get the out of my files quite right. The gui version I thought would be a simple install however I kept running into dependency issues.

Finally I did it, and worst of all it was far easier than expected.

First ensure you have subversion installed and configured as follows.

  • sudo apt-get install subversion

Now setup subversion

  • sudo svnadmin create /svn

Now to sort the dependencies.

  • sudo apt-get install  yasm build-essential autoconf libtool zlib1g-dev libbz2-dev intltool libglib2.0-dev libdbus-glib-1-dev libgtk2.0-dev libhal-dev libhal-storage-dev libwebkit-dev libnotify-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev

To begin the install you will need to fetch the latest build of handbrake as follows:

  • svn checkout svn://svn.handbrake.fr/HandBrake/trunk hb-trunk

Once the handbrake source code has downloaded change into the src directory.

  • cd hb-trunk

To configure and install handbrake in one easy go use the following command.

  • ./configure --launch

Once the build has completed you should be able to launch the gui as follows.

  • cd build/gtk/src
  • ./ghb &

NOTE: You are able to copy the ghb binary file to anywhere on your system.

I would recommend moving it to the local bin dir, then you should be able to launch it from a terminal screen by typing handbrake-gui &

  • mv ghb /usr/local/bin/handbrake-gui

If all was good you can delete the installation directory.

  • rm -rf hb-trunk

NOTES: I have run through these instructions on crunchbang / ubuntu 8.04 & 8.10 with no problems.

Powered by WordPress Web Design by SRS Solutions © 2010 Paul’s Linux Blog Design by SRS Solutions