True's beaked whale.jpg

Western spotted skunk

Hooded skunk

Yellow-throated Marten

Wolverine

Archive for the ‘linux’ Category

Disk mount issue

Monday, November 27th, 2023

I added a new disk, removed one on my workstation. It is running Ubuntu 20.04. Booted up, and the drive letters have changed, and the md number of a RAID 1 array changed. So I updated /etc/fstab and went to mount the /dev/md1 array. The mount command completes without error, but the disk did not mount. Turns out, needed to:

systemctl daemon-reload

Then the mount worked, and I could add the new disk to the RAID 1 array.

Limit Firefox memory

Saturday, November 11th, 2023
  1. Open Firefox, go to about:config.
  2. Go to browser.tabs.unloadOnLowMemory, set it to true.
  3. Go to browser.low_commit_space_threshold_mb, set it to 2/3 or 3/4 of total memory on your computer. (e.g. 32GB -> 24000).

Downloading a video from an ebay listing

Wednesday, March 8th, 2023

Using Firefox, go to the item page, open the Firefox Web Developer Tools (Menu -> More tools -> Web Developer Tools). Click on the Network tab in the Tools section, then on the web page click on the video and play it.

In the Network tab, requests for audio_128kb-0.m4s to audio_128kb-16.m4s appeared, and video_720p-0.m4s to video_720p-16.m4s. I copied the URL for the video and audio requests (all the same but with a different -0 to -16 segment), and used wget to download the files. Each was 1-2 MB:

wget https://video.ebaycdn.net/videos/v1/8f1e79501860a64d9e245434ffffec91/5/video_720p-0.m4s

After 32 wget commands, the entire video was present. I downloaded segments from 0 up until after number 16, I got a ‘not found’ message letting me know I had the last segment.

Then I concatenated the pieces together:

cat video_720p-0.m4s >> video_720p.m4s
cat video_720p-1.m4s >> video_720p.m4s
...
cat video_720p-16.m4s >> video_720p.m4s

And the same for the audio segments. I put the cat commands into a batch file “cat.txt” and ran them using “bash cat.txt”.
Then ffmpeg was used to combine them and convert to mp4 format:

ffmpeg -i video_720p.m4s -i audio_128kb.m4s -c copy ebay_720p.mp4

Using cron to mute sound in Ubuntu 20.04

Wednesday, August 18th, 2021

I wanted to turn off audio at night automatically using cron.

I saw suggestions to use amixer:
export DISPLAY=:0 && /usr/bin/amixer -D pulse sset Master,0 0%
but this gave an error:

ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused
amixer: Mixer attach pulse error: Connection refused

This works, add this line to /etc/crontab:

* 23<tab>* * *<tab>jiml<tab>DISPLAY=:0.0 pactl --server unix:/run/user/1000/pulse/native set-sink-mute @DEFAULT_SINK@ true

and restart cron:
service cron restart

jiml is the user with the open desktop.
‘1000’ is the uid of user ‘jiml’, this can be found by:

ls /run/user
or
id -u jiml

and restart cron:
service cron restart


jiml is the user with the open desktop.
‘1000’ is the uid of user ‘jiml’, this can be found by:

ls /run/user
or
id -u jiml

Saving streaming audio on Linux

Saturday, January 30th, 2016

MONITOR=$(pactl list | egrep -A2 ‘^(\*\*\* )?Source #’ | grep ‘Name: .*\.monitor$’ | awk ‘{print $NF}’ | tail -n1)

goes to alsa_output.pci-0000_00_1b.0.analog-stereo.monitor on my system

LAMEOPTIONS=’ -s 44.1 –preset cbr 192′
FILENAME=foo.mp3

Record currently playing audio:
parec -d $MONITOR | lame $LAMEOPTIONS -r $FILENAME

Split into separate 1 hr files with a 3 sec overlap:
ffmpeg -ss 00:00:00 -t 01:00:03 -i foo.mp3 $1.01.mp3 -acodec copy
ffmpeg -ss 01:00:00 -t 01:00:03 -i foo.mp3 $1.02.mp3 -acodec copy

Commands from here

Switched to the Cinnamon window manager

Sunday, January 13th, 2013

I run Ubuntu on my main home machine, but the latest 12.04 LTS release has a terrible, barley useable window manager.

I’ve switched to Cinnamon, following the instructions here. Now it all works like it is supposed to.

Converting .m4a sound files to .mp3

Thursday, February 11th, 2010

Converting a single file:

faad -o - file.m4a | lame - file.mp3

Bash script for converting multiple files:

-----------------------
#!/bin/bash

for i in *.m4a; do
    echo "Converting: ${i%.m4a}.mp3"
    faad -o - "$i" | lame - "${i%.m4a}.mp3"
done
-----------------------

Spelunking partition tables with testdisk

Friday, February 6th, 2009

I have my home directories on a separate drive from the OS, and after upgrading Fedora I went to remount my home directory and ran into problems. First off, the new Fedora had renamed hda as sda and so all the drive naming was off. I had my home directory disk mirrored in RAID 1, but some months ago one the the drives went bad and I dropped it from the array but left it plugged in until I had time to deal with it.

So I looked around for my home directory disk and mounted the one that had gone bad. It was working fine when I mounted it, so I didn’t notice until a few days later when it I noticed recently created files were missing and eventually figured it out.

So I could find the ‘good’ home directory disk and mount it, right? Not so easy, it turned out to have a small ext2 partition and a large LVM partition. Which is not the way it should be, it should have one partition. I mount the small one, and it throws ‘read past end of disk’ errors. It takes quite a while to figure out how to mount and read the LVM partitions. LVM is a really, really idea. The LVM tools couldn’t find a filesystem on the LVM partition, and after much hair pulling I realized that there really *wasn’t* one, that the partition shouldn’t exist. Because it was LVM, this took about 10X longer than it should have.

Now running with the hypothesis that the home directory disk had picked up a disk error in the partition table (Argg^&@$#@!), I made a backup image of the drive using dd:

dd if=/dev/hdc of=/data/hdc_copy.bin

Then I mounted the image as a loopback device:

losetup /dev/loop0 /data/hdc_copy.bin

And started working with the image to repair it. Looking around, testdisk seemed promising, so I installed it, ran it. Testdisk finds potential partitions on the disk, and lets you view the files in them to see if it has guessed right. After a few tries I found a testdisk partition that contained my home directories. At this point I used testdisk’s copy function to save the most critical recently (no backup) changed directories. This worked and I was hopeful. Then I had testdisk write the partition it had found to the disk image.

Now running fdisk on /dev/loop0 shows the single partition (/dev/loop0p1) spanning the whole disk as expected. /dev/loop0 can’t be mounted by itself as it is an image of the disk, not a file system (/dev/loop0p1 isn’t a device in /dev, just a fdisk label). So I had to mount the partition as a second loopback device using the info from fdisk to find the correct offset:


Disk /dev/loop0: 203.9 GB, 203928109056 bytes
1 heads, 1 sectors/track, 398297088 cylinders, total 398297088 sectors
Units = cylinders of 1 * 512 = 512 bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/loop0p1 64 398283327 199141632 83 Linux

So I tried an offset of 64 * 512 = 32768:

losetup -o 32768 /dev/loop1 /dev/loop0

and then ran e2fsck on /dev/loop0. But e2fsck wasn’t happy, and none of the alternate superblocks worked either. Finally I found a reference to doing this that mentioned setting fdisk to sectors first:


Command (m for help): u
Changing display/entry units to sectors

Command (m for help): p

Disk /dev/loop0: 203.9 GB, 203928109056 bytes
1 heads, 1 sectors/track, 398297088 cylinders, total 398297088 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/loop0p1 63 398283326 199141632 83 Linux

Ah ha, the sector offset is *really* 63, so 63 * 512 = 32256 bytes, and after

losetup -o 32256 /dev/loop1 /dev/loop0

e2fsck now sees the file system and works! BTW sending e2fsck the SIGUSR1 signal makes it show a progress bar:

kill -s SIGUSR1 <e2fsck pid>

and after e2fsck completes I can mount the now good file system:

mount /dev/loop1 /mnt/home_recover
and it works!

With a good copy of the home directory filesystem I now was willing to risk changing the original drive, and ran testdisk and e2fsck on it following the same course. I was able to fix the partition table, clean the filesystem, and mount it! My home directories are all back!

Scanning and posting photos

Tuesday, January 20th, 2009

I scanned in a bunch of family photos, fixed them up, added captions, and posted them on Google’s Picasa Web Album.

I used a flatbed scanner and filled it with photos each scan. This necessitated splitting and cropping each scan into separate images. To speed this along I wrote an AppleScript to call Photoshop’s “Crop and Straighten Photos” function and then save the images.

split_img Applescript

The script worked pretty well for about half the images. I went through and cropped/straightened each image. Then I automatically ran Auto Levels and Auto Contrast or Auto Colors on each image using a second Applescript.

adjust_img Applescript

I wanted to add captions and tags to each image using a list of captions I made when I scanned the photos. Jpg images can store this meta data in the file using the IPTC standard. Unfortunately, Google’s Picasa uploading applications terribly buggy and don’t work well with IPTC tags added by other programs like iPhoto or EXIFutils. So I couldn’t use Google’s Picasa software or plugins to upload the photos.

Google makes an API for interacting with their web sites available, and there is a Perl module, Net::Google::PicasaWeb, available that allows adding captions and tags when uploading pictures. Testing showed that it worked so I wrote a small Perl program to take a tab-delimited text file of images, the target album, the caption, and any tags and load the photos onto the Picasa Web Album site. I needed to use the most up to date version of Net::Google::PicasaWeb and make a one line change.

picasa_upload Perl program

My Picasa Web Album:

Old family photos (Jan. 2009)

RAID1 recovery

Thursday, December 8th, 2005

One of the MA database systems went down. It wouldn’t boot, so we put in the install disk, ‘linux rescue’ at the prompt, and it booted into rescue mode. The system is set up with the system files on a pair of RAID1 SATA drives. Drive /dev/sda was gone–fdisk found no partition. /dev/sdb was fine. I looked around for hacking traces but found nothing. /var/log/messages indicated the system had shutdown for reboot two days before. We hadn’t done it, so how/why?

First, I re-partitioned /dev/sda to look like /dev/sdb using the same ‘fd’ RAID partition type.

To bring it back up, I shut down, switched the sda and sdb cables so we could boot off the good drive and then have RAID restore the second drive. The original /dev/sdb didn’t have grub installed on the MBR, so I had to reboot with the rescue disk and reinstall grub.


/mnt/sysimage/sbin/grub
grub>root (hd0,0)
grub>setup (hd0)

I had to use grub because grub-install wasn’t available from the rescue environment and /mnt/sysimage/sbin/grub-install couldn’t find /sbin/grub.

Then reboot, grub comes up, the system boots. The root /dev/md1 RAID1 is degraded as this shows, so add /dev/sdb back:


mdadm --query --detail /dev/md1
...degraded...

mdadm --add /dev/md1 /dev/sdb

And 20 minutes later the array is clean!