Mar
21
2012

Mounting A WD Elements Drive At Boot

Gentoo Init Script Hacking

(Add / View Comments) (0)Wednesday, March 21, 2012 - 10:44:23 pm
(Posted Under: Gentoo Linux Gentoo Linux)
So, this was a fun way to kill an afternoon. I picked up a WD Elements drive over a year ago. The 2TB drive has saved my life, despite the fact that it's been teetering on being almost full for months. I can not be trusted with disk space.

Anyways, I've never had the thing successfully mount on boot. Which is somewhat of a pain, since it contains a number of other loop files that need to be mounted that I rely on. Though, given how infrequently the machine gets rebooted, I've just done that manually. However, when the server crashed today, I decided it was time to probably fix that. Especially since I've had the mysqld data directory temporarily moved to that drive for some time (though, after tonight now moved back to /var on a fixed disk).

Through trial and error, and countless reboots I was able to finally work out the culprit - the slow spin up time on the drive. At the point that localmount is executed, the system doesn't know about the partitions on the drive - fails to mount it, and subsequently all of the loop files also fail.

The trick to fix this was to move the mounting of usbfs to the beginning of the script. Following that, probing /dev/sdb1 (for 2 minutes) until it's available. Not sure exactly how long it takes, but it's at least 10 seconds. Once that it is, mount the usb drive, and then mount everything else as per the original localmount script.

   # Wait up to 2 mins for Elements partition to be available
   ebegin "Probing /dev/sdb1"
   i=0
   while [ $i -lt 120 ]; do
      if [ -b /dev/sdb1 ] || [ -b /dev/sdf1 ]; then
         eend 0
         break
      fi
      ((i++))
      sleep 1
   done
   [ -b /dev/sdb1 ] || [ -b /dev/sdf1 ]
   eend $?
   # Mount the elements drive
   mount /mnt/usb/elements
   [ $? != 0 ] && mount /dev/sdf1 -t reiserfs /mnt/usb/elements
The checks against /dev/sdf1 may be unnecessary. In the past I've seen the drive fairly randomly assigned to /dev/sdb and /dev/sdf (seemingly thanks to the numerous USB card readers the machine has) so I added this to make things "just work", since I don't have a monitor attached to the box, and don't care to have to go back to this. But after implementing this, the device seemed to fairly reliably get assigned to /dev/sdb. The explicit mounting of the drive is probably also unnecessary, but I included it for the same reason.

This wasn't really how I had planned on spending 3 hours after work, but finally having the system come up right on boot without any manual intervention makes it worth while.

Switch Styles

About Style Switching.

!Weblog Index

Feb March 2012 Apr
SU MO TU WE TH FR SA
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Categories

RSS FeedRSS Feed