Thursday, July 25, 2013

LVM resize

My root partition recently ran out of space and I needed to resize it.

So I booted into a live usb and then, after activating my volume groups:

$ sudo vgchange -a y

I looked up lvm resize online and came up with the command:

$ sudo lvextend -L+10G /dev/mapper/big-root

Next I rebooted and ran "df -h". It was the same size and I was annoyed and confused. After some routine poking around I noticed the man page suggested the use of a "-r" flag to actually resize the file system. Who knew?

Final command:

$ sudo lvextend -r -L+10G /dev/mapper/big-root


PS: Oh and if you need to reduce the size of the partition because you ran the command without modifying the filesystem and you don't want to learn how to use "resizefs"

$ sudo lvreduce -L-10G /dev/mapper/big-root


UPDATE: A reader has suggested that the previous code block might be misleading. To reduce the size of a lvm partition,  you should use the following command with the "-r" flag or you will risk losing data. The file system must be resized before the lvm partition's size is reduced. However in the previous example, my filesystem was the size of the partion after reduction.

$ sudo lvreduce -r -L-10G /dev/mapper/big-root


Note: Commandlinefu says it better and faster:
http://www.commandlinefu.com/commands/view/12195/lvextend-logical-volume

Monday, April 22, 2013

extension ram files

I was helping my girlfriend watch some videos that she needed for a class that she was having trouble playing on her mac. Once I saw that ubuntu wasn't able to play them out of the box I looked at the extension and found a solution on ubuntu forums.

The solution suggested that I try mplayer to play the file:

$ mplayer -playlist file.ram

Success! I could watch the video streaming.

 However, it also pointed out that extension ram files were just real player's playlist and the file was simply a text file. I opened the file and it contained one line which was the url to the video. A .rm file, real players video file, that I was sure I could covert with ffmpeg.

The url was rather long so I used cat and wget to download the whole file.


$ wget `cat file.ram`


Next, I used a tutorial on ehow to find the correct flags for converting using ffmpeg. (I am lazy and why read man pages when you have examples you can search and find)


$ ffmpeg -i IN.rm -vcodec mpeg4 -sameq -acodec aac -ab OUT.mp4


It seems I am never going to remember that avconv is the new replacement for ffmpeg. But no matter what I tried I couldn't seem to get it to work.

I decided because I knew it would run in mplayer that mencoder was the logical choice.


$ mencoder IN.rm -aid 0 -vid 1 -ovc lavc -oac lavc -o OUT.mp4


And that .... worked a little but the video seemed poorly made.

Next i tried something called transmageddon which was a gui and seemed to spin rather than work. More to come if I get it to work...


Sources:

http://ubuntuforums.org/showthread.php?t=1177723
http://www.ehow.com/how_6306550_convert-realmedia-mp4-using-linux.html

Wednesday, April 17, 2013

Wireless Broadcom

So I have had this issue where my wireless card would one day suddenly disappear. I had a wireless usb so I used that for a month or so and finally I decided that I would just reinstall and see if that fixed it. It did like magic but then a couple days later poof gone. Now if you are reading this there is a good chance you have search for linux and broadcom related information and you have found a ton. Ultimately I fixed mine using information from a few sources:

First you can list your network related hardware using:

$ sudo lshw -C network

Confirm that you have a broadcom chip. In my case the broadcom chip was listed as "*-network UNCLAIMED". Next you can check for some sort of blocking

$ rfkill list all

In my case before I fixed the issue my wireless device wasn't even listed. After that I would run:

$ lspci -vnn | grep 14e4:

In my case after finding that command I check back on the table at http://linuxwireless.org/en/users/Drivers/b43#Supported_devices. My device was listed as 14e4:4727 which is BCM4313 (same as lshw listed) Next I looked at http://linuxwireless.org/en/users/Drivers/brcm80211 I found my chip in a table listed under "
brcmsmac" from my research I knew that "brcmsmac" was one of the options for broadcom drivers. So I tried modprobing it as I had done for 'b43' and 'brcmfmac' earlier.

$ sudo modprobe brcmsmac

And success!

Lastly if you don't want to run that command every time you turn your machine on you could add "modprobe brmsmac" on a line immediately before "exit 0" in the file /etc/rc.local


The four most helpful and complete sources:
https://wiki.archlinux.org/index.php/Broadcom_wireless#broadcom-wl
http://linuxwireless.org/en/users/Drivers/brcm80211
http://linuxwireless.org/en/users/Drivers/b43#Supported_devices
http://askubuntu.com/questions/235279/my-wifi-adapter-is-not-working-at-all-where-to-start-troubleshooting



Tuesday, April 16, 2013

Forward and Back Buttons

For what ever reason perhaps just nostalgia possibly because I happen to use them more than expected, I have forward and back links on my website. The buttons are JavaScript powered and I have had "noscript" tags warning users of their lack of functionality since I added the links years ago. However, I don't like that they still exist without scripting. Anyway, I decided that I was going to use scripting to draw the buttons.

<script type="text/javascript">
            document.write('\x3Ca href="javascript:history.back()">Back\x3C/a>');
            document.write('\x3Ca href="javascript:history.forward()">Forward\x3C/a>');
            document.write('\x3Chr />');
</script>

Note: that by using '\x3C' rather than '<', I eliminated a potential problem in the parsing of the page and made it so that they would validate again. 

Saturday, April 6, 2013

Image Magick IV: watermark

I decided to try and start signing my pictures.


$ for i in *.JPG; do echo -e "$i... \c"; composite -watermark 15% -gravity southeast sign-1.png $i $i; echo done; done

It needs more tweaking but that will do for now.

Tuesday, March 12, 2013

Play DVDs

To play dvds first you must install a package:


sudo apt-get install libdvdread4


Next you will run this command and like magic it works:


sudo /usr/share/doc/libdvdread4/install-css.sh

You may need to reboot:

Friday, February 22, 2013

pygments

Pygments is a python based syntax highlighter.

Examples:

pygmentize -f html -l python -O full -o file.py.html  file.py

pygmentize -l latex -O full -o resume.tex.html resume.tex

Tuesday, January 15, 2013

Lost Partition Table

Step 1: Losing the Data

We will start this post off with a tip... 

Never ever ever re-install a distribution when you are tired.

Long story short, I was re-installing Ubuntu at way to early in the morning and clicked "Erase Entire disk" about 2 seconds later I panicked and pulled out the battery on my laptop. After restarting, the installer had not yet managed to do any damage that I knew of, but it had removed my partition table.

Step 2: Panic

I am now wide awake and really angry at myself. I put in a liveusb and begin the process of getting my data back. The best thing I did at this point was go to bed. I was way to wired to work on recovering my data and it was far to important not to screw up. Take your time, rushing is probably what got you in this mess.

Step 3: Recover partition table

After a few seconds of search and a few hours of research, I found a seemly universally liked program called testdisk. I highly recommend testdisk. 

"Test disk is a free data recovery utility. It is primarily designed to help recover lost data storage partitions and/or make non-booting disks bootable again when these symptoms are caused by faulty software, certain types of viruses or human error (such as accidentally erasing a partition table). TestDisk can be used to collect detailed information about a corrupted drive which can then be sent to a tech for further analysis." - wikipedia

Using testdisk, I was able to really easily scan my hard disk. The program allowed me to view files in partition and do some navigation through the directories. I was also able recover most of my partition table.

Testdisk correctly (sort of) found four partitions: Boot, recovery, windows, and linux. However, testdisk incorrectly placed the linux partition with "unallocated" space on either side. More to come on that later.

Step 4: Recover lvm2 configuration file

LVM stores a copy of the lvm configuration file in the front of each physical volume. Using dd to read the first few sectors of the lvm partition to a file, I should have been able to find the config file. I did not. Now, this should be a red flag to you that something is wrong with my partition table but at the time i over looked this detail. 

Next, I used photorec (another program in the testdisk suite) and a custom signature to scan the disk for my lvm config file. All lvm config files should begin with something like "# Generated by LVM2" so by creating a signature for that type of file I was able to recover my configuration file.

Step 4.5: Fix the partition table

After trying many different times and processes to restore the lvm config file and failing each time, I determined that testdisk had incorrectly recovered my partitions. I was able to confirm this by comparing the size of sda4 with the size of the physical volume in the configuration file. The lvm physical volume was the entire rest of the disk after the third partition not just a chunk in the middle (duh) after the third. To change my partition table I used gparted. I think that partitions aren't worth screwing up on the command line but to each their own. Now, and this is important I deleted the existing partition and made a new one. I did not move and resize the partition. If you move the partition most programs will move the data to the new start sector of the partition which would erase some of your data. So again delete and recreate do not move.

Step 5: Restore lvm config file

Now that the partition table was correct the restore went smoothly. First I had to use "pvcreate" to turn sda4 back into a valid lvm physical volume, then I used "vgcfgrestore" to restore the configuration file.

Epilogue:

As ever person who has ever used a computer knows... back up your data. But actually do it. Because I promise you that you will be super angry just like me. 

I am sorry I do not not still have the actual commands that I ran to do the recovery it has been a couple of months and I have since forgotten all of the correct arguments and such.

If you want more information about any of the programs used... I found all of this on the internet there are a few really good sites that explain testdisk as well as some lvm restoration troubleshooting.

Sources:

I have found some of the websites that I found useful when solving this problem:

http://linuxcommando.blogspot.com/2008/06/show-progress-during-dd-copy.html

http://www.linuxquestions.org/linux/answers/Applications_GUI_Multimedia/How_To_Do_Eveything_With_DD

http://unix.stackexchange.com/questions/25497/lvm2-can-not-wake-up-suspended-logical-volume

http://www.novell.com/coolsolutions/appnote/19386.html