There's always time to play

Sunday, March 15, 2009

Creating a bootable USB flash drive formatted as NTFS

Next in the series of bootable flash drives: NTFS support.

I don't really care what filesystem my devices are, as long as I can read and write them. So FAT32 would be a decent choice, right? No. FAT32 has a file size limit of only 4G and I tend to store larger stuff on my Corsair Flash Survivor. I came up with two different solutions:
1. Create two separate partitions, one with stuff GRUB needs access to, one with large stuff like the filesystem images and my data,
2. Create a NTFS partition and boot from that.

Of course I first came up with solution 2, but I couldn't find much information about grub and ntfs, except for total lack of support for ntfs. I was thinking about solution 1 and then decided it sucks if you're forced to use two partitions while you don't really want to, so I went on looking for booting from ntfs drives.

After a while I came upon grub4dos. I can't say I really love it (without spending any time investigating it seems it's more of a hack than an enhancement to grub), but it's grub and it boots from ntfs formatted drives. Once I had that figured out, it was time to start doing some work.

First, partition the flash drive so there's a large ntfs partition (in my case the whole 16G). In my case there was already a partition there, if there's not you can skip deletion of the partition.
# fdisk /dev/sdx

Command (m for help): d
Selected partition 1

Command (m for help): n
Command action
e extended
p primary partition (1-4)
Partition number (1-4): 1
First cylinder (1-125, default 1): [return]
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-125, default 125): [return]
Using default value 125

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 7
Changed system type of partition 1 to 7 (HPFS/NTFS)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Now it's time to create a filesystem on the flash drive, since we've chosen ntfs we'll need ntfsprogs, your linux distribution probably has it in it's repositories. Enter the following command to format the drive:
# mkfs.ntfs -L label -Q /dev/sdxY
Cluster size has been automatically set to 4096 bytes.
Creating NTFS volume structures.
mkntfs completed successfully. Have a nice day.

This shouldn't have been hard, if I actually needed to explain those steps to you at all, so let's continue with the serious part. The next few steps need a grub4dos archive. You can find one at their downloads page, I took Extract this and open a command line in the directory where the extracted files are. Now enter the following command:
# ./ /dev/sdx

Disk geometry calculated according to the partition table:

Sectors per track = 63, Number of heads = 255


If it says Success or something similar, then grub4dos is on your flash drive. You can actually boot from it, however for grub4dos to be useful it needs some files. Copy grldr to your flash drive (of course you need to mount it for that). It should be in the root of the drive. Now create a menu.lst in the root of the drive too (yes, this differs from grub behaviour). Edit the menu.lst file so it resembles a usable grub menu.lst and you're done.

The following block is my menu.lst, if there's any interest in the files and layout I used then just leave a comment and I'll be sure to answer any questions about it.
default 0
timeout 60

title Ubuntu Jaunty Alternate Install AMD64
kernel /ubuntu/jaunty/vmlinuz
initrd /ubuntu/jaunty/initrd.gz

title Gentoo Minimal X86
kernel /gentoo/x86/gentoo root=/dev/ram0 init=/linuxrc looptype=squashfs loop=/gentoo/x86/image.squashfs cdroot
initrd /gentoo/x86/gentoo.igz

title Gentoo Minimal AMD64
kernel /gentoo/amd64/gentoo root=/dev/ram0 init=/linuxrc looptype=squashfs loop=/gentoo/amd64/image.squashfs cdroot
initrd /gentoo/amd64/gentoo.igz

title GParted
kernel /gparted/vmlinuz boot=live union=aufs noswap vga=791 ip=frommedia nolocales live-media-path=gparted
initrd /gparted/initrd1.img

title Memtest 86+
kernel /memtest86/memtest86-3.5

title Boot first harddisk
rootnoverify (hd1)
chainloader +1

title Reboot

title Shut down

Tuesday, March 10, 2009

How not to fix an issue in an ebuild

As seen on Comment #2 From Christian Hoffmann 2008-06-08 13:59:44:
cherokee ships a patched version of lighty's spawn-fcgi. We could try to make
spawn-fcgi an independent package again and patch in the additional features of
cherokee based on a USE flag. Or we could introduce a "spawn-fcgi" USE flag for
both lighty and cherokee and die in the ebuild if the other web server was
installed with USE=spawn-fcgi as well. Any ideas?

Yes dude, you totally understood it. I bet mister Hoffman likes to tell portage (or whatever package manager he uses) to continue after every second ebuild because there's a check halfway in the ebuild instead of a real solution...

What if the check fails? Well, then package install fails of course. And what then? Well if you were just rebuilding world then you can fix the issue and start over again, or continue and know that you still have to fix it...

Sunday, March 1, 2009

Playing videos on a second display using mplayer

I decided I didn't need my home theatre pc anymore, because I don't record that much anymore (and that's the thing I liked most about it). I do however still have the need to play stuff on my tv and watch it from my bed, so I started by using mplayer to play videos to my already connected tv. I'm not covering the display setup here, just the needed information. My tv is display :0.1, I have multiple sound cards (my desktop speakers feature an internal soundcard), and the one my tv is plugged into is hw:1.0 (alsa). Putting this together with stuff lyign around on the web you get this:
DISPLAY=:0.1 mplayer -vo xv -ao alsa:device=hw=1.0 -fs /path/to/file

Using the above I have audio and video from my tv, so when I'm done watching I can turn the tv off and go to sleep... Now all I need is a remote!