Sunday, December 16, 2012

Linux Finding Hidden Networks (ESSID) (SSID)

It can be hard to find your wireless router if you have a hidden SSID.

You need to give your network manager a little help. Try this:

iwconfig wlan0 essid "myRouterName"

Then you can search for it:

Arch: wifi-menu
Debian: iwlist wlan0 | grep "myRouterName"

Setting Up Syslinux to Chainload other Linux Distros



I am starting this blog as a new install. 

You need to set up your partitions. We will be using a boot partition, a swap partition, an Arch Linux partition, and a Debian Linux partition. I am using a GPT partition table, so that converting to UEFI later on, will be easier.

#parted /dev/sda
mklabel gpt
mkpart 100MiB 200MiB
mkpart 200MiB 10GiB
mkpart 10GiB 60GiB
mkpart 60GiB 110GiB
set 1 boot_legacy on
quit

Make the first partition a fat partition. Turn swap on and enable EXT4 file system for Arch and Debian. 

mkfs.vfat -F32 /dev/sda1 
mkfs.ext4 /dev/sda3
mkfs.ext4 /dev/sda4
swapon /dev/sda2

After you have completed your installation you can set up you can set up your boot loader Syslinux. Ensure that your boot partition is not added to your fstab file.

After you have downloaded syslinux and installed it, we can set up the boot process.

#mkdir /mnt/boot
#mount /dev/sda1 /mnt/boot
#mkdir /mnt/boot/boot/syslinux
#syslinux -i /dev/sda1 -d /boot/syslinux

We need to copy the GPTMBR over to the boot sector. Syslinux installs a MBR by default.

#dd bs=440 count=1 conv=notrunc if=/usr/lib/syslinux/gptmbr.bin of=/dev/sda

There should only be ldlinux.ld file in /boot/syslinux. You can place syslinux in the base but I prefer the hierarchy structure. Simply use syslinux -i/dev/sda1.

Copy over the chain boot and menu files.

#cp /usr/lib/syslinux/chain.c32 /mnt/boot/boot/syslinux/
#cp /usr/lib/syslinux/menu.c32 /mnt/boot/boot/syslinux/

Now we need to make a syslinux.cfg file.

I suggest you copy over the partition uuids before creating it.


#lsblk /dev/sda -o NAME,PARTLABEL,PARTUUID > /mnt/boot/boot/syslinux/syslinux.cfg
NAME   PARTLABEL PARTUUID
sda              
├─sda1 boot      ccd52c34-e8af-4ee7-8c33-592ec83445db
├─sda2 swap      c8d1a535-d8c6-4499-81fa-a0ee58d67695
├─sda3 arch      0b0299aa-8d0f-4865-bfa8-ff43a74386f8
├─sda4 debian    f22cb873-9a1a-47c8-9bd8-d9f0c828e6b6


My syslinux.cfg looks like this. Ensure that if you use UUID that you use lsblk -0 PARTUUID not lsblk -o UUID.


DEFAULT menu.c32 
PROMPT 0

MENU TITLE Syslinux Boot
MENU AUTOBOOT arch
TIMEOUT 300
TOTALTIMEOUT 9000

LABEL arch
  MENU DEFAULT
  MENU LABEL Arch Linux
  SAY Booting to Arch Linux
  COM32 chain.c32
  APPEND guid=0b0299aa-8d0f-4865-bfa8-ff43a74386f8
  #APPEND label=arch /dev/sda3

LABEL debian
  MENU LABEL Debian Linux
  COM32 chain.c32
  APPEND guid=f22cb873-9a1a-47c8-9bd8-d9f0c828e6b6
  #APPEND label=debian

For each operating system you need a extlinux. Unmount the boot partition and set up extlinux.

#umount /dev/sda1

Install extlinux to the base of your system

#extlinux -i /dev/sda3 -d /boot/syslinux

Older extlinux require the path to be /boot/extlinux and require a /boot/extlinux.conf file. I prefer to standardize syslinux.

#vim /boot/syslinux/syslinux.cfg

default arch


label arch
  linux /boot/vmlinuz-linux
  initrd /boot/initramfs-linux.img
  append root=/dev/sda3 rw

You'll need to repeat this for your Debian distribution




Saturday, December 15, 2012

How to Create a USB stick to Flash your BIOS for a Linux PC


***WARNING: ATTEMPTING TO FLASH YOUR BIOS CAN PERMANENTLY DAMAGE YOUR PC***


Most vendors do not provide support for Linux, which can be especially difficult when you want to update your BIOS.

I will be providing two methods for upgrading you BIOS.

1. FreeDOS
2. Windows PE


The first option is for DOS utilities and the second is for Windows utilities. I recommend the first unless you are forced to use a Windows executable from your vendor

---------------------------------------------------

FREEDOS


1. Download the FreeDOS live disk.

2. Plug in your USB replace /dev/sdb with /dev/[your USB] (if you do not know where your USB stick is try the command lsblk). Prepare to set up a partition table. (Warning: this will erase everything on your USB stick.)

parted /dev/sdb

mklabel msdos

mkpart primary 0% 100%
set boot on


3. Add a file system:

mkfs.vfat -F32 /dev/sdb1

4. Now install Syslinux to your USB stick: (refer to your distro package manage for downloading the syslinux package):

syslinux -i /dev/sdb

5. Add a configuration file that will boot your FreeDos Image:

sudo mkdir /mnt/usb
sudo mount /dev/sdb1 /mnt/usb

sudo vim /mnt/usb/syslinux.cfg


DEFAULT FreeDOS

LABEL FreeDOS
 LINUX memdisk
 INITRD fdboot.img

6. Copy memdisk to your USB stick. (If you can not find the syslinux library try the command whereis syslinux.)

sudo cp /usr/lib/syslinux/memdisk /mnt/usb


7. Copy the FreeDOS image and your vendor executable image.

sudo cp ~/fdboot.img
sudo cp ~/myBIOSflash.exe /mnt/usb


8. Plug in your USB and boot up your machine. Syslinux should boot into FreeDOS. Type myBIOSflash.exe to upgrade your BIOS.

---------------------------------------------------

WINDOW PE (Windows Portable Edition)


If you've tried to flash your BIOS with FreeDOS and received "incompatible DOS file". This method is for you. Unfortunately, you will require a copy of Windows for this tutorial to work:

1. Download the Installation Kit and burn an ISO and install to Windows.

Download the Windows 7 Automation Installation Kit
Download the Windows Vista/XP/Server 2003 Automated Installation Kit

I have followed this Walkthrough from Microsoft, but have added necessary corrections.
Walkthrough: Create a Bootable Windows PE RAM Disk on UFD


2. Start the "Deployment Tools Command Prompt" from the start menu.

3. Create a Windows PE Image

copype.cmd x86 c:\winpe_x86

4. Mount the Image:

imagex /mountrw WinPE.wim 1 c:\winpe_x86\mount\

5. Add your BIOS flash files:

cp c:\acerBIOSflash.exe c:\winpe_x86\mount


6. Unmount the Image:

imagex /unmount /commit c:\winpe_x86\mount

7. This step [b]must[/b] be added (it is in the other walkthroughs). It will not boot otherwise.

xcopy c:\winpe_x86\winpe.wim c:\winpe_x86\iso\sources\boot.wim /y

8. To partition the disk you must leave the "Deployment Tools Command Prompt". If you stay in the "Deployment Tools Command Prompt" it will not create a proper bootable partition. Start a separate command prompt with administrator privileges. Replace disk 6 with your USB.:

diskpart
list disk
select disk 6
clean
create partition primary size=<size of device>
select partition 1
active
format fs=fat32 quick
exit

9. Copy to your USB. Change "F:\" to the location of your drive:

xcopy c:\winpe_x86\iso\*.* /s /e /f f:\

Once you boot, you get a command prompt in a Windows environment.

Now you can navigate to the location of flash utility and install.

I hope this tutorial helps anyone else. It took a while to compile various walkthroughs and Q&As.

Note:
1. You cannot add the flash utility directly to the ISO. It has to be mounted into the actual boot.wmi.

2. If the disk fails to boot ensure that the active flag (boot) is set in diskpart.

Sunday, December 4, 2011

Printing with CUPS

Install CUPS:
$sudo aptitude update && sudo aptitude install cups


Finding Printers and Printing to Specific Printers:
$ lpstat -p
printer HP_Deskjet_3050A_J611_series is idle.  enabled since Sun 04 Dec 2011 07:00:07 PM EST
Ready to print.
$ lp -d HP_Deskjet_3050A_J611_series lettercount2.py
request id is HP_Deskjet_3050A_J611_series-3 (1 file(s)

Setting your default printer (root sets default for all users):
$ lpoptions -d HP_Deskjet_3050A_J611_series
auth-info-required=none copies=1 device-uri=socket://192.168.1.100:9100 finishings=3 job-hold-until=no-hold job-priority=50 job-sheets=none,none marker-change-time=1323043293 marker-colors=none,none marker-levels=-1,-1 marker-names='black\ ink\ cartridge,tri-color\ ink\ cartridge' marker-types=ink,ink number-up=1 printer-commands=AutoConfigure,Clean,PrintSelfTestPage printer-info='HP Deskjet 3050A J611 series' printer-is-accepting-jobs=true printer-is-shared=false printer-location=office-wifi printer-make-and-model='HP Deskjet 3050a j611 Series hpijs, 3.11.10' printer-state=3 printer-state-change-time=1323043293 printer-state-reasons=none printer-type=10522636 printer-uri-supported=ipp://localhost:631/printers/HP_Deskjet_3050A_J611_series.
$ lp lettercount2.py
request id is HP_Deskjet_3050A_J611_series-4 (1 file(s))

Disable Root Login for your SSH Host

Edit your sshd config file:
sudo vi /etc/ssh/sshd_config


Disable root login and save:
# Authentication:
LoginGraceTime 120
PermitRootLogin yes   #change this to no
StrictModes yes


Restart your ssh server:
sudo /etc/init.d/ssh restart

Sunday, November 27, 2011

Debian Net Install - Setting WPA wireless from the command line.

WPA_SUPPLICANT is a pain in the ass.


I highly recommend the net install CD over the various other packaged versions of Debian; mainly because it gives you the freedom to customize your OS exactly how you want it.

I have ran into some problems with the pre-packaged Debian CDs. For example the Debian default Gnome CD#1 does not include a network manager such as Gnomes Network Manager or Wicd. This is extremely frustrating, without an internet connection your distro is limited to the existing packages you have on CD.

Make sure you download an "unofficial" NETINST CD from the Debian site. This ensures you have the restricted firmware, if necessary, rather than having to download it later from another computer. They are from the official Debian site, but the conviently package all the non-free firmware. Its nice to have a pure libre OS, but at the end of the day I am not going out to buy another $50 network adapter.

Unofficial CD Images (w/ Non-Free Firmware)

Start:
I assume you can follow the installation instructions. The NETINST CD is pretty simple to follow along with. Once you have installed your system, restart your computer and log in.

Non-Free Firmware Check:
First, check if you need any non-free firmware. Type the following:
ifconfig wlan0 up

 If nothing happens you do not need non-free firmware. If you see "SIOCIFFLAGS: Operation not permitted", then you will need non-free firmware.

Install Firmware:
List all your hardware, you can grep for keywords such as wireless or wifi to help narrow it down.
sudo lspci 

Insert your Debian NETINST CD. Update aptitude and search for the various firmware available. If you see your vendor, install it:
sudo aptitude update
sudo aptitude search firmware
sudo aptitude install firmware-ralink

Confirm that the firmware installed correctly. ifconfig should return without an error message
ifconfig wlan0 up

Set-up aWPA Wireless Connection:
Download the necessary tools and install them from the NETINST CD.
aptitude install wpasupplicant wirelesstools

After you will need to set your essid if your network is hidden. (Otherwise you can skip this step)
sudo iwconfig wlan0 essid myNetworkName

WPA requires a special generated key based upon your essid (Network Name) and your network password.
sudo wpa_passphrase myNetworkName myNetworkPassword | sudo tee /etc/wpa_supplicant.conf

Start wpa_supplicant in the background
sudo wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf &

Ensure that a DHCP reolv.conf file exists:
sudo touch /etc/resolv.conf

Set-up your connection for DHCP
dhclient wlan0

Test to ensure that you have a network connection.
ping google.com

Customizing your System:
Enter vi and edit /etc/apt/sources.list and ensure that all online repositories are no longer commented out (remove the #). Then you can start customizing your new net install, exactly how you want.

All the Debian repositories you could ever want and WPA_SUPPLICANT is no longer a pain in your ass.

Sunday, August 7, 2011

Speeding up Apt

Remember: apptitude does not have super cow powers.
This is a small post about speeding up Aptitude. First you need to download and install apt-spy. It is a utility that tests the bandwidths of the various Debian mirrors an appropriately selects the fastest mirror. Surprisingly, they may not be the closest mirror.

sudo apt-spy install
sudo apt-spy update
sudo apt-spy -d wheezy -s ca 

The flag -d sets your current version such as wheezy, squeeze, etc and -s sets your country (ca=Canada). If you wish to select an entire are you may also go with the -a flag such as -a North America.

You should go into /etc/apt/sources.list and comment out your current mirrors as it will be given priority of apt-spy configuration. If you wish to see apt-spy's selected mirror go to /etc/apt/sources.list.d/apt-spy.list


# sources.list generated by apt-spy v3.1
#
# Generated using:
#
# apt-spy \
# -d wheezy \
# -s ca
#
deb http://debian.yorku.ca/debian/ wheezy main #contrib non-free
deb-src http://debian.yorku.ca/debian/ wheezy main #contrib non-free
#deb http://security.debian.org/ stable/updates main