[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Installing Debian on USB sticks.



On 02/09/2011 04:29 AM, James Allsopp wrote:
Hi,
Recently I placed the netinst i386 debian installer on an old USB stick
using:
zcat boot.img.gz>  /dev/sdc

and I've installed one machine using it. However yesterday I was trying
to install debian itself on a USB stick and the installer found it could
connect to a couple of the mirrors but that it couldn't find a correct
version. Could this be due to the transition from lenny to squeeze?

I'm also wondering if this is the correct procedure for installing a
working debian installation on USB stick. A problem I ran into yesterday
was that I installed grub onto the MBR and overwrote the MBR on my
laptop's HD. Fixed it now but would like to know how to get around that
and install it to the USB stick.

My eventual goal is to have a USB debian install that my gf can use on
computers (i386 or newer architecture) at work, as they don't give out
install privileges.

Thanks for any advice.
Jim

The easiest / safest / most fool proof way is to perform the install on a machine with no harddrive, I don't do this because I have a bunch of install images ready to be pushed onto any drive or device

I take the image (from a non booted single partition system) with something like this
###############################################################################

 img_dir=/mnt/smb_docs
 src_drv=/dev/sdX
 src_part_no=n

# identify partition label & UUID
 ls -la /dev/disk/by-uuid/
 e2label ${src_drv}${src_part_no}
# set image file name in the form of
# description, architecture, drive, boot loader, date, partition label, uuid
img_file_name=debian_squeeze_dsktp_686_sda1_GRUB2_11_02_03_DebianSqueezeX86_80000000-4000-4000-4000-120000000000

# Mount source install
 echo ${src_drv}${src_part_no}
 echo ${img_dir}/img/${img_file_name}
 umount ${src_drv}${src_part_no}
 mkdir -p ${img_dir}/img/
 mkdir -p /mnt/src
 mount ${src_drv}${src_part_no} /mnt/src
 cd /mnt
# delete swap file (not usually installed on my images anyway)
# & some other host specific files
 rm -f /mnt/src/var/swap
 rm -f /mnt/src/etc/udev/rules.d/70-persistent-net.rules
 rm -f /mnt/src/etc/udev/rules.d/70-persistent-cd.rules
 rm -f /mnt/src/var/lib/ntp/ntp.drift

# Take the image
 ls ${img_dir}/img/${img_file_name}.tar.gz
 nice -n 19 tar czvf ${img_dir}/img/${img_file_name}.tar.gz ./src
 ls -la ${img_dir}/img/${img_file_name}.tar.gz

# I back up the boot sector & partition table for safety
dd if=${src_drv} of=${img_dir}/img/mbr/mbr_${img_file_name}_446.ddimg bs=446 count=1 dd if=${src_drv} of=${img_dir}/img/mbr/mbr_${img_file_name}_512.ddimg bs=512 count=1

# unmount & spin down drive (particularly if you're hot swapping)
 umount ${src_drv}*
 umount ${src_drv}*
 hdparm -y ${src_drv}
 hdparm -Y ${src_drv}
 hdparm -C ${src_drv}

###############################################################################
I install the image like this
###############################################################################


img_dir=/mnt/smb_docs
img_file_name=debian_squeeze_dsktp_686_sda1_GRUB2_11_02_03_DebianSqueezeX86_80000000-4000-4000-4000-120000000000

 dst_drv=/dev/sdX
 part_no=n

 # for flash drives ideally leave the manufacturer partition table
 # it's probably aligned correctly so just change the ID to 83
 # & set the bootable flag
fdisk -cu ${dst_drv}

# format the partition (on Flash you probably want ext2 instead)
mkfs.ext4 -v ${dst_drv}${part_no} -L DebianSqueezeX86
tune2fs ${dst_drv}${part_no} -U 80000000-4000-4000-4000-120000000000

# mount destination as ./src as that's the path in my .tar files
 mkdir -p /mnt/src
 mount ${dst_drv}${part_no} /mnt/src
 cd /mnt
 ls -la ${img_dir}/img/${img_file_name}.tar.gz
 nice -n 19 tar xzvf ${img_dir}/img/${img_file_name}.tar.gz
 rm -f /mnt/src/var/swap
 rm -f /mnt/src/etc/udev/rules.d/70-persistent-net.rules
 rm -f /mnt/src/etc/udev/rules.d/70-persistent-cd.rules
 rm -f /mnt/src/var/lib/ntp/ntp.drift
# on a portable system this keeps network connections @ eth0 & wlan0
 chmod -c 644 /lib/udev/write_*

# fix the /boot/grub/device.map and fstab on new drive
# so they point to the new drive
 ls -la /dev/disk/by-uuid/
 ls -la /dev/disk/by-id/
 cat /mnt/src/boot/grub/device.map
 vim /mnt/src/boot/grub/device.map
 vim /mnt/src/etc/fstab

# install grub, on first boot you may have to manually enter
# correct uuid then as root run update-grub2

 grub-install --root-directory=/mnt/src ${dst_drv}

 umount ${dst_drv}*
 umount ${dst_drv}*
 hdparm -y ${dst_drv}
 hdparm -Y ${dst_drv}
 hdparm -C ${dst_drv}

Your done.
This way I have a fully functioning install with all my preferences up and running in minutes, it's great for an experimental upgrade to sid or to push a web-server install onto a laptop while I play musical hardware.


Reply to: