This howto will explain how to install the base Debian GNU/Linux system onto a USB flash thumb drive.
So open your favorite root login shell and follow these 12 simple steps!
$QUOTE$Load any/all needed kernel modules (this is a partial list, actual list depends on your configuration):
root@hostname# modprobe ehci_hcd root@hostname# modprobe ohci_hcd root@hostname# modprobe usbhid root@hostname# modprobe usb_storage
Install the necessary applications on the build system:
root@hostname# apt-get install parted debootstrap
The first thing we need to do is identify what our system identifies our media as. To do this, simply stick the usb thumbdrive into one of the usb ports and then run the tail command:
root@hostname# tail -n 14 /var/log/messages
Jan 1 12:00:00 hostname kernel: ohci_hcd 0000:00:02.1: wakeup
Jan 1 12:00:00 hostname kernel: usb 2-3: new full speed USB device using ohci_hcd
and address 2
Jan 1 12:00:00 hostname kernel: Initializing USB Mass Storage driver...
Jan 1 12:00:00 hostname kernel: scsi2 : SCSI emulation for USB Mass Storage devices
Jan 1 12:00:00 hostname kernel: usbcore: registered new driver usb-storage
Jan 1 12:00:00 hostname kernel: USB Mass Storage support registered.
Jan 1 12:00:00 hostname kernel: Vendor: Model: TS256MJFLASHA Rev: 1.00
Jan 1 12:00:00 hostname kernel: Type: Direct-Access ANSI SCSI
revision: 02
Jan 1 12:00:00 hostname kernel: SCSI device sda: 506400 512-byte hdwr sectors (259 MB)
Jan 1 12:00:00 hostname kernel: sda: Write Protect is off
Jan 1 12:00:00 hostname kernel: SCSI device sda: 506400 512-byte hdwr sectors (259 MB)
Jan 1 12:00:00 hostname kernel: sda: Write Protect is off
Jan 1 12:00:00 hostname kernel: sda: sda1 sda2
Jan 1 12:00:00 hostname kernel: sd 2:0:0:0: Attached scsi removable disk sda
root@hostname#
As we can see from this output, the device was detected and assigned to /dev/sda.
The first thing we want to do is remove any old data from the drive. To do this, we'll use the shred tool which overwrites the media with progressive cycles of random and nonrandom data to make recovery of any old data near impossible. As a final step, shred will overwrite everything with zeros.
root@hostname# shred -n 1 -z -v /dev/sda shred: /dev/sda: pass 1/2 (random)... shred: /dev/sda: pass 1/2 (random)...1.1MiB/248MiB 0% shred: /dev/sda: pass 1/2 (random)...2.4MiB/248MiB 0% shred: /dev/sda: pass 1/2 (random)...3.7MiB/248MiB 1% <SNIP> shred: /dev/sda: pass 2/2 (000000)...246MiB/248MiB 99% shred: /dev/sda: pass 2/2 (000000)...248MiB/248MiB 100% root@hostname#
For this example, shred wil run in verbose mode, with one overwrite pass of random data (-n 1) and then overwrite with zeros (-z).
Next we need to partition the media. For a flash media installation, we will have a single partition and no swap.
For simple formating operations like this, I prefer to use GNU Parted because its a simple command.
root@hostname# parted /dev/sda "mklabel msdos mkpartfs primary ext2 0.0 -0
set 1 boot on"
Information: Don't forget to update /etc/fstab, if necessary.
root@hostname#
Now that we have our partition, we need to create a temporary mount point and mount our partition to it so we can perform our install.
root@hostname# mkdir /mnt/buildroot root@hostname# mount -t ext2 /dev/sda1 /mnt/buildroot root@hostname#
Some BIOS will have difficulting seeing larger partition sizes on flash media, but the kernel does not have this limitation. So we can get around the problem by using a small /boot partition.
root@hostname# parted /dev/sda "mklabel msdos mkpartfs primary ext2 0.0 21.0
mkpartfs primary ext2 21.0 -0 set 1 boot on"
Then mount like so:
mkdir /mnt/buildroot mount /dev/sda2 /mnt/buildroot mkdir /mnt/buildroot/boot mount /dev/sda1 /mnt/buildroot/boot
Now that we have our partition mounted, we can install the base Debian system onto it.
root@hostname# debootstrap --arch i386 sid /mnt/buildroot I: Retrieving Release I: Retrieving Packages I: Validating Packages I: Resolving dependencies of required packages... I: Resolving dependencies of base packages... I: Found additional base dependencies: libdb4.2 libgnutls12 libreadline5 libsigc++-2.0-0c2a openbsd-inetd readline-common I: Checking component main on http://ftp.debian.org/debian... I: Retrieving adduser <SNIP> I: Configuring gnupg... I: Configuring sysklogd... I: Configuring klogd... I: Configuring netbase... I: Configuring openbsd-inetd... I: Base system installed successfully. root@hostname#
root@hostname# chroot /mnt/buildroot /bin/su - hostname:~#
Use vi to create the /etc/fstab file and add these contents to it:
#/etc/fstab: static file system information. # /dev/sda1 / ext2 defaults,errors=remount-ro,noatime 0 1 proc /proc proc defaults 0 0 tmpfs /etc/network/run tmpfs defaults,noatime 0 0 tmpfs /tmp tmpfs defaults,noatime 0 0 tmpfs /var/lock tmpfs defaults,noatime 0 0 tmpfs /var/log tmpfs defaults,noatime 0 0 tmpfs /var/run tmpfs defaults,noatime 0 0 tmpfs /var/tmp tmpfs defaults,noatime 0 0
#/etc/fstab: static file system information. # /dev/sda2 / ext2 defaults,errors=remount-ro,noatime 0 1 /dev/sda1 /boot ext2 defaults,noatime 0 1 proc /proc proc defaults 0 0 tmpfs /etc/network/run tmpfs defaults,noatime 0 0 tmpfs /tmp tmpfs defaults,noatime 0 0 tmpfs /var/lock tmpfs defaults,noatime 0 0 tmpfs /var/log tmpfs defaults,noatime 0 0 tmpfs /var/run tmpfs defaults,noatime 0 0 tmpfs /var/tmp tmpfs defaults,noatime 0 0
Then mount all the filesystems:
hostname:~# mount -a hostname:~#Note: There maybe errors here that /dev/sda1 and /dev/sda2 can't be found. It is safe to ignore them and continue. Set Hostname
Set the hostname by editing /etc/hostname, and then add the base configuration to /etc/hosts:
127.0.0.1 localhost.localdoman localhost <hostname>FILE: /etc/apt/sources.list
Next we have to add some sources to the Apt configuration.
deb http://ftp.debian.org/debian sid main non-free contrib deb-src http://ftp.debian.org/debian sid main non-free contrib deb http://mirrors.kernel.org/debian/ sid main non-free contrib deb-src http://mirrors.kernel.org/debian/ sid main non-free contrib
Start by updating the apt databases.
root@hostname# apt-get update Get:1 http://mirrors.kernel.org sid Release.gpg [189B] Get:2 http://mirrors.kernel.org sid Release [38.3kB] Get:3 http://mirrors.kernel.org sid/main Packages [4079kB] Get:4 http://ftp.debian.org sid Release.gpg [189B] Hit http://ftp.debian.org sid Release Hit http://ftp.debian.org sid/main Packages Get:5 http://ftp.debian.org sid/non-free Packages [74.6kB] Get:6 http://ftp.debian.org sid/contrib Packages [57.1kB] Get:7 http://ftp.debian.org sid/main Sources [1559kB] Get:8 http://ftp.debian.org sid/non-free Sources [30.3kB] Get:9 http://ftp.debian.org sid/contrib Sources [24.3kB] Get:10 http://mirrors.kernel.org sid/non-free Packages [74.6kB] Get:11 http://mirrors.kernel.org sid/contrib Packages [57.1kB] Get:12 http://mirrors.kernel.org sid/main Sources [1559kB] Get:13 http://mirrors.kernel.org sid/non-free Sources [30.3kB] Get:14 http://mirrors.kernel.org sid/contrib Sources [24.3kB] Fetched 7608kB in 48s (158kB/s) Reading package lists... Done root@hostname#
The first thing we're going to install is localepurge to help keep the installation size down by removing all documentation in languages other than those you speak. When you install localepurge, it will ask you what locales you would like to keep. As an american english speaker, I select the following locales: en, en_us, and en_us.UTF8. Be careful not to remove too many locales or you may lose some functionality.
root@hostname$ apt-get install localepurge Reading package lists... Done Building dependency tree... Done Suggested packages: debfoster deborphan The following NEW packages will be installed localepurge 0 upgraded, 1 newly installed, 0 to remove and 30 not upgraded. Need to get 35.2kB of archives. After unpacking 87.0kB of additional disk space will be used. Get: 1 http://ftp.debian.org sid/main localepurge 0.4.1 [35.2kB] Fetched 35.2kB in 9s (3780B/s) Preconfiguring packages ... Configuring localepurge ----------------------- localepurge will remove all locale files from your system but the ones for the language codes you select now. Usually two character locales like "de" or "pt" rather than "de_DE" or "pt_BR" contain the major portion of localizations. So please select both for best support of your national language settings. The entries from /etc/locale.gen will be preselected if no prior configuration has been successfully completed. 1. aa 92. en_SG 183. ja_JP.UTF-8 274. se 2. aa_DJ 93. en_US 184. ka 275. se_NO 3. aa_ER 94. en_US.UTF-8 185. ka_GE 276. si 4. aa_ER@saaho 95. en_ZA 186. kk 277. si_LK 5. aa_ET 96. en_ZW 187. kk_KZ 278. sk <SNIP> 77. en 168. hy_AM 259. pt_BR 350. zh_CN 78. en_AU 169. ia 260. pt_PT 351. zh_CN.GB18030 79. en@boldquot 170. id 261. pt_PT@euro 352. zh_CN.GB2312 80. en_BW 171. id_ID 262. rm 353. zh_CN.GBK 81. en_CA 172. is 263. ro 354. zh_CN.UTF-8 82. en_DK 173. is_IS 264. ro_RO 355. zh_HK 83. en_GB 174. it 265. ru 356. zh_HK.UTF-8 84. en_GB.UTF-8 175. it_CH 266. ru_RU 357. zh_SG 85. en_HK 176. it_IT 267. ru_RU.KOI8-R 358. zh_TW 86. en_IE 177. it_IT@euro 268. ru_RU.UTF-8 359. zh_TW.Big5 87. en_IE@euro 178. iw 269. ru_UA 360. zh_TW.EUC-TW 88. en_IN 179. iw_IL 270. rw 361. zh_TW.UTF-8 89. en_NZ 180. ja 271. rw_RW 362. zu 90. en_PH 181. ja_JP 272. sa 363. zu_ZA 91. en@quot 182. ja_JP.EUC-JP 273. sa_IN (Enter the items you want to select, separated by spaces.) Selecting locale files 77 93 94 localepurge failed to preconfigure, with exit status 10 Selecting previously deselected package localepurge. (Reading database ... 79926 files and directories currently installed.) Unpacking localepurge (from .../localepurge_0.4.1_all.deb) ... Setting up localepurge (0.4.1) ... Configuring localepurge ----------------------- Based on the same locale information you chose above, localepurge can also delete superfluous localized man pages. Also delete localized man pages? yes If you are content with the selection of locales you chose to keep and don't want to care about whether to delete or keep newly found locales, just deselect this option to automatically remove new locales you probably wouldn't care about anyway. If you select this option, you will be given the opportunity to decide whether to keep or delete newly introduced locales. Inform about new locales? yes root@hostname#
After this, everytime you run apt-get to install or upgrade, it will post-install run localepurge to remove all unwanted documentation.
For now, we have to force it to run for the first time.
hostname:~# localepurge localepurge: Disk space freed in /usr/share/locale: 25396K hostname:~#
As space is limited, get in the habit of removing apt's cached files frequently.
root@hostname# apt-get clean
Before we can install the kernel, we need to set its configuration. Edit /etc/kernel-img.conf so that it looks like this:
do_symlinks = yes relative_links = yes do_bootloader = no do_bootfloppy = no do_initrd = yes ## <--- Verify this line link_in_boot = yes postinst_hook = /sbin/update-grub postrm_hook = /sbin/update-grubNext we install the kernel.
hostname:~# apt-get install linux-image-2.6.16-1-686 Reading package lists... Done Building dependency tree... Done Suggested packages: linux-doc-2.6.16 linux-source-2.6.16 grub lilo Recommended packages: libc6-i686 The following NEW packages will be installed: linux-image-2.6.16-1-686 0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded. 5 not fully installed or removed. Need to get 0B/15.7MB of archives. After unpacking 46.8MB of additional disk space will be used. Preconfiguring packages ... (Reading database ... 7204 files and directories currently installed.) Unpacking linux-image-2.6.16-1-686 (from .../linux-image-2.6.16-1-686_2.6.16-5_i386.deb) ... Done. Setting up busybox (1.01-4) ... Setting up libklibc (1.3.1-1) ... Setting up klibc-utils (1.3.1-1) ... Setting up udev (0.088-2) ... A chroot environment has been detected, udev not started. Setting up initramfs-tools (0.59b) ... wc: /proc/swaps: No such file or directory tail: cannot open `/proc/swaps' for reading: No such file or directory Setting up linux-image-2.6.16-1-686 (2.6.16-5) ... Hmm. The package shipped with a symbolic link /lib/modules/2.6.16-1-686/source However, I can not read it: No such file or directory Therefore, I am deleting /lib/modules/2.6.16-1-686/source Running depmod. Finding valid ramdisk creators. Using mkinitramfs-kpkg to build the ramdisk. Error, do this: mount -t proc none /proc hostname:~# apt-get clean hostname:~#Install Bootloader (Grub or Lilo) Either:
install the grub binaries:
root@hostname# apt-get install grubOr:
install the lilo binaries:
root@hostname# apt-get install lilo
At this time, we need to exit the chroot
hostname:~# exit logout root@hostname #
Either: GRUB
To install grub into the bootsector
root@hostname# grub-install --recheck --root-directory=/mnt/buildroot /dev/sda Probing devices to guess BIOS drives. This may take a long time. Installation finished. No error reported. This is the contents of the device map /mnt/buildroot//boot/grub/device.map. Check if this is correct or not. If any of the lines is incorrect, fix it and re-run the script `grub-install'. (fd0) /dev/fd0 (hd0) /dev/hda (hd1) /dev/sda root@hostname#
Next we need to open /mnt/buildroot/boot/grub/menu.lst and add this configuration.:
# default num default 0 # timeout sec timeout 5 # pretty colours color green/black black/green title Debian GNU/Linux-2.6.16-1-686 root (hd0,0) kernel /vmlinuz-2.6.16-1-686 root=/dev/sda1 init=/sbin/init initrd /initrd.img-2.6.16-1-686 savedefault boot title Debian GNU/Linux-2.6.16-1-686 (Rescue/Single) root (hd0,0) kernel /vmlinuz-2.6.16-1-686 root=/dev/sda1 init=/sbin/init single initrd /initrd.img-2.6.16-1-686 boot
# default num default 0 # timeout sec timeout 5 # pretty colours color green/black black/green title Debian GNU/Linux-2.6.16-1-686 root (hd0,0) kernel /vmlinuz-2.6.16-1-686 root=/dev/sda2 init=/sbin/init initrd /initrd.img-2.6.16-1-686 savedefault boot title Debian GNU/Linux-2.6.16-1-686 (Rescue/Single) root (hd0,0) kernel /vmlinuz-2.6.16-1-686 root=/dev/sda2 init=/sbin/init single initrd /initrd.img-2.6.16-1-686 boot
Then we need to run grub to link it all together
root@hostname# grub
Probing devices to guess BIOS drives. This may take a long time.
GNU GRUB version 0.97 (640K lower / 3072K upper memory)
[ Minimal BASH-like line editing is supported. For
the first word, TAB lists possible command
completions. Anywhere else TAB lists the possible
completions of a device/filename. ]
grub> root (hd1,0)
root (hd1,0)
Filesystem type is ext2fs, partition type 0x83
grub> setup (hd1)
setup (hd1)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/e2fs_stage1_5" exists... yes
Running "embed /boot/grub/e2fs_stage1_5 (hd1)"...
failed (this is not fatal)
Running "embed /boot/grub/e2fs_stage1_5 (hd1,0)"...
failed (this is not fatal)
Running "install /boot/grub/stage1 (hd1) /boot/grub/stage2
p /boot/grub/menu.lst "... succeeded
Done.
grub> quit
Or: LILO
Edit /mnt/buildroot/etc/lilo.conf so that it looks similar to this:
boot=/dev/sda root=/dev/sda1 compact bitmap=/boot/sid.bmp bmp-colors=1,,0,2,,0 bmp-table=120p,173p,1,15,17 bmp-timer=254p,432p,1,0,0 install=bmp default=sid # install=menu map=/boot/map vga=normal delay=20 image=/boot/vmlinuz-2.6.16-1-686 label=sid root=/dev/sda1 read-only initrd=/boot/initrd.img-2.6.16-1-686
boot=/dev/sda root=/dev/sda2 compact bitmap=/boot/sid.bmp bmp-colors=1,,0,2,,0 bmp-table=120p,173p,1,15,17 bmp-timer=254p,432p,1,0,0 install=bmp default=sid # install=menu map=/boot/map vga=normal delay=20 image=/boot/vmlinuz-2.6.16-1-686 label=sid root=/dev/sda2 read-only initrd=/boot/initrd.img-2.6.16-1-686
Then load the configuration into the master boot record
root@hostname# lilo -M /dev/sda # install MBR root@hostname# lilo -b /dev/sda # install lilo root@hostname#Thanks to Rick Bronson for submitting the Lilo configuration on my original howto.
Copy an existing /etc/group, /etc/passwd, and /etc/shadow file over from another system (this has to be done from outside the chroot directory).
root@hostname# cp /etc/passwd /etc/group /etc/shadow /mnt/buildroot/etc/ root@hostname#
Then chroot in and create their homedirectories
root@hostname# chroot /mnt/buildroot /bin/su - hostname:~# mkdir /home/<username> hostname:~# chown <username>.<username> /home/<username> <Repeat as necessary> hostname:~# exit root@hostname#Or:
Set root password and add users in the chroot
root@hostname# chroot /mnt/buildroot /bin/su -
hostname:~# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
hostname:~#adduser test
Adding user `test'...
Adding new group `test' (1001).
Adding new user `test' (1001) with group `test'.
Creating home directory `/home/test'.
Copying files from `/etc/skel'
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for test
Enter the new value, or press ENTER for the default
Full Name []: test
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [y/N] y
hostname:~#
<Repeat as necessary for more users>
hostname:~# exit
root@hostname#
And thats it. time to reboot and test.
Comments
error log
hi again,
i get this often : Can not write log, openpty() failed (/dev/pts not mounted?)
re: error log
this is an excellent
this is an excellent tutorial, i've managed to get myself a bootable usb stick. yay.
only bad thing is: you actually need a mainboard wich allows you to boot from usb sticks. as i wanted to use this on older hdd-less pcs, this doesnt work anymore.
any idea on howto start the system from an usb stick through a bootfloppy ?
info
Hi - answered my own question above :: exit jail
First, great pages Dave - learning curve's been steep the last week or more! Today I finally managed to get a working install on a USB2 device that has stumped me all week with about 5 or more attempts. I have seen nearly all of the errors that others have found at one point or another. The success today was combining info from both of the node 25 and 94 pages and carefully going through line by line in each section of each How To and omitting the encryption related stuff as Iḿ using only one partition, and don't want it anyway;
I found one definite problem that may have caught others if, like me, they raced through cutting and pasting commands just get things working. I was only careful checking the command line pastes for the right drive info - sdb in my case - but missed the etc/fstab file line each go except today, so the device was never going to boot all the way in to find its root fs , all other things being equal and is obviously the reason got the:
pivot_root : No such file or directory // Kernel panic ! and
can't open tty console - type of errors
for those of you who also have a SATA main drive in your PC which of course is sda! Idiot...
The first problems with this one device though, seemed to be "parted" not writing to the MBR correctly as when I checked the info Seth gave I also had parttion unreadable/anomolies in fdisk and cfdisk which may have been because the device had a messed mbr from all those Windows formats done when it was a working MP3 unit initially. I rewrote the MBR with
#apt-get install mbr
#install-mbr /dev/sdb
and did the partitioning and formatting with cfdisk and mkfs.ext2 first which seemed to fix things.
So its worth checking your device first before just plugging in and pasting commands then finding grub can't install properly later with a "can't read stage1 or 2" type error later on etc..
.
One other mistake I made was leaving and forgetting another USB disk device plugged in (a 2GB stick that had a first time succesfull encrypted install, node 94) when booting, which the main device tried to load and read stopping at something like
device sdd .0.0.0.0 assuming write cache-through
and got stuck which when removed and rebooted worked.
This time the install seemed to get stuck at (mkinitramfs) prompt and when I thought it had failed again,the device continued as it switched on again after 15-20 secs, then went all the way no probs.
Anyway, there was much more fun hosing both systems with the careless use of #rm -vR /tmp/.* in a clean up attempt (don't ask...!!) which recursively wiped both my main system and the USB within seconds!!...but I put that in just to give a smile or 2 to those experts out there! And messing up my main pc boot sector with grub and not having a boot floppy..ho hum..recovered it using the successful encrypted 2GB disk though , haha..!
For the next stage, now I have my wifi netcard and Samba working on it, seeing as Puppy Linux (which has never worked properly an any machine Ive had in the last 2 years) and Damn Small Linux claim to have a desktop environments for surfing, Office etc that fits on 50-90MB etc.(DSL-N didn't work today either!!) is there a Debian friendly X setup (much smaller than Gnome) anyone knows, that I could add to this sytem with my remaining 90M of space on this 479M drive? (incidently, how come the partition size was 518.2MB in cfdisk to start and now shows 479M total size, using
#df -h /dev/sdb
from my main system?? thatś 40M disappeared?!
I really would like this 512Mb disk to have desktop functions as its fast, cause the 2GB drive is USB1.1 only but works well enough with Gnome once its booted (slowly!)
thanks for a very interesting and useful website - I learned loads..
exit jail
HI
thus page has kept me frustrated all day...good work though. Problem is after installing kern img and grub and leaving jail I get:
blahhost# grub-install --recheck --root-directory=/mnt/buildroot /dev/sdb
Probing devices to guess BIOS drives. This may take a long time.
The file /mnt/buildroot/boot/grub/stage1 not read correctly.
Ive diff 'd this file against the PCs grub/stage1 file and they come up identical so why isn't it read?
any ideas - have tried removing grub and re -insting to see if it would re-write it but no...
Everything else worked fine up to this...
ta
Steve
It's possible to make USB
It's possible to make USB pen read-only?
re: It's possible to make USB
Yes.
Most USB keys have a small switch on the outside labeled "lock", this is the read vs read-write tab (as we remember from 3.5" floppy disks), set it to "lock" and its read only.
If that doesn't work for you or if you USB flash thumb drive does not include a switch then you can set the partitions to read-only while you are mounting them.
To always mount them as read-only, you can add RO as an option in /etc/fstab.
Or if the partition is not mounted in /etc/fstab, you can mount it be hand like so:
mount -o RO /dev/<device> /mnt/<mount-point>
But what about mtab and
But what about mtab and other files? I thing, there is a 2-3 files in etc directory that must be read/write.
re: But what about mtab and
You want to boot and run from a read-only OS on a USB flash thumb drive?
Then look into one of the many knoppix or live-CD derived distros.
http://en.wikipedia.org/wiki/Live_USB
Netinst option
Thanks for all the hard work thats been put into this reference!
I found this document after I had a working Debian USB system looking for flash fstab examples. I had luck installing to a USB key directly from the Debian NetInst disk. Boot up a system from the NetInst disk and a USB key, the installer takes care of most of the rest.
- Make sure to set up / and /boot partitions on the correct device (without swap, of course) and set them up as ext2.
- When setting up GRUB make sure to say no to the first suggestion of installing it on the primary hard disk. After that it asks for the device to install to.
- I did a base + standard + server install and used about 420MB of space on a 1Gig key.
- Now when booting from a different system (for me this was for a mini ITX board) be aware that the GRUB settings will probably be pointing to the wrong devices. You'll need to change the GRUB config to point to the right places, and get rid of reference to the old system.
- Edit /etc/fstab as above, again pointing mounts to the right places, I removed entries for cdrom and floppy since there are none on this system, and added the tmpfs. Also make sure / and /boot are set with noatime.
I wrote a script for doing all this
Error
I'm trying to install it on a usb drive using knoppix.. and I'm getting the following error:
any help would be appreciated
pivot_root : No such file or directory // Kernel panic !
Great How-to !!! very helpfull.
I tried the install on a 2Gb usb flash drive.
All went ok, grub ok, kernel image decompressed, but the boot failed at this point :
pivot_root : No such file or directory
/sbin/init 431: Cannot open /dev/console: No such file...
kernel panic
I wasted a lot of time searching for any help but finally I found on a web page, someone talking about
the kernel which take time to load the usb modules, but initrd image delay is set to zero and tries to load /sbin/init but doesn't find it as /dev/sda is not loaded yet ...
So 2 solutions for filesystems on /dev/sda recognized :
- Include SCSI/USB modules directly in the kernel image. No need to load usb modules (but kernel image bigger ...)
- or set DELAY=15 on /etc/mkinitrd/mkinitrd.conf and then rebuild the initrd image.
I didn't tried yet those solutions, for the moment, I'm working on a knoppix install solution on usb drive using FAT32 partition .
I'll try soon re-installing debian ext2 filesystems on usb drive, I hope it could help someone in the same situation.
Brgrds. // Brahim
re: pivot_root : No such file or directory // Kernel panic !
Thanks for the heads up, I'm sure one of the solutions will help.
...how does using "shred"
...how does using "shred" on a usb memory device impact MTBF for the life of the flash storage?
it counts as 25 writes
it counts as 25 writes IIRC. But shred is customizable, if you do shred -n X filenames, it does X writes.
lilo bug
root@hostname# lilo -M /dev/sda # install MBR
root@hostname# lilo -b /dev/sda # install lilo
root@hostname#
this won't work since lilo looks for /etc/lilo.conf by default and according to the tutorial, only /mnt/../etc/lilo.conf exists
You can try to add the -C flag but then lilo will compare lilo.conf to the actual system map and won't find /boot/vmlinuz....
buga
when are we chroot and when are we not ?
Unless, I get this wrong, it is very confusing to know whether we are typing cmd as chroot or not:
from point VII we are are chrooted:
hostname:~#
at point IX we should still be chrooted, but the ex says:
root@hostname:~#
and then back chrooted when calling localepurge
and again not chroot when apt-get clean(ing)
Then before installing the kernel, is it not better to install grub first since we use postinst_hook = /sbin/update-grub and postrm_hook = /sbin/update-grub in the kernel image ?
after this, I really don't know wheter it is in the /etc/ of the new system that we should edit the grub file or in our system, from point X we are supposed to quit the chroot but then when editing lilo, we are supposed to edit /mnt/.../etc/lilo/conf. However if grub is used, the how to say to edit /etc/grub/menu/ls (not as chroot so in the initial system).
Any help would be much appreciated since this how to is REALLY interesting
alex
re: when are we chroot and when are we not ?
Everything between step VII and step X is in the chroot. Everything else is outside of it. It seems counter intuitive to configure grub or lilo from outside the chroot but it works best this way.
As for /etc/grub/menu.lst well that was a typo.
It should have read: /mnt/buildroot/boot/grub/menu.lst
Fixed now for future reference.
Thanks for catching that.
root@hostname# chroot
root@hostname# chroot /mnt/buildroot /bin/su -l
hostname:~#
/bin/su: invalid option -- l
Did you mean "chroot /mnt/buildroot /bin/su -"?
Luka666
re: chroot
"su -l" is an old habit and had the same effect as "su -".
So yes. Thats what I meant and I've fixed the text.
Thanks.
Boot error! /sbin/init 432: Couldn't find /dev/console
Great how to.
I did follow your install instructions and there were no errors along the way, but when booting I get Kernel panic error right after /sbin/init 432: Couldn't find /dev/console. I had to use kernel 2.4.27-3-386. Is that what causing the issue?
re: Boot error! /sbin/init 432: Couldn't find /dev/console
Sounds like the devices were not correctly copied into the initrd, which very well could be because of the 2.4 kernel (more specifically because of no udev support).
You could also try using Yaird instead of initramfs-tools to build the initrd file.
one more anomaly re: disk partitioning
After partioning/formatting my thumbdrive using the following command as per the guide:
root@hostname# parted /dev/sda "mklabel msdos mkpartfs primary ext2 0 21 mkpartfs primary ext2 22 -0 set 1 boot on"I noticed that fdisk reports some partitioning anomalies (see below). Is this something to be concerned about?
re: one more anomaly re: disk partitioning
Nice catch. Thats a bug/typo in the parted command.
It should read:
parted /dev/sda "mklabel msdos mkpartfs primary ext2 0.0 21.0 mkpartfs primary ext2 21.0 -0 set 1 boot on"
Now, I ran an install with this partitioning problem for a long time and was completely unaware of it, so I dont think there is significant risk. Then again if its a fresh install, I'd probably wipe and fix it quick.
debootstrap.log contents
btw, here's the contents of debootstrap.log:
chroot: cannot run command `mount': No such file or directory
debootstrap command fails
I'm trying to follow these instructions on a system running Xubuntu linux 6.06
I get as far as running the debootsrap command...
debootstrap --arch i386 dapper /mnt/buildroot
...which eventually fails here:
I: Extracting sysvinit...
I: Extracting tar...
I: Extracting util-linux...
I: Extracting zlib1g...
W: Failure trying to run: chroot /mnt/buildroot mount -t proc proc /proc
Have tried re-partitioning and formatting my usb drive a couple of times now, but it still chokes in the same place.
Any suggestions?
I ran into the same problem
I ran into the same problem when using debootstrap on Debian Etch. I found out my USB device was mounted with the following (default in usbmount) options: noexec,nodev. I removed these from /etc/usbmount/usbmount.conf which solved the problem.
can not mount /proc in chroot
i have experienced two problems so far
First one is related to the partition. As discussed elsewhere. i have tried to partition twice but fdisk reports as the partitiong not ending at cylindder boundry.
i decided to move on to next step and see how far I can go?
Second problem is where I am stuck right now.
After paritional and mounting the usb drive under /mnt/flashdrv. i tried to run debootstrap and i receive error message about can not run mount The full message is as follows.
wolverine:~# debootstrap --arch i386 sid /mnt/flashdrv/
I: Retrieving Packages
I: Validating Packages
I: Resolving dependencies of required packages...
I: Resolving dependencies of base packages...
W: Failure trying to run: chroot /mnt/flashdrv mount -t proc proc /proc
if I try to manually run the command for mount. i get the similar message as posted by someone else.
wolverine:~# chroot /mnt/flashdrv/ mount -t proc proc /proc
chroot: cannot run command `mount': No such file or directory
I just ran aptitude update && aptitude upgrade to make sure my installation was upto date.
I am running debian unstable. I have 1GB flash drive /dev/sdc partitioned into two partitions ( /dev/sdc1 , /dev/sdc2) mounted as / and /boot respectively.
Any help suggests would be much appreciated.
Bhavesh R.
Same problem.
I have been trying to follow directions for past couple of days. But i keep running into two problems.
First problem is partitionaing, as another poster has mentioned, the parition does not seem to fall on a cylinder boundry, I have tried to create the partitions twice but same problem, i decided to move on to see how far i can go before it comes back to bite me :)
Second problem I have is as follows:
wolverine:~# debootstrap --arch i386 sid /mnt/flashdrv/
I: Retrieving Packages
I: Validating Packages
I: Resolving dependencies of required packages...
I: Resolving dependencies of base packages...
W: Failure trying to run: chroot /mnt/flashdrv mount -t proc proc /proc
I do not have usbmount installed, i don't have hotplug installed. i attempted to mount the drive manually with -o dev,exec options thinking may be the system is defaulting to it, but i am still receiving same error.
When i try to manually mount the proc inside /mnt/flasdrv I receive the following message
wolverine:~# chroot /mnt/flashdrv/ mount -t proc proc /proc
chroot: cannot run command `mount': No such file or directory
I am trying to install it on a 1GB usb drive. I am running debian unstable on my computer and I just finished running aptitude update/upgrade to make sure my system has the newest packages.
any direction/help would be much appreciated.
Bhavesh R
great HOWTO
Hi,
Thanks for the great HOWTO. I've just finished installing Debian etch onto a 1GB partition on a 2GB usb key. It seems to work fine, just looking at getting X running on it now :)
I don't suppose you want to extend this with some tips on how to run the USB key in read-only mode? It would be useful for flash devices in general (not sure how long a usb key will last with lots of writes even if log and tmp are using tmpfs)?
-stephen
how to not fsck up existing system on step XI (grub-stuff)
I'm trying to install my usb-key (with grub) one machine, and then use it from another machine. Doesn't these step, outside the chroot, just alter my regular bootloader?
(I think it was here I screwed up the first time, needing to reinstall system and pick up my latest backup of work)
re: how to not fsck up existing system on step XI (grub-stuff)
If you'll look at the first step in part XI, you'll see that we do "grub-install". From its output, we can see that on my development box HD0 is the first IDE drive and my usual system drive, and we can see that HD1 is the only other drive detected.
Then in the last grub step, you will see that we install to HD1 and not HD0 so the base system will remain unchanged.
If you do accidentally overwrite the grub installed on your base system drive, simply boot to any rescue media to fix it, the rest of the system will still be intact.
Got it working, thanks
Learned a bit more about Grub, and now I can install on a usb-stick with success and still keep my existing system. Only needed a little post-editing of menu.lst on both the usb and hd before booting. Thanks for a really valuable site.
You are using mkinitramfs
You are using mkinitramfs to build the default initial ramdisk from Debian.
I've also read other HOWTOs around and after configuring the distribution, they use squashfs and unionfs (so they build a very different initial ramdisk).
Do you know how to add them you your setup in a easy way?
Re: mkinitramfs options
The reason this howto uses mkinitramfs is because that is the default tool for Debian at this time.
Now having said that, I'm all for exploring the options so that we can see what works best for USB and other removable media.
As for squashfs and unionfs, I haven't worked with them yet but you can see examples of how to use cramfs and Yaird in two other howtos I've written.
Cramfs example at: http://www.debian-administration.org/articles/179
Yaird example at: http://feraga.com/node/30
One of these days I need to consolidate all this info into the Base Configuration section, but I just haven't gotten to it yet.
Know of any other good examples to add?
A little problem
I tried the instruccions in a directory before installing a USB drive.
So I began in step VI:
#mkdir my_amazing_distro
#debootstrap --arch i386 sid /mnt/hda8/my_amazing_distro
what I get is:
I: Retrieving Release
I: Retrieving Packages
I: Validating Packages
I: Resolving dependencies of required packages...
(snip)
I: Extracting util-linux...
I: Extracting zlib1g...
I: Installing core packages...
W: Failure trying to run: chroot /mnt/hda8/my_amazing_distro dpkg --force-depends --install var/cache/apt/archives/libc6_2.3.6-7_i386.deb
If I try to do it at hand:
# chroot /mnt/hda8/my_amazing_distro/.
# dpkg --force-depends --install var/cache/apt/archives/libc6_2.3.6-7_i386.deb
(Reading database ... 583 files and directories currently installed.)
Preparing to replace libc6 2.3.6-7 (using .../libc6_2.3.6-7_i386.deb) ...
/var/lib/dpkg/tmp.ci/preinst: line 117: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 122: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 127: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 117: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 122: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 117: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 122: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 117: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 122: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 127: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 117: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 122: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 117: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 122: /dev/null: Permission denied
Unpacking replacement libc6 ...
dpkg: libc6: dependency problems, but configuring anyway as you request:
libc6 depends on tzdata; however:
Package tzdata is not installed.
Setting up libc6 (2.3.6-7) ...
/var/lib/dpkg/info/libc6.postinst: line 112: /dev/null: Permission denied
/var/lib/dpkg/info/libc6.postinst: line 112: /dev/null: Permission denied
/var/lib/dpkg/info/libc6.postinst: line 29: /dev/null: Permission denied
dpkg: error processing libc6 (--install):
subprocess post-installation script returned error exit status 1
Errors were encountered while processing:
libc6
Any idea about what's going wrong?
Very helpful HOWTO anyway.
re: Debootstrap Permission Denied Error
I just ran a test run of debootstrap here and it completes without errors.
This error resembles the ones reported last summer when the Debian admins were working on upgrading libc and gcc. I wonder if maybe there was just an unbalanced update when you tried your run that had been fixed by the time I ran mine.
That might be so because your error log is reporting:
dpkg: libc6: dependency problems, but configuring anyway as you request:
libc6 depends on tzdata; however:
Package tzdata is not installed.
And my install reports tzdata is installed correctly.
I'd recommend giving debootstrap another clean run. Reformat the partition, remount it and restart debootstrap.
FYI for future use, rather than rerun the command by hand, just check the error log in /mnt/hda8/myamazingdistro/debootstrap/debootstrap.log for detailed information.
/dev/null ?
I used a directory instead of a partition but since the error happens inside the chroot, I don't think that makes any difference.
I'm using debian unstable and I have debootstrap, dpkg, libc6 and gcc in their latest version (according to apt-get)
I also tried that instruccions today, so if you are also using the lastest version of that software, we both have the same environment.
The problem seems related to /dev/null
I installed tzdata in the chroot without problems, then I move to libc6:
#dpkg --force-depends --install var/cache/apt/archives/libc6_2.3.6-7_i386.deb
(Reading database ... 2329 files and directories currently installed.)
Preparing to replace libc6 2.3.6-7 (using .../libc6_2.3.6-7_i386.deb) ...
/var/lib/dpkg/tmp.ci/preinst: line 117: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 122: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 127: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 117: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 122: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 117: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 122: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 117: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 122: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 127: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 117: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 122: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 117: /dev/null: Permission denied
/var/lib/dpkg/tmp.ci/preinst: line 122: /dev/null: Permission denied
Unpacking replacement libc6 ...
Setting up libc6 (2.3.6-7) ...
/var/lib/dpkg/info/libc6.postinst: line 112: /dev/null: Permission denied
/var/lib/dpkg/info/libc6.postinst: line 112: /dev/null: Permission denied
/var/lib/dpkg/info/libc6.postinst: line 29: /dev/null: Permission denied
dpkg: error processing libc6 (--install):
subprocess post-installation script returned error exit status 1
Errors were encountered while processing:
libc6
/dev/null seems ok (/dev/ also have the correct permisions and everything is run as root), but it's not working:
# ls -la /dev/null
crw-rw-rw- 1 root root 1, 3 Nov 5 18:32 /dev/null
#echo "echo" > /dev/null
bash: /dev/null: Permission denied
from:
from: http://www.knoppix.net/wiki/Dev_null_permission_denied
Its commonly reported that when users chroot into an existing linux environment on their harddrive, they encounter the /dev/null: Permission Denied error message. This page attempts to explain it and how to avoid it.
The error is caused by mounting a filesystem with the "nodev" mount option and then chrooting into it. Knoppix automatically places a "users" mount option into the /etc/fstab file, which implies this "nodev" option. This can happen if you save your Knoppix configure data to the same partition that you are using here, AND if you start with Knoppix with knoppix home=scan.
You can override this option by editting /etc/fstab and appending ",dev" to the options column or simply mount your new chroot filesystem by bypassing the /etc/fstab entirely by typing the following command:
mount -o remount,dev /dev/hda1
If the /dev/null warnings persist then before the chroot do :
mkdir /mnt/hda1/knx/source/KNOPPIX/KNOPPIX
mount --bind /KNOPPIX /mnt/hda1/knx/source/KNOPPIX
mount --bind /dev /mnt/hda1/knx/source/KNOPPIX/dev
And re-enter the chroot. Remember that you have to
umount /mnt/hda1/knx/source/KNOPPIX/dev
umount /mnt/hda1/knx/source/KNOPPIX
rmdir /mnt/hda1/knx/source/KNOPPIX/KNOPPIX
before building the CD image or your /dev directory on the CD will be messed up!
Same here: root@suske:/dev#
Same here:
root@suske:/dev# ls -al null
crw-rw-rw- 1 root root 1, 3 Oct 12 10:36 null
root@suske:/dev# echo "xxx" > null
bash: null: Permission denied
the null is there, but I get perm denied.
interesting enough
After doing:
dpkg --force-depends --install var/cache/apt/archives/*
libc6 seems unconfigured, I do this:
#dpkg --configure libc6
Setting up libc6 (2.3.6-7) ...
/var/lib/dpkg/info/libc6.postinst: line 29: /dev/null: Permission denied
dpkg: error processing libc6 (--configure):
subprocess post-installation script returned error exit status 1
Errors were encountered while processing:
libc6
Ok, I try to debug the script to see where it's failing and I got this:
# sh -x /var/lib/dpkg/info/libc6.postinst
+ set -e
+ export LC_ALL=C
+ LC_ALL=C
+ type=
+ preversion=
+ package=libc6
+ '[' -L /usr/doc/libc6 ']'
+ for suffix in -dbg -dev -pic -prof
+ package_name=libc6-dbg
+ '[' -L /usr/doc/libc6-dbg ']'
+ for suffix in -dbg -dev -pic -prof
+ package_name=libc6-dev
+ '[' -L /usr/doc/libc6-dev ']'
+ for suffix in -dbg -dev -pic -prof
+ package_name=libc6-pic
+ '[' -L /usr/doc/libc6-pic ']'
+ for suffix in -dbg -dev -pic -prof
+ package_name=libc6-prof
+ '[' -L /usr/doc/libc6-prof ']'
+ '[' '' = configure ']'
++ uname -s
+ '[' Linux = Linux ']'
++ dpkg -s sysvinit
/var/lib/dpkg/info/libc6.postinst: line 355: /dev/null: Permission denied
++ grep '^Version:'
++ sed -e 's/^Version: *//'
+ sysvinitver=
+ case "`uname -m`" in
++ uname -m
+ badsysvinitver='2.[0-6]*|2.7[0-3]*'
+ case "$sysvinitver" in
+ '[' -x /sbin/init -a -x /bin/readlink ']'
++ readlink /proc/1/exe
/var/lib/dpkg/info/libc6.postinst: line 372: /dev/null: Permission denied
+ '[' '' = /sbin/init ']'
+ '[' '' = configure ']'
+ exit 0
So, it's returning 0 and dpkg is getting a -1?
I really can't get it ?_?
Solved
Inside the chroot I mount the /dev directory as tmpfs and create the null file.
An ugly hack but that solved everything
Re: Solved
Interesting. I've tried recreating this error with a partition on a USB stick and with a test directory. Both ways work without error here. I wonder what I'm doing different that I haven't documented properly.
Well thanks for the excellent followup, it will be very useful as I try to track this problem down.
A little typo?
In the end of part three it says:
Shouldn't you mount the boot-partition (sda1) under /mnt/buildroot/boot, making it look like this:
Re: A little typo?
Nice catch. Fixed.
Thanks.