Gettin’ Down & Grubby with Grub!

Last week I broke down and bought myself a shiny new (refurbished) an HP “Elitebook” 8440p lappy! 😀  It’s been ten long years or so since my last computer purchase (also a corporate refurb).  My way is to buy a good used one from a generation or two back, put Linux on it and have a faster machine than most brand new ones whilst saving a ton of money.  My last one’s been great as a docked desktop paired w/a big monitor, but has become a very crappy laptop that runs hot, has no working battery, and the hinge won’t hold the lid up anymore.  Portability issues aside, it still performs very well, especially for its age.  I’ve even been complemented on how snappy it is, considering it’s age.
This “new” lappy came with a huge, terrabyte SCSI hard drive (the good ol’ fashioned spinning kind, which I prefer) loaded with a fresh install of Windows-7 Professional 64 bit to complement it’s eight gig of RAM.  I ended up shopping longer and paying a tad more in order to nail down one of the (apparently rare) ones that has the higher-resolution (HD+) screen sporting 1600×900 resolution (most come w/a crappy 1366×750 screen) combined w/the non-dedicated integrated Intel graphics.  The reason I wanted Intel graphics is that it’s no hassle to get to work well with Linux, runs cooler, and yields longer battery life than the Nvidia dedicated version.  The box arrived from Odyssey Computers via Amazon with free shipping in three days!  It contained a nice, shiny clean new-looking computer and 65 watt HP power supply wrapped in a generous supply of bubble wrap.  I plugged it in, opened the lid, turned it on and was greeted with Windows-7’s “First Use” screen.  I read the eula, signed over my first born to lifetime servitude to Bill Gates Inc., created an abUser account, and set it up. I confirmed the graphics, screen, hard drive, and RAM quickly through Windows’ Device Manager.  One fear that I had was that Windows would be set to boot under UEFI, making my task much more difficult, but I poked around in the bios and determined that, thank goodness, that was not the case.
Now, on to the Linux setup!  I remastered my current Antix Linux setup using Antix’s unique and very cool “snapshot” tool onto a DVD, inserted it and booted it right up.  First order of business was to run gparted and determine the partition layout for Windows.  This revealed three existing NTFS partitions: a 12 gig “Recovery”, a 150 meg “SYSTEM”, and the remaining 919 gig “Windows” (C:).  This meant we had the fourth and final partition slot available for creating an extended partition and filling it with logical partitions to our hearts content for Linux!  I then proceeded to create the extended partition and added logical Linux partitions for root, var, swap, and home in that order.  It’s fully ok and preferable (to avoid tiny slices of unusable disk space) to select “Alignment: None” for each one as you create it.
This is where the good ended and the bad began: ALL three were NTFS (INCLUDING the first) AND, the SECOND (NOT the first) one was marked as the “boot” partition.  This meant NO installing Grub boot-loader in the MBR (The normal location) and most likely having to modify the Windows boot-loader to launch Grub and Linux from the Linux “root” partition we would create.  Still no biggie, right? (WRONG!)  Fortunately for me, I started googling around BEFORE I attempted an install and found out that this might be a bit more difficult (little did I know yet!).  I had installed Antix once before on another Windows-7 machine with only a couple of minor hiccups involving Windows booting via “chainloading”, but that one was set up the “normal/proper” way with a FAT32 partition at the beginning for booting (just put Grub in MBR, add “hide/chainloader” entries for Win-7 and I was good to go).  I quickly learnt that GRUB would not play nice if put into an NTFS partition.  I also became acquainted with an obscure Windows program called bcdedit.  I went ahead and played with that and successfully added a second entry in the boot menu for Linux.  I then cautiously created all my Linux partitions using gparted and installed Antix. Then I carefully created the special “antix.bin” file and gently placed it into the Window’s C:\ directory as instructed in my research and rebooted.  I was quickly greeted again with my Windows boot menu containing two entries:  “Windows” and “Antix”.  I selected “Antix” and…BLACK SCREEN.  Tried again with “Windows”, Windows booted up as normal.  Oooo-kaaaay, back to Google . I then learnt that Grub Legacy (the version I use since I’ve found Grub 2 very hard to configure with a labyrinth of separate configuration files) also doesn’t play nice if installed into an ext4 partition (unless it’s the MBR/boot partition (hd0,0)).  So, rinse, spit, repeat – this time, tried making the root partition ext2 (ugh!)  This likewise did not work because, come to later find out, the Windows-7 boot loader does not like to talk to ext2 filesystems, even just to boot.  Then came a full twenty-four hour haze of gory details of experimentation that I won’t bore you with here, with little to show for it.  As a last resort, I ended up creating a separate 1 gig FAT32 “boot” partition and with a lot of kicking and screaming from Grub, I finally got it installed there and a working 512 byte “antix.bin” file in the Windows “boot” partition (not C:\) and was able to boot “manually” (It would boot to a cold bare “GRUB>” prompt (when “Antix” was selected), where I could type in a partition identifier (hd0,4), then a kernel line (see menu.lst), then an initrd line, and boot. More googling and T&E revealed that I could just type “configfile /grub/menu.lst” and boot right in. Still more led to making copies of everything in /boot/grub/ to /boot/boot/grub/ (guess we need two matching boots, LOL), and finally, VALA, Linux nirvana!
Lessons learned:
1)  To install Grub in a separate partition (other than the first in the MBR) and be accessible by the Windows-7 boot-loader, one needs to create a separate FAT32 partition and mount it in Linux as “/boot”.
2)  To create the “linux.bin” (I chose “antix.bin”) file for the Window boot-loader, you must first coax Grub into installing it in said FAT32 partition and then use the dd command to grab the first 512 bytes of THAT partition writing it to that file (antix.bin in the root directory of /dev/sda2).
3)  Grub Legacy expects to find it’s “menu.lst” file in /boot/grub/ off of THAT partition (/dev/sda5 or (hd0,4) in my case) even though Linux will have to mount that partition as /boot off of it’s (Linux’s) root (/dev/sda6) and will, along with “update-grub”, expect to find it, along with the other grub stuff in /boot/grub/ off of Linux’s root (/grub in the /boot partition).  Therefore, you must create a “/boot/boot/grub/” subdirectory (off of Linux root – when Linux is booted up) and copy everything in /boot/grub/* to there.  The logical thing to do would be to move it there and create a symlink (cd /boot; ln -s boot/grub grub), but this WON’T WORK because this is all in a FAT32 partition, a rickity old filesystem from the MS-DOS era, so you must COPY the grub tree. You will also need to update BOTH menu.lst files whenever you do “update-grub” or upgrade your kernel, then make sure both menu.lst files match!  NOTE:  It’s only grub that must be copied, NOT your kernels, etc.  They reside one level up in /boot/.
4)  You really should reinstall your kernel package (at least if installing via Antix remaster’s “cli-installer” installer) after you successfully get booted up, since I ran into a few devices modules missing, etc. as I tested things out.  All were fixed by reinstalling / updating my preferred kernel).
5)  Making a “bootable” USB-stick was a good way to test the bootability of my Linux install, but NOT a good way to configure Grub after booting up with it as the system came up with the USB stick seen as “sda” (the FIRST “hard drive”), and my hard drive as “sdB” (the SECOND) – NOT what neither I nor Grub were expecting, forcing manual typing in the boot entry each time!
6)  Grub Legacy is a total BEEACH when asked to configure itself in any way out of the ordinary as far as partitioning goes.  It really wants to reside in the MBR.  As a biased and unabashed Linux user, I expected Windows-7 to be the problem child in the sandbox, but no, it was grumpy, grubby ol’ Grub that had to be dragged kicking and screaming every step of the way and be absolutely beaten into submission!  All the while, Windows gave me no grief whatsoever nor even sneezed or snickered at me as I struggled and fought with Grub.
Ok, here’s the gory details that worked (NOTE, this is only for other unlucky souls who have a non-UEFI booting Win-7 installed with no FAT32 first partition with the “boot” flag” set and no Windows re-install disks).  Otherwise, IF non-UEFI booting, you can MAYBE, MOST LIKELY install Grub (at your own risk) the usual way in the MBR and (maybe) ignore all this!:

NOTE: THIS ASSUMES THE FOLLOWING PARTITION SETUP (I had the 1st three, shrank the third (using gparted), and created the rest and you’ll need to adjust as needed for yours):

     (hd0,0) /dev/sda1:  NTFS - Windows "Recovery"
     (hd0,1) /dev/sda2:  NTFS - Windows "SYSTEM" (boot flag set!)
     (hd0,2) /dev/sda3:  NTFS - Windows (C:)
     (hd0,3) /dev/sda4:  Extended
     (hd0,4) /dev/sda5:  FAT32 (mount as /boot in Linux)
     (hd0,5) /dev/sda6:  ext4 or any other Linux filesystem (mount as / (root) in Linux)

Boot up in Linux Live-CD:

1)  Use garted to shrink the Windows C: partition (I tried to do this in Windows, but it wouldn’t allow me to shrink it as much as I wanted, since Windows likes to put “immovable” – (to Windows), files in the middle or latter part of the partition) gparted SHOULD handle this without fuss (it did for me).

2)  Create an “extended” partition and then your Linux partitions (First one must be FAT32 and will later be mounted as “/boot” in Linux).  Next should be your Linux “root” (mounted as “/”) and be ext4 (my preference) or any other modern Linux filesystem.  Additional partitions are optional (I like to create ones for “/var”, swap, and “/home” in that order).  With 8 GIG of RAM, I don’t really need a swap, but I created an 8+GIG swap for hibernation perposes (Hibernate is a very useful feature on laptops).

3)  Install your Linux, but do NOT install Grub in the MBR!!!  Instead install it in “root” (Linux’s root directory – /dev/sda6 in my case)!  If you are lucky enough to be installing a distro that gives you Grub install choices OTHER than “MBR” or “root” (I wasn’t), then choose your FAT32 partition!  I had to choose “root” (and the slightly-buggy Antix “cli-installer” did not do THAT quite right either – I looked at the script’s code and it appeared designed for Grub-2 with options that Grub Legacy does not recognize), but at least it did not touch my MBR, thank goodness!.

4)  I had to do the following to get Grub Legacy properly installed:

Boot up (again) into my Antix live-CD and:

     mount /dev/sda6 /mnt
     mkdir /media/boot
     mount /dev/sda5 /media/boot
     mount /dev/sda6 /mnt
     vi /mnt/boot/grub/menu.lst:  #WE NEED TO CHANGE OUR "root"s in "menu.lst" AS SO (root=our Linux root (/), (hd0,4) IS OUR NEW /boot)!  (I use the Liquorix kernel, but you need an Antix kernel for the remaster/install):

         title Liquorix, kernel 4.4-6.dmz.1-liquorix-686
         root (hd0,4)
         kernel /vmlinuz-4.4-6.dmz.1-liquorix-686-pae root=/dev/sda6 quiet nosplash ro
         initrd /initrd.img-4.4-6.dmz.1-liquorix-686

         title Antix, kernel 4.0.5-antix.1-486-smp ro
         root (hd0,4)
         kernel /vmlinuz-4.0.5-antix.1-486-smp root=/dev/sda6 ro
         initrd /initrd.img-4.0.5-antix.1-486-smp
         ...

     vi /mnt/etc/fstab:  #THIS NEEDS TO PROPERLY MOUNT /dev/sda5 AS /boot!

         /dev/sda2  /media/Recovery  ntfs-3g noauto,noexec,...
         /dev/sda3  /media/Windows  ntfs-3g noauto,noexec,...
         /dev/sda5  /boot  vfat  defaults,noatime  0 0
         /dev/sda6  /  ext4  defaults,noatime  1 1
         ...

     cp -afv /mnt/boot/* /media/boot  #THIS COPIES ALL OUR BOOT STUFF (GRUB & KERNELS TO OUR /boot PARTITION):
     umount /media/boot  #MAKE SURE THIS IS UNMOUNTED!
     #NOTE:  OUR ROOT PARTITION (/dev/sda6) IS MOUNTED, OUR BOOT PARTITION. (/dev/sda5==(hd0,4)) IS *NOT* MOUNTED!
     for i in /sys /proc /run /dev; do mount --bind "$i" "/mnt$i"; done
     chroot /mnt  #MUST BE IN OUR NEW INSTALL AS "/" TO INSTALL GRUB.
     update-grub  #SO OUR UPDATED "menu.lst" GETS USED!
     #FOR SOME REASON, grub-install DOESN'T LIKE OUR PARTITIONS, SO WE ENDED UP (SUCCESSFULLY) TRYING:
     grub
         grub>root (hd0,4)
         grub>setup (hd0,4)
         grub>quit
     mount /dev/sda2 /media/Windows  #MOUNT OUR WINDOWS "BOOT" PARTITION:
     ls /media/Windows  #CONTENTS OF THE WINDOWS BOOT PARTITION:
         Boot   bootmgr   System Volume Information
dd if=/dev/sda5 of=/media/Windows/antix.bin bs=512 count=1  #(RE?)CREATE OUR BOOT FILE (antix.bin) FOR WINDOWS BOOT-LOADER:
     cd /mnt/boot
     rm -rf *  #WE MUST NOW REMOVE EVERYTHING IN OUR LINUX ROOT'S /boot DIRECTORY SO IT WILL MOUNT PROPERLY!
     mount /dev/sda5 /media/boot #/boot DIRECTORY
     cd /media/boot
     mkdir boot
     mkdir boot/grub
     cp -afv grub/* boot/grub  #VERY IMPORTANT: GRUB LEGACY WILL LOOK FOR menu.lst in "/boot/grub/" WHICH IS "/boot/boot/grub/" TO LINUX ROOT!  GRUB2 MAY NOTE NEED THIS?
     umount /media/boot
     exit
     reboot

5)  Now reboot into Windows-7 and do:

Select Start.Accessories menu, then right-click on “Command Prompt” and choose “Run As Administrator”.
In the (admin) DOS window, do:

     bcdedit /export C:\originalbcd  #BACK UP YOUR ORIGINAL! (/import to restore if you should screw it up!)
     bcdedit /create /d "Linux" /Application BOOTSECTOR
     #THIS WILL RETURN A LOOONG STRING OF CHARACTERS IN CURLY BRACES
     #IMPORTANT:  REPLACE "{ID}" WITH THIS STRING (INCLUDING THE CURLY BRACES):
     bcdedit /set {ID} device boot
     bcdedit /set {ID} PATH \antix.bin
     bcdedit /displayorder {ID} /addfirst  #THESE TWO WILL MAKE Antix THE FIRST AND DEFAULT ENTRY.
     bcdedit /default {ID}
     bcdedit /export C:\backupbcd  #BACK UP YOUR NEW ONE TOO!

6)  Now reboot and select “Linux” and (hopefully) boot up into your shiny new Antix Linux install!

7)  Re-install or update your kernel package and run “update-grub” – (I installed a PAE version so I could access my 8-GIG of RAM)  I found that the Antix installer did not seem to quite carry over all the kernel modules (my cd-rom disappeared, etc.) and this corrected everything.  I also backed up my “antix.bin” file somewhere on my Linux filesystem too!  (YMMV!!!)

Overall, I’m very pleased with this machine, all hardware seems to work well with Linux (Only thing I haven’t tested is the thumbprint reader).  Googling shows that it can be used in Linux.  The modem’s an Agere “losermodem” (winmodem).  I haven’t purchased a docking station yet).  The Intel Centrino Advanced-N 6200 wifi card needed:  “options iwlwifi bt_coex_active=0 swcrypto=1 11n_disable=8 led_mode=0” in a file I added to /etc/modprobe.d/ to work at proper speed with my 802.11G home wireless network, however.  The computer itself runs fast and fairly cool, and the fan is much quieter than any of the previous machines I’ve owned!  Here’s my /proc/cmdline:  root=/dev/sda6 quiet nosplash cgroup_disable=cpuset,cpu,cpuacct,blkio,memory ipv6.disable=1 libahci.ignore_sss=1 vga=0x365 ro
Links that I found very helpful along the way:

     https://www.iceflatline.com/2009/09/how-to-dual-boot-windows-7-and-linux-using-bcdedit/
     http://askubuntu.com/questions/88384/how-can-i-repair-grub-how-to-get-ubuntu-back-after-installing-windows
     http://www.troubleshooters.com/linux/grub/grub.htm
     http://ubuntuforums.org/showthread.php?t=1342241
     http://ubuntuforums.org/showthread.php?t=1163686
     https://wildstar84.wordpress.com/2015/09/17/copying-replicating-your-linux-install-to-a-different-hard-drive/
     https://www.boyans.net/DualBootWindows7andLinuxOrUnix.html

UPDATE:  The WIFI card, an “Intel Centrino Advanced-N 6200” is a bit wonky.  It seems to work find in Linux (no dropped connections, etc.), but there are a couple things I had to do due to the fact that I use a rickity old Linksys WRT54G (11G) router with Tomato firmware installed. Using iwconfig, the wireless card reports a pathetic “Bit Rate=1 Mb/s”. I tried everything I could think of or find to get it to work properly and have given up.  Every once in a while, it’ll come up showing a larger number (once showed 54)!  I’ve since determined that the card seems to be working properly (speedtest.net shows my internet at the full 6.4 Mb/s on it!), but it’s just REPORTING the wrong value (1).  My final settings are (/etc/modprobe.d/iwlwifi.conf):  “options iwlwifi bt_coex_active=0 swcrypto=1 11n_disable=1 uapsd_disable=1“.  This tells it to ignore any blue-tooth interference, turns on software encryption capability, disables 802.11n service, and turns off an obscure power-saving capability (primary power management is off by default).  I also blacklisted all bluetooth modules (btusb, btintel, btrtl, btbcm, and bluetooth), as I don’t use any bluetooth devices, though if you do, this should not be necessary.  I also had to go into /lib/firmware/ and do:

     sudo ln -s iwlwifi-6000-4.ucode iwlwifi-6000-5.ucode
     sudo ln -s iwlwifi-6000-4.ucode iwlwifi-6000-6.ucode

to eliminate a complaint in dmesg about the kernel not being able to autoload the firmware.  Not doing this did not prevent the card from working, but I didn’t like the error (warning?) and wanted to make sure the correct and best firmware available (6000-4) was being loaded. The 5 and 6 versions do not appear to exist yet!

One Comment

  1. Anonymous
    Posted April 11, 2016 at 2:22 pm | Permalink | Reply

    I am impressed!!!

Feel Free to Comment (Name/Email/Website optional):