西西河

主题:【原创】Install and boot linux on a USB external hard drive -- whoknows

共:💬4 🌺7 新:
全看树展主题 · 分页首页 上页
/ 1
下页 末页
家园 【原创】Install and boot linux on a USB external hard drive

Ok, ok, this is not a totally new stuff, we all know it. Here is only a record to show how I did it.

The story happened when we were doing unpacking and arranging our new apartment. A old, very old laptop was digged out from one of the boxes. The configuration is as following:

CPU: P-III 1GHz

Memory: 256M

HD: None

DVD-ROM

Floppy Drive

No support for USB boot (that's something different, right;) )

Fortunately I have a spare 80G hard disk and a hard drive enclosure. So I decided to make this old guy something useful - a Linux server for my car pc system develpment such that I do not have to do development on and mess up the target machine.

The Linux distributionn I chose is Ubuntu 6.06 LTS, which is downloanded from www.ubuntu.com, for its very good reputations and my pervious experiences with Ubuntu. Installation is very simple. Just follow the on screen instructions is good.

After installation, a boot cd will be created to boot the system since this old guy does not support boot via USB. After search using www.google.com, I got some very good references, which will be listed in the reference part below. Here is what is needed and how to make the boot cd.

The only necessary software package that one may have to install is syslinux 3.11. I use another computer that have the exactly same Ubuntu system installed to make/get another two important pieces: the linux kernel image and the ramdisk image. Following is a step-list of how to do to reach the point the old guy is booted:

(1) install the Ubuntu to the external hard drive through USB. In my case is /dev/sda1

(2) install the syslinux package. It can be installed via the Synaptic Package Manager automatically or downloaded from the syslinux.zytor.com.

(3) make the initial ramdisk you will need. The initial ramdisk wil at least include the USB drivers that will allow you to mount your USB external hard drive as your root file system after your kernel is started.

Using my Ubuntu, make such an initial ramdisk is just a piece of cake:

(a) edit the /etc/mkinitramfs/modules to add following lines:

ehci-hcd

ohci-hcd

uhci-hcd

usb-storage

scsi-mod

sd_mod

(b) make the new ramdisk image by running following command

mkinitramfs -o /boot/initrd_usb.img /lib/modules/<linux version>

For me, the command is like: mkinitramfs -o /boot/initrd_usb.img /lib/modules/2.6.15-23-386

For other Linux distributions, there are other means of create the initial ramdisk, yeah, even manually. I will discuss this in another post, maybe.

(4) Make the iso image for the boot cd

(a) create a directory to hold all the files that will be used to create the iso image, under my home directory.

$ mkdir bootcd

(b) copy the created initial ramdisk image to bootcd

$ cp /boot/initrd_usb.img bootcd/

(c) copy the desired linux kernel image to bootcd. For me, the command looks like

$ cp /boot/vmlinuz-2.6.15-23-386 /bootcd/linux

(d) copy the isolinux.bin of syslinux to bootcd directory. For me, the command looks like

$ cp /usr/lib/syslinux/isolinux.bin bootcd/

(e) create the isolinux.cfg file in the bootcd directory, which is the configuration fiile for the isolinux bootloader. Put following lines in the isolinux.cfg file:

DEFAULT linux initrd=<initial ramdisk image name> ro root=<your root device>

where <initial ramdisk image> is the name of the initial ramdisk image you want use. In my case, it is initrd_usg.img. The <your root device> is the device that you have installed your Linux. For me, it is /dev/sda1.

Thus my isolinux.cfg file looks like:

DEFAULT linux initrd=initrd_usb.img ro root=/dev/sda1

(f) create an iso image using following command

$ mkisofs -o bootcd.iso -b ioslinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -J -hide-rr-removed -R bootcd/

(g) burn the bood cd using the image

(5) Test it. And the external disk can be used. The boot cd and the external hard drive can be used anywhere as long as the boot from cd is supported and USB port presents.

Notes: The approach here can be used not only for the Ubuntu system but also any other linux distributions, as long as you can create the right initial ramdisk image and get the desired kernel image.

Enjoy:)

References:

[1] http://ubuntuforums.org/archive/index.php/t-19428.html

[2] http://ubuntuforums.org/showthread.php?t=80811

[3] http://www.freeos.com/guides/lsst/

[4] http://www-128.ibm.com/developerworks/linux/library/l-initrd.html?ca=dgr-lnxw01LinuxInitialRam

[5] http://librenix.com/?page=USB%20Drive

[6] http://yolinux.com/TUTORIALS/LinuxTutorialRecoveryAndBootDisk.html

[7] http://www.geocities.com/potato.geo/bootlinuxcd.html

and many many others, and great thanks to them.

元宝推荐:铁手,
家园 逮住牛人问个问题:如何修改/boot/initrd_usb.img中的内容啊

我要修改里面的/linuxrc,用了网上多人的经验,都没成功,无论是在ubuntu还是gentoo上,你有没有好主意?

参见链接出处

家园 一点建议

首先,我不是什么牛人了。其次,不好意思,最近忙着搬家,不是很经常上网,见谅。

在ubuntu上有一个命令mkinitramfs (ubuntu 6.06) / mkinitrd(?) (older version of ubuntu)。 这个命令应该是一个script,你可以参考一下。但是基本上不太可能直接修改initrd_usb.img里面的内容;而是要根据你自己的设置重新生成这个image。

至于你的具体问题,我觉得举个例子会好说清楚一些:

首先假定有一个目录叫ramdisk/,里面是你要放的东西。当然,放什么东西取决于你做initrd的目的了。然后哪,有一个script,就叫做makeinitrd.sh吧:

============ script start =================

#!/bin/sh

dd if=/dev/zero of=rd-ext2.bin bs=1k count=2048

mke2fs -F -m0 rd-ext2.bin

mount -t ext2 rd-ext2.bin /mnt -o loop

tar -C ramdisk --exclude .svn -cf - . | tar -C /mnt -xf -

umount /mnt

============= script end ====================

The 2nd line is to create a empty 2M file filled with zeros.

The 3rd line is to create an ext2 filesystem on that empty 2M file we just created.

Then, at the 4th line, we mount this file using /dev/loop to a local mounting point as an ext2 filesystem.

The 5th line is to put what we have prepared in the ramdisk folder to the mounted file system.

Then at last, the ramdisk image is unmounted at 6th line.

上面的解释是从我的笔记里面copy出来的,比较懒,就不翻译成中文了。希望对你的问题有帮助

家园 内存映像是可以用mount挂的,需要一个module
全看树展主题 · 分页首页 上页
/ 1
下页 末页


有趣有益,互惠互利;开阔视野,博采众长。
虚拟的网络,真实的人。天南地北客,相逢皆朋友

Copyright © cchere 西西河