Tuesday, February 12, 2008

Copy One Hard Disk to Another with Ubuntu 6.06 LTS

  1. With the machine off plug your target hard drive into a second channel on your computer.
  2. Boot the machine, when you see the grub start menu hit ESC
  3. Choose "Recovery Mode"
  4. When it prompts, enter your root password
  5. If you have IDE hard drives your drives will be /dev/hda for the source drive and /dev/hdb for the target. If they are SATA then they will be /dev/sda and /dev/sdb
  6. Type fdisk /dev/sda
  7. Type "p" to print a list of the partitions. Write these down, trust me it will make things easier in the future.
  8. quit out of fdisk with a CTRL+C
  9. Start FDISK again with /dev/sdb
  10. Press "n" to start a new patition segment
  11. Fill in the parameters you wrote down
  12. Try to duplicate the partition tables the best you can, here's the time to make the partition layout larger if you wish.
  13. Once you are done, type "w" to write the partition info to the disk
  14. Now you can copy the data over to the target disk
  15. mkdir /new in the root of the source disk
  16. mount /dev/sdb1 /new
  17. I have var on a separate partition on my system so I'm going to exclude it for this step and handle it later. However we still need to create a var mount point in what will be /
  18. mkdir /new/var
  19. mkdir /new/var/run
  20. mkdir /new/var/lock
  21. Now we do the copy:
  22. cd into /
tar --exclude var --exclude new -cvf - . | (cd /new; tar xf -)
  1. You will get error messages saying that the size has changed during copying, this is normal.
  2. Once it's done copying, we will do the same for the var partition.
  3. umount /new
  4. mount /dev/sdb3 /new
  5. cd into /var
tar -cvf - . | (cd /new; tar xf -)
  1. That copy should be pretty quick, we are done with the copy process.
  2. umount /new
  3. poweroff the system
  4. Next we need to reinstall grub on the new hard drive
  5. Remove the source disk from the system
  6. Power on the system, insert the ubuntu 6.06 installation CD and boot from it
  7. Select the "Rescue a broken system" option.
  8. This will look like it's installing the system again, just select all the appropriate options, enough to get you to the recovery screen.
  9. At one point it will ask which partition you want to be your root file system, 99% of the time this is part1, select it.
  10. It will then ask you what you want to do, select "re-install grub boot loader"
  11. It will give big long thing to read asking you where do you want to install the boot loader; we want it on /dev/sda, so we type that in and hit enter.
  12. It should install the boot loader, reboot the system and take the installer disc out of the drive.
  13. Done, you should have a fully working system on a new drive.

Wednesday, November 14, 2007

Mounting and Sharing CD/DVD ISO Images with Ubuntu and Samba

This is a WIP, draft quality now:

If you plan on having more then 8 Loop devices (loop0 - loop7) you need to set an option in "/etc/modprobe.d/options" called "option loop max_loop=255", or whatever number you need, then reboot the system.

  1. Copy the CD/DVD Images to a folder on your Ubuntu system hard disk
  2. Mount the image with the following command:
    • Syntax: mount -t iso9660 -o loop /path/to/image.iso /path/to/mountpoint
    • Real example: mount -t iso9660 -o loop /opt/CDImages/Ubuntu-710.iso /mnt
  3. Edit the samba config file:
    • vi /etc/samba/smb.conf
  4. Add the following lines:
[Sharename]
comment = Some descriptive comment or serial key
path = /mnt
valid users = testuser
available = yes
browseable = yes
public = yes
writeable = no

  1. Now add a user that we will use for authentication
    • useradd testuser
    • usermod -s /bin/false testuser
  2. Make sure you do NOT set a UNIX password for this account, we don't want people logging into the Linux box
  3. DO set a password for samba
    • smbpasswd -a testuser
  4. restart the samba server
    • /etc/init.d/samba restart
Now in your windows machine open windows explorer or my computer. In the address bar type \\servername OR \\svr.ip.add.res

NOTE this has change fro 10.04.1:

you need to modify your "/boot/grub/grub.cfg" and modify your menu entries to look like the follwing, note the "max_loop=128" part of the kernel line:

menuentry 'Ubuntu, with Linux 2.6.32-30-generic-pae' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
insmod ext2
set root='(hd0,1)'
search --no-floppy --fs-uuid --set 30c0ecfe-1708-4bec-b545-127d23466906
linux /vmlinuz-2.6.32-30-generic-pae root=/dev/mapper/Hostname-root ro quiet max_loop=128
initrd /initrd.img-2.6.32-30-generic-pae
}

First Gen Zune Firmware Update

I don't know anyone who has covered this topic on how to update your zune to the latest firmware. It's very simple, go to zune.net and get the new software front end. Once you have installed that over your old front end, plug in your first get Zune. It will automatically detect that you need to update your firmware. Once you tell it to begin, the process takes approx 8-10 minutes. That's it!

Friday, November 9, 2007

Compiling a Custom Kernel for Ubuntu

  1. Install necessary packages:
    1. apt-get install kernel-package libncurses5-dev fakeroot wget bzip2
  1. Download the kernel sources from www.kernel.org
  2. Extract them
  3. ln -s linux-kernel-version linux
  4. change directory into "linux"
  5. Copy the current kernel's config:
    1. cp /boot/config-`uname -r` ./.config
  6. Start the GUI kernel configuration
    1. make menuconfig
  7. Save the config
  8. Start the compile
    1. make-kpkg clean
    2. fakeroot make-kpkg --initrd --append-to-version=-custom kernel_image kernel_headers
  9. After it's done compiling, which may take 30 minutes or much more you will have to .deb packages in the /usr/src directory, install them
    1. dpkg -i kernel-image-2.6.23-custom_10.00.Custom_i386.deb
    2. dpkg -i kernel-headers-2.6.23-custom_10.00.Custom_i386.deb
  10. verify that the entries are in grub
    1. vi /boot/grub/menu.lst
  11. reboot

Friday, November 2, 2007

Monday, October 29, 2007

Sorting IP Addresses with Linux/Unix "sort"

Recently I was doing a site survey of all active IPs on our network. I used nmap for this function and dumped all responding IP addresses to a text file. I don't have to worry about PC's not responding to the ping due to a personal firewall since our PC's here do not have one turned on; they are all protected by our corporate firewall. To find all responding IP's I ran the following command line for nmap:
/usr/bin/nmap -n -sP xxx.xxx.xxx.xxx-xxx xxx.xxx.xxx.xxx-xxx >> /home/myUserName/IPdb/site1IPsUp.txt
I did this for several times a day, several days a week for a couple weeks to make sure I had gotten the most complete picture possible, then I tried to sort them...

IP addresses are a strange animal, they aren't really "numbers" per se due to multiple decimal points and they aren't really words, they are a sort of hybrid. Because of this using sort without so pretty specific command line arguments won't give you what you want, which is numerically proper sorting.

Also, nmap outputs a bunch of junk text which I'm not interested in at all, I want this removed and just want the IP addresses themselves. Since I've done this survey over and over again I'm going to have dozens of the same IP address show up in the file, I only want to see it listed once. After all is said and done this is the command line I finished with to give me the output I was looking for:
cat site1IPsUp.txt | grep -v Nmap | grep -v Starting | awk '{ print $2 }' | sort -u -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4

From there I can do with it what I like. ;)

Wednesday, October 3, 2007

Enabling Windows 2000/XP "File and Printer Sharing" at the Command Line

I've searched high and low and there does not seem to be any way to enable Windows File and Printer Sharing without having someone actually perform the function of clicking the stupid check box. Yes, I've gone through the registry and even did the ol' regmon trick to see what windows was modifying, nothing was obvious. Recently this problem has cropped up again causing me to renew my search for an answer, and an answer I found!

The key here is a little program called "snetcfg" which allows you to add or remove services to the windows networking system. I'm assuming snetcfg stands for "service net configurator" or something like that. Now, this program in itself can't actually check that little box that we've been discussing rather we are going to leverage some of windows' default behaviors against it.

When windows installs a service it enables it by default, what we will be accomplishing with snetcfg is that we will be uninstalling the File and Printer Sharing service and then re-installing it. Once Windows has re-installed the service it enables it by default.

Here's how we do it:
  1. Grab snetcfg.zip
  2. The command line to uninstall Win2K File and Printer Sharing Service is:
    1. snetcfg.exe -v -u MS_Server
  3. The command line to re-install Win2K File and Printer Sharing Service is:
    1. snetcfg.exe -l %windir%\Inf\NETSERV.INF -c s -i MS_Server
I've found Windows XP to be similar, you can just put these lines into a batch file and push it out via a domain login script.