Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Replacing Google search on LinuxMint

I was sick of LinuxMint's hack on Firefox's search results page. And every time I fix it, the next update to Firefox replaces my fixed doc with the default one, which just sucks :(

So here's a script that I run after every update to Firefox:

cd /usr/share/linuxmint/common/artwork/firefox/
sudo wget http://mxr.mozilla.org/firefox/source/browser/locales/en-US/searchplugins/google.xml?raw=1 -O google.xml.fixed
sudo mv google.xml google.xml.orig
sudo mv google.xml.fixed google.xml

LVM: Reusing physical volumes from another machine

Here I wish to demo how to dismantle LVM setup on one machine and reassemble it on another without losing filesystem data stored on the Physical Volumes.

This may be useful in places where block devices can be unmounted from one machine and remounted on another, say to recover from hardware failure on the first machine. (I plan to use it on Amazon AWS' EBS volumes)

The key is to use the -'-zero n' option when reassembling Physical Volumes in lvcreate, and to use the same --size option as the done for the previous LVM setup.

A Volume Group stores its metadata in the Physical Volumes, and hence if you manage to reassemble all Physical Volumes of a Volume Group, you get the original Volume Group back. (Per responses of 'comps' on Freenode's #lvm channel, and confirmed by the testing below)

Now it is up to the Logical Volume creator to carve out volumes of the same size and from the same locations of this Volume Group.

# Legend:
# LVM = Logical Volume Manager 2
# PV = Physical Volume
# VG = Volume Group
# LV = Logical Volume
# FS = FileSystem

# Make a temp directory to play in
mkdir ~/lvm_test
cd ~/lvm_test

MINOR_NUMBER_START=100
MAX_DEVICES=8
for (( i = $MINOR_NUMBER_START ;
 i < $MINOR_NUMBER_START+$MAX_DEVICES ;
 ++i )); do
 # Make a few empty files
 dd if=/dev/zero of=dev$i bs=1024 count=20480

 # Make a few loop devices
 sudo mknod -m660 lo$i b 7 $i
 sudo losetup lo$i dev$i

 # Create LVM PVs using these loop devices
 sudo pvcreate lo$i
done

# Create a VG over all the PVs, and name it vg1
sudo vgcreate vg1 lo*

# Create a LV from the VG, and name it lv1
sudo lvcreate --name lv1 vg1 --size 100M

# Make EXT3 FS on LV with name lv1
sudo mkfs.ext3 `sudo lvdisplay -c vg1/lv1 | cut -d : -f 1`

# Make a directory to act as a mount point
mkdir dir

# Mount the LV on the directory
sudo mount `sudo lvdisplay -c vg1/lv1 | cut -d : -f 1` dir

# Create a 20 MB file filled with random data on this new FS
sudo dd if=/dev/urandom of=dir/dd.out bs=1024 count=20480

# Make a backup of the file
cp dir/dd.out ./dd.out


# Now we perform the test where we remove all the LVs and PVs from the VG and
# the VG itself, and then use the PVs to create a new VG and LV that can be
# mounted with the filesystem intact.

# Teardown the FS, LV and VG, but DONT remove the PVs
sudo umount dir
sudo lvchange --available n vg1/lv1
sudo lvremove vg1/lv1
sudo vgremove vg1

# Create a new VG using existing PVs, and name it vg_new
sudo vgcreate vg_new lo*

# Create a new LV on this VG, but DONT zero the first 1kB block; In essence,
# retain the data on Physical Volumes.
# Make sure to use the same size as previous LV (lv1), else mounting of EXT3 FS
# won't work.
sudo lvcreate --zero n --name lv_new vg_new --size 100M

# Mount the LV on the directory; Note that we did not format.mkfs on the LV.
sudo mount `sudo lvdisplay -c vg_new/lv_new | cut -d : -f 1` dir

# Compare the backed-up copy of del.dd with the one just mounted from the new
# Logical Volume
sudo diff del.dd dir/del.dd

# 
# Teardown
sudo umount dir
sudo lvchange --available n vg_new/lv_new
sudo lvremove vg_new/lv_new
sudo vgremove vg_new

for (( i = $MINOR_NUMBER_START ;
 i < $MINOR_NUMBER_START+$MAX_DEVICES ;
 ++i )); do
 sudo pvremove lo$i
 sudo losetup -d lo$i
done

rm -rf ~/lvm_test

unset MINOR_NUMBER_START
unset MAX_DEVICES

How to convert MTS files to AVI

Per my comments here on a blog post [1] I finally succeeded in converting MTS files (from my Sony HD handycam) to AVI files. Here's how to convert them en'masse:

I am using Linux Mint 10, and ffmepg version 0.6-4:0.6-2ubuntu6.1

.) Put all your MTS files in a directory, and cd into that directory.
.) Use ffmepg to find out the highest bitrate used by the MTS files:
    ls *.MTS | xargs -n 1 ffmpeg -i 2>&1 | grep bitrate | cut -d : -f 6 | sort -g | tail -n 1

    I got 13039 kb/s in my case.


.) Use ffmpeg to do the conversion:

    ls *.MTS | xargs -n 1 -I XXXX ffmpeg -i XXXX -b 13000k -ac 2 -ab 256k -deinterlace XXXX.AVI

    I used the 13000k value above because in the previous step we found out that the highest value is 13039 kb/s. This will allow us to keep the quality of our videos almost unaltered.

    I think that if the actual bitrate of a video is lower than this value, say 8000 kb/s, then ffmpeg will keep that bitrate instead of creating the AVI at 13000 kb/s bitrate, so the AVI filesizes will almost be the same as the MTS files.

    This step will result in additional files to be created in the directory where you are; for eg. if you had files a.MTS and b.MTS, this step will create files a.MTS.AVI and b.MTS.AVI.

[1] http://justplainobvious.blogspot.com/2010/06/how-to-convert-mts-to-avi-in-linux.html

Enabling right-click in GMail

For the record...

I recently switched to Linux Mint, and ever since then I right-clicks in GMail on my firefox had stopped working.


Disabling all the labs feature fixed the problem, so I started hunting for the specific offending labs feature.

In the end it turned out to be the 'Mouse gestures' feature. Since I don't use that feature at all, it was easy to just turn it off, and voila, my Firefox+GMail is back to normalcy.

Restart Ubuntu's Wireless Network Driver (script)

I have admitted on more than one occasion that I am a Windows fan; yes, even after using Vista! But when I got my new laptop, on which I installed Vista Business on my own, I tried to push myself into using Ubuntu; I'll leave blogging about that experience for some other post (on my RNFs). That was a long time ago (2 months to be precise) and this post is about something else.

I encountered too many network disconnections on Ubuntu. I noticed that the wireless' indicator on my laptop would just go away after using Ubuntu for a while. The only work-around to start the connection I had was to restart the OS! As I was very committed to using Ubuntu at any cost, I dug up the internet and found some clues. A little while later I developed this script.

What this script does is it uses the utility that is installed with the Intel (restricted) wireless driver, to check if the driver is still running,; if it is not, then it starts it, and if it is already tunning, it will kill and restart it. Worked like a magic for me for the week that I used Ubuntu after this.


$ cat restart_network_driver.sh

#!/bin/sh
# This code is in public domain, under GPL 2.0 license
if ipw3945d-2.6.22-14-generic --isrunning; then
echo killing \
&& ipw3945d-2.6.22-14-generic --kill \
&& echo restarting \
&& ipw3945d-2.6.22-14-generic --quiet \
&& ipw3945d-2.6.22-14-generic --isrunning; \
else
echo starting \
&& ipw3945d-2.6.22-14-generic --quiet \
&& ipw3945d-2.6.22-14-generic --isrunning;
fi


Here's what I was using:
OS: Ubuntu 7.04 (Gutsy Gibbon)
Laptop: Thinkpad R61i
Wireless: Intel ipw3945d (restricted) driver

and here's how to use it:

sudo ./restart_network_driver.sh


PS: I am posting it now because I am going to give Linux another shot, this time with Hardy heron; and wanted some place to save this script before I wipe out that partition.