Monday, January 24, 2011

code blocks in blogger

Something I've just come across is the formatting of code blocks in blogger:
 here is some code

There are plenty of sites out there with information on how to do this [Dashboard->Design->Template Designer->Advanced->Add CSS], but what they fail to mention is that the CSS is not correctly implemented in blogger's preview pane [Edit Posts->Preview].
I spent ages testing out CSS changes, expecting to see the effect in the Preview pane, but nothing seemed to be working. After some frustration I decided to post anyway, viewed the post and there was the CSS formatting implemented correctly. If only someone had mentioned this sooner...

adding an smb share in linux

Another post of something I do regularly but can't quite remember...

Running df gives the mount point:
> df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda1 72G 4.7G 64G 7% /
tmpfs 253M 0 253M 0% /lib/init/rw
udev 10M 768K 9.3M 8% /dev
tmpfs 253M 0 253M 0% /dev/shm
/dev/sda1 917G 13G 859G 2% /mnt/raidk
/dev/sdb1 230G 11G 207G 5% /mnt/alfred

In this case it's /mnt/alfred I'd like to share.

Now to add the entry to /etc/samba/smb.conf:
> sudo gedit /etc/samba/smb.conf

I tend to copy an existing section of the config file and change the relevant parts. In this case, the new entry looks like:
[alfred]
path = /mnt/alfred
available = yes
browsable = yes
writable = yes
valid users = joeblo
admin users = joeblo

Once the changes are made, samba needs to be restarted:
> sudo /etc/init.d/samba restart
Stopping Samba daemons: nmbd smbd.
Starting Samba daemons: nmbd smbd.

Now that samba is restarted the new share is available on the network.

Sunday, January 23, 2011

connecting a new drive to linux

This is one of those things I do infrequently enough that I'm not quite able to remember all the details. So here's the procedure documented so that I can do it more quickly next time. Maybe someone else might find it useful too.

FYI, the linux distro I'm running is Debian, and I'm connected to it from Mac OS X via ssh.

1. Connect the drive, power it up, and see where linux has put it.
> sudo /sbin/fdisk -l
Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xdd27dd27

Device Boot Start End Blocks Id System
/dev/hda1 * 1 9541 76638051 83 Linux
/dev/hda2 9542 9729 1510110 5 Extended
/dev/hda5 9542 9729 1510078 82 Linux swap / Solaris

WARNING: GPT (GUID Partition Table) detected on '/dev/sda'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/sda: 1000.1 GB, 1000153686016 bytes
255 heads, 63 sectors/track, 121595 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/sda1 1 121596 976712583 ee EFI GPT

WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.


Disk /dev/sdb: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/sdb1 1 30402 244198583 ee EFI GPT

In this case the drive I'm interested in is the 250 Gb one, and it is at /dev/sdb1.

2. Run gparted to partition the drive.
> sudo /usr/sbin/gparted

gparted is a gui application. I'm running it over an ssh connection (using the -Y option), so it will display on my Mac OS X machine using the X11 server that's part of Mac OS X. Choose the relevant drive (/dev/sdb), and delete all the current partitions. All the available space should be shown as "unallocated" when you're done. Click Apply to make the changes to the disk - note that this will destroy any data on the drive!
The new partition needs a filesystem before it can be used. This can also be done with gparted: click New, change to ext3, primary partition should already be selected and the other defaults are OK. Click Apply and wait a while. The bigger the partition, the longer the wait. Once this is complete the drive is ready for use, but the operating system needs to gain access by mounting it.

3. Now to define a mount point. In my system, these are at /mnt, and running ls -l /mnt shows the default permissions:
> ls -l /mnt
total 12
drwxr-xr-x 2 root root 4096 2010-04-30 14:18 cuda_80
drwxr-xr-x 2 root root 4096 2010-09-06 15:16 five_hundred
drwxr-xr-x 4 root root 4096 2010-12-23 13:59 raidk

cuda_80 is the drive that I'm replacing - the physical drive has already been removed from the system, and I've removed it from fstab and smb.conf. The new drive I'm calling alfred (I watched Batman last week), so I'll rename cuda_80 to alfred rather than deleting it and creating a new one. This will maintain the correct permissions, too.
> sudo mv /mnt/cuda_80 /mnt/alfred


4. I need to know the drive's UUID so I can add it to the fstab file. Using the UUID makes it independent of the /dev/* information, so that if other drives are added or removed and the drive ordering changes, this drive will still mount OK. The UUID is retrieved with:
> /sbin/blkid
/dev/hda1: UUID="0521aa47-4fdb-424e-bd83-0f6b164e55f5" TYPE="ext3"
/dev/hda5: TYPE="swap"
/dev/sda1: UUID="637d0461-72d5-40c2-9446-04a45912eb8e" SEC_TYPE="ext2" TYPE="ext3"
/dev/sda5: TYPE="swap"
/dev/sda2: UUID="13A3CE68BA98A5AF" LABEL="Untitled" TYPE="hfsplus"
/dev/sdb1: UUID="a5c5ba62-3c58-4ff4-9d1c-6d754f4430f0" SEC_TYPE="ext2" TYPE="ext3"

Using the information from step 1, I know the drive is at /dev/sdb1, so the UUID is the long string starting with a5c.

5. Now to edit fstab. I'll do this in gedit, which has a gui interface so I can cut and paste.
> sudo gedit /etc/fstab

I'm duplicating a fstab line that works, then changing the UUID and mount point to the values determined in the previous steps. My extra line in fstab is:
UUID=a5c5ba62-3c58-4ff4-9d1c-6d754f4430f0 /mnt/alfred ext3 defaults,errors=remount-ro 0 2

The line is made up of 6 fields separated by tabs. The UUID and the mount point are the first two. The third is the filesystem type (ext3 in this case), and the fourth is a collection of options (see the fstab or mount man pages for details), the fifth has something to do with dumping the filesytem (I've never really read the finer details) and the final field "determines the order in which filesystem checks are done at reboot time." Root filesystems should have the value of 1, but this is not a root filesystem so it has the value of 2. This also gives the USB drive time to get going during startup so that it's ready by the time the OS looks for it.

6. Now that the fstab has been edited, it should be possible to mount the filesystem. This can be done as follows:
> sudo mount -a

There's a little bit of noise from the drive, and running df -h shows that the drive is now mounted (the -h option causes the drive sizes to be shown "human readable").
> df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda1 72G 4.7G 64G 7% /
tmpfs 253M 0 253M 0% /lib/init/rw
udev 10M 768K 9.3M 8% /dev
tmpfs 253M 0 253M 0% /dev/shm
/dev/sda1 917G 200M 871G 1% /mnt/raidk
/dev/sdb1 230G 188M 218G 1% /mnt/alfred

It should also be mounted automatically when the system restarts.