Error opening /dev/sda: No medium found

I have had this issue before, solved it, and had it again.

Let’s say you plug in a USB drive into a Linux machine, and try to access it (mount it, partition it with fdisk/parted, or format it), and you get the error

Error opening /dev/sda: No medium found  

Naturally the first thing you will do is ensure that it appeared when you plugged it in, so you run ‘dmesg’ and get:

sd 2:0:0:0: [sda] 125045424 512-byte logical blocks: (64.0 GB/59.6 GiB)  

And it appears in /dev

Computer:~ $ ls /dev/sd*  
/dev/sda  
Computer:~ $  

Now what? Here’s what has bitten me twice: make sure the drive has enough power. Let’s say you mounted a 2.5" USB drive into a Raspberry Pi. The Pi probably doesn’t have enough current to power the drive, but it does have enough to make the drive recognisable. Or, if you are like me, the USB charger powering the drive is faulty, so even though it has power, it doesn’t have enough.

The next troubleshooting step should be obvious: give the drive enough power to completely spin up.

Lessons Learned from Kathmandu

My first trip to Kathmandu is now over, so there are some lessons learned I should scribe. Some of these are obvious, and which I abide by whenever travelling, and some I simply forgot in my (very) impromptu trip to Nepal.

  • When agreeing on a price, make 100% sure the other person states the price back to you. I thought a price had been agreed to when the other person responded “ok ok, you are a lucky man”, but this does not count. As they say, reconfirm, reconfirm, reconfirm.
  • When arriving at the airport, make sure you have small bills, too. I had 3x 100RS, 1x 10RS, and then a few 500RS. The price I negotiated was 440RS, and it would have been nice to have paid the exact amount.
  • Kathmandu is polluted and dirty. I cannot emphasise this enough. It is dirtier than probably any other city I have been to. If I come back, I will be bringing masks. I know this sounds silly, to wear a mask, but any local on a motorbike or in a taxi wears a mask, and many just walking around. Instead of the normal cloth masks that many people use, I would probably bring a make with finer grained material - probably N95. I ultimately tried to avoid walking on main roads, but having some activated carbon absorb something would have made it a little less unpleasant.
  • Bring old cloths, and throw them away after the trip. Or just bring black. If you have nice jackets or clothing they will likely come back pretty dirty.
  • Bring some toilet paper. Similar to other parts of Asia, the bathrooms don’t have any.
  • Bring a flashlight. The load shedding makes the city dark, and if you go out, you will want a flashlight. There aren’t any lights. I only used it a few times, but I am really glad I brought two flashlights with us.
  • Bring vitamin C and lots of hand sanitizer. I did, like I always do when I travel, and I’m really glad I did. Everybody is coughing or sick, and everybody spits. It is similar to the situation in China, i.e. everyone spits. Then everybody gets sick. Bring hand sanitizer.
  • If you take a bus somewhere, try to ask when you buy tickets to sit on the left side in the middle. The front is a no-go for me. I typically had seats in the rear right, but on the curvy roads I think the left middle would be safer, as oncoming buses won’t hit you. One bus on the way back had the left side decimated. If you do a search on “nepal bus crashes” in images.google.com, you will quickly see why you don’t want to be in the front row.
  • My hotel rooms all typically had just one power outlet. If you bring multiple electronic devices, bring some way to  charge more than one at a time.
  • Bring clothing to stay warm at night. I travelled to Nepal in winter, and all my rooms got pretty cold at night.

Enjoy!

Lessons Learned for Lightweight Travel to Europe

Now that my Europe trip has ended, I need to leave a note of things I wish I had done better, both travel-wise, and the stuff I brought along.

I like to travel light, and find it a little comical when I see people struggling with giant 70L backpacks; I always do carry-on, no matter for a two week trip, or two months. (This means my packs have to weigh less than 7KG). Even in winter it is possible to pack light. The trick seems to be only packing what one will use regularly, with no duplicates, of appropriate size, and hopefully reusable for other purposes. Don’t pack anything you would be gutted if it broke.

The lessons below are not just to pack light, but also to reduce stress. Some really only apply to me for next time :) This is not a howto list on packing light for travel, just a few things I need to do better for next time.

Electronics
Only bring electronic devices that can be charged by USB, which leads me to my next point…

Look on eBay for a USB charger that has multiple inputs (make sure it has enough amps if you are charging certain phones). It became a hassle trying to charge four or five devices using just one USB charger. The charger, if going to Europe, should have room to accept a ground, or be able to get around the ground plug used in many places. In other words, get one like (broken old link) not like (another broken link) (basically, not like any of the block ones from eBay). Once again, try to get a 4-port one with travel adaptors included.

I’m going to consider not bringing my Kindle next time, but instead bring one paperback book. The weight might be about the same. I might not even bring a book - less stuff to break or get wet. I don’t do much reading on my travels anyway, instead writing in a journal or finding out what to do next.

Get an Eye-Fi or be able to read a USB stick with my phone. I need to figure out a way to backup photos from my camera to the cloud every night using only my phone (if the hotel has free wi-fi). Sorry if you are the guest next door…

Going Light

Don’t bring jeans, or bring only one nice pair of pants for semi-formal situation. I have to admit, I almost never wore my jeans. After only wearing them once or twice they would get wet, dirty, and/or smelly, so I would be forced to wear my Columbia hiking pants over and over! The pants are not particularly stylish, especially in European cities, but they are reasonable warm, repel water, dry quickly, and are exceptionally light. After weeks of abuse they didn’t smell, or look dirty, somehow. I’m a bit of a Columbia fan…

Try to find one pair of shoes that are ergonomic and athletic enough for walking 20KM/day, or on a trail, but also stylish enough to go into a nice restaurant and not draw too much attention. And dry quickly. I don’t really have any suggestions, since I’m still looking, but I’m certainly never going to put my Allen Edmonds in a backpack.

Bring cotton undershirts instead of normal shirts for winter travel. I never ended up wearing a t-shirt on the outside, so the shirts were basically just used to keep the rest of my clothing clean. I may look into undershirts that wick better than cotton.

Replace my money belt with something. It is just uncomfortable. I am trying to find an alternative, maybe something that goes over the shoulder instead. I only need something for my passport.

My fingerless gloves worked really well, because I could still use my mobile phone without taking off my gloves.

Staying Clean and Healthy

Bring two large dry bags for dirty clothing, a dry bag for larger electronics, a dry bag for electronic cords/cables/chargers, and a dry bag for lotions and creams. Or get indestructible bags. The zip-loc bags I brought all had holes within the first few days of travel, spewing my cables everywhere. The corners on any bottle tears straight through them. I have since bought some Loksak bags, and a year later they are still holding up.

Bring more vitamins, both Multi and C, especially if in winter. A tube from an energy capsule mix would work well to store them in, or Vitamin C fits well into a Tic-Tac container. Only bring enough pills that you need. For instance, I usually only bring two pills of Gastro-Stop, because that stuff works maybe too well. Also, vitamins were really inexpensive in parts of Europe compared to most places I have lived.

Long Johns next time I travel in winter and it looks to go below 0C. I were OK, but that extra layer would have been nice.

Buy a Mach 3 as soon as possible. I tried shaving in Prague before the opera with a normal three blade razor, and it was horrible. I had to use an entire pack just to see skin, and even then had little patches of hair that I couldn’t get. I’m never making that mistake again. Alternatively, I’m thinking of getting a portable Sanyo electric razorthat I saw my dad use when I were in New Zealand.

RELATED: I have added a similar entry on my recent trip to Nepal (12/2012).

Reload a Cisco Router WIthout Worry

Recently I tried editing my Cisco’s ACL at home on the train. It went something like this:

  • I logged in
  • I started updating the ACL
  • I hit a blackspot in my 3g coverage
  • My command stops at “router(config)#access-”
  • I get an alert saying my home internet was down

Although it is simple enough to just ask her to “flip the switch on the black box”, I still don’t like doing it. Plus, if she’s not home, I’m stuck. This accident immediately reminded me of one of a trait of the ‘reload’ command: it can be scheduled.

In the case of updating a device remotely, it is as easy as:

router# reload in 2
router# conf t
router(config)# [type in desired commands]
router(config)# exit
router# reload cancel

If the commands are entered in fine, then cancel the reload. If there is a problem, then the router will reboot and resort to the startup config.

Beginning Scripting ESXi

I’m not impressed too often with much software, especially the closed source kind. I find a leaning preference to all things FOSS. If I had a million dollars, I’d likely spend all day contributing to all the projects I wish I had time to contribute to. Regardless, there are a select few closed-source products that I believe are truly excellent. I mean, the type of software where you aren’t asking “I wish this could do this” and start asking “I wonder what else this can do.”

While I’ve played around with most types of virtualization out there (OpenVZ, Xen, V-Server, qemu…), I’ve really found a soft spot for VMWare.

Don’t get me wrong, if I was going to host a heap of Linux web servers I would absolutely use Xen, but for a heterogeneous environment, I haven’t used anything as easy as VMWare’s products. Not that I judge a product by how easy it is to use, not by a long shot, but ease of use sure makes judging other factors easier.

Regardless, this isn’t a post trumpeting VMWare. I just realized tonight that some of the VMs I have running don’t need to be except for certain hours of the day, or if condition A is true. The first example is my backup mail server; I really don’t need it even powered on unless my main server is down. The second example is my Server 2003 instance, which has VI3 on it; I don’t need this running unless I’m asleep. One of the most useful resources I’ve seen for the vmrun command is over at VirtualTopia – loaded with examples.

Turn off via time

On my “monitoring” instance, which is always up, I’ve decided to install the script that controls my VM. I’ve opted to use a soft shutdown.

192.168.0.10 = ESXi box

datastore1 = name of datastore that hosts VMs

#!/bin/sh
 
vmrun -t esx -h https://192.168.0.10/sdk -u root -p root_password stop "[datastore1] Server 2003 R2/Server 2003 R2.vmx" soft

I have that saved in a file called stop_2003.sh in /opt/vmware/bin; make sure it isn’t world readable. I also have a start_2003.sh:

#!/bin/sh
 
vmrun -t esx -h https://192.168.0.10/sdk -u root -p root_password start "[datastore1] Server 2003 R2/Server 2003 R2.vmx"

Next, edit root’s crontab (crontab -e):

# m h  dom mon dow   command
0 8 * * * /opt/vmware/bin/start_2003.sh
0 23 * * * /opt/vmware/bin/stop_2003.sh

The conditional task is a tad bit more tricky, but just a tad. Ping won’t do, since the mailserver could go down itself, so install nmap. Create a script:

#!/bin/bash

if nmap -p25 -PN -sT -oG - mail.kelvinism.com | grep 'Ports:.*/open/' >/dev/null ; then
echo \`time\` >> mailserver.log
else
/opt/vmware/bin/start_mail.sh
fi

And sticking with our theme, start_mail.sh:

#!/bin/sh

vmrun -t esx -h https://192.168.0.10/sdk -u root -p root_password start "[datastore1] Mail Server/Mail Server.vmx"

This of course changes the crontab entry to:

#!/bin/bash
 
if nmap -p25 -PN -sT -oG - mail.kelvinism.com | grep 'Ports:.*/open/' >/dev/null ; then
echo `time` >> mailserver.log
else
/opt/vmware/bin/start_mail.sh
fi

So, that’s it. detect_port.sh is lacking any type of error detection or redundancy - if one packet/scan is dropped, the mail server will turn on. I’ll re-work this at some point, but it works for now.

Update: Vmware has also released a decent blog entry about using vmrun: on their blog.

Speeding Up VMWare Server

I found VMWare Server to have very slow I/O, and sought to improve it. Below are a list of tests I performed, the change, and the results.

  
  
### Host OS ###  
/dev/sdb1:  
 Timing buffered disk reads:  220 MB in  3.05 seconds =  72.17 MB/sec  
kelvin@gorilla:~$ sudo hdparm -t /dev/sdb1  
  
/dev/sdb1:  
 Timing buffered disk reads:  266 MB in  3.01 seconds =  88.33 MB/sec  
kelvin@gorilla:~$ sudo hdparm -t /dev/sdb1  
  
/dev/sdb1:  
 Timing buffered disk reads:  310 MB in  3.01 seconds = 102.99 MB/sec  
  
  
### Before Changes ###  
  
/dev/mapper/openfiler-data:  
 Timing buffered disk reads:    8 MB in  3.36 seconds =   2.38 MB/sec  
[root@files etc]# hdparm -t /dev/mapper/openfiler-data  
  
/dev/mapper/openfiler-data:  
 Timing buffered disk reads:   24 MB in  3.63 seconds =   6.61 MB/sec  
[root@files etc]# hdparm -t /dev/mapper/openfiler-data  
  
/dev/mapper/openfiler-data:  
 Timing buffered disk reads:   28 MB in  4.54 seconds =   6.16 MB/sec  
  

I made several changes, but the changes that seemed to have the most impact are below:

vm.dirty_background_ratio = 5  
vm.dirty_ratio = 10  
vm.swappiness = 0  
  

Pop this into the virtual machine’s .vmx file, reboot, and off you go. One unfortunate side effect is that you can no longer overload the memory (e.g. allocate more memory with the VMs than you actually have available).

  
  
### After Changes ###  
  
/dev/mapper/openfiler-data:  
 Timing buffered disk reads:   52 MB in  3.13 seconds =  16.61 MB/sec  
[root@files ~]# hdparm -t /dev/mapper/openfiler-data  
  
/dev/mapper/openfiler-data:  
 Timing buffered disk reads:   82 MB in  3.31 seconds =  24.75 MB/sec  
[root@files ~]# hdparm -t /dev/mapper/openfiler-data  
  
/dev/mapper/openfiler-data:  
 Timing buffered disk reads:  118 MB in  3.19 seconds =  36.97 MB/sec  
[root@files ~]# hdparm -t /dev/mapper/openfiler-data  
  
/dev/mapper/openfiler-data:  
 Timing buffered disk reads:  144 MB in  3.32 seconds =  43.37 MB/sec  
  
[root@files ~]# hdparm -t /dev/mapper/openfiler-data  
  
/dev/mapper/openfiler-data:  
 Timing buffered disk reads:  160 MB in  3.10 seconds =  51.57 MB/sec  

UPDATE: Those wanting all the speed and still want to use memory overloading, I’d suggested you give ESXi a try. So far, so good.

  
## With ESXi, same hardware ##  
[root@files ~]# hdparm -t /dev/mapper/openfiler-data   
  
/dev/mapper/openfiler-data:  
 Timing buffered disk reads:  200 MB in  3.18 seconds =  62.92 MB/sec  

My Portable Travel Stick

This will be my last post from Taiwan, and I’m placing it in my tech section. Shortly I will be flying to Hong Kong, and then traveling into China. I’m not bringing my laptop with me. I’m always a little wary of using public computers, especially in many of the poorly run internet cafes. Often the logged in user is the administrator, and we all know the computers are obviously crawling with worms and keyloggers. What can I do?

I had a 128MB flash drive, which is the perfect size fo this. I’ve installed the following applications to run directly from it:

  • Portable Clamwin - I plan to fire it up and do a memory scan before I start typing any passwords.
  • Portable Putty - This is useful for two reasons. Firstly, in case my server (or any server with SSH) needs help, I’m on it. Secondly, and more importantly, for security. Putty can easily be used as a SOCKS5 proxy over SSH, so I can tunnel Firefox and IM securely. Password sniffers, be gone! A side benefit is the ability to bypass the “Great Firewall”, if needed (e.g. the block my Google account).
  • Portable Miranda - In case I’m feeling home sick, or have some crazy desire to talk on IRC. Don’t count on it.
  • Firefox - I tried the Portable Apps package, yet it didn’t work.

I noticed in the “known issues” that it doesn’t work if loaded on a drive with a non-asci path, which this machine (and those in China) usually have. The “resolution” is to run it in Win98 compat mode, but this didn’t work for me. To get around this, I downloaded the normal Firefox, installed it, copied the contents of “Mozilla Firefox” and dumped it in /Firefox. Then I created a profile directory called /FFProfile, and created a bat file called “firefox.bat”:

start \Firefox\firefox.exe -profile \FFProfile

Double click the bat file, and you have FF running on your usb drive.
I’m in a search for a better keylogger detector, as I don’t know how complete ClamAV will be. If you know of one, let me know. Until then, I’m going to pretend I have the perfect traveling USB companion.

Turn Off Google Suggest in Firefox

I generally like Firefox, and generally like Google. But having Google suggest enabled when I search for things is annoying, at least on my rather small laptop screen. Mostly it is because my internet right now is pretty average, so I try to cut down on any extra traffic. Anyhow, I didn’t even both Googling how to do this:

Type in ‘about:config’ into your address bar and type ‘search’ in the top filter bar. Look about half-way down for this:

browser.search.suggest.enabled

Double click it to turn it to false. All done.

Where the heck is my Diskspace

Logs spiraling crazy, we run out of disk space all the time. A nifty trick to find where the disk went is to issue:

du -cks * |sort -rn |head -11

This returns where the disk usage is, and makes finding the bloated log a lot easier.

Firefox + BugMeNot

Here’s a tip for Firefox. An extension called BugMeNot enables you to right click on “general” forms and say “Login with BugMeNot.” Firefox will call the BugMeNot extension which looks up in an external database login information. For instance, www.nytimes.com requires a login, which is a great place to test it out.

http://extensionroom.mozdev.org/more-info/bugmenot