Results 1 to 3 of 3

Thread: [HOWTO] How to boot a chroot directory ...

  1. #1
    Senior Member registered user
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    297

    [HOWTO] How to boot a chroot directory ...

    This is actuaqlly a copy of a mail I sent to debian-knoppix earlier this day ...

    I hope this is interesting for some of you:

    ---

    Hi,

    in my last mail I said, that there are problems with chroot, that you are not
    able to unmount or remount ...

    I also had an idea, and this idea did work ...

    What you need:

    - Linux partition
    - Lilo (Grub could also be possible)

    Create an ext2-image with 2560000 bytes. (Should be enough).

    Mount it to /mnt.

    -rwxr-xr-x 1 root root 150580 2002-07-26 14:09 /mnt/static/ash
    lrwxrwxrwx 1 root root 3 2003-04-01 23:46 /mnt/static/init
    -> ash
    lrwxrwxrwx 1 root root 3 2003-04-01 23:46 /mnt/static/sh ->
    ash

    Copy ash to /mnt/static and create symlinks ...

    Copy needed modules (for ext3 that are jbd.o and ext3.o) to /mnt/modules

    -rw-r--r-- 1 root root 87626 2003-04-01 23:46
    /mnt/modules/ext3.o
    -rw-r--r-- 1 root root 74090 2003-04-01 23:46 /mnt/modules/jbd.o

    Copy device that needs to be mounted to /mnt/dev (or copy whole /dev)

    cp libraries for non-static binaries ("real" mount/pivot_root are needed)

    -rwxr-xr-x 1 root root 82456 2003-05-07 09:27
    /mnt/lib/ld-linux.so.2
    -rwxr-xr-x 1 root root 1104072 2003-05-07 09:27 /mnt/lib/libc.so.6

    mkdir -p /mnt/mnt /mnt/mnt2 /mnt/proc

    copy mount and pivot_root to /bin:


    -rwsr-xr-x 1 root root 81080 2003-05-07 09:27 /mnt/bin/mount
    -rwsr-xr-x 1 root root 4832 2003-05-07 09:27
    /mnt/bin/pivot_root

    Last but not least create the /mnt/linuxrc the heart of our operation )

    #!/static/sh

    # load needed modules
    insmod /modules/jbd.o
    insmod /modules/ext3.o

    # mount proc, say that root is pivot_rooted and unmount it
    mount -t proc proc /proc
    echo 256 > /proc/sys/kernel/real-root-dev
    umount /proc

    # mount the root-filesystem
    mount -t ext3 /dev/hda5 /mnt

    # tricky: We now bind our chroot environment to /mnt2
    /bin/mount --bind /mnt/home/knoppix/newroot /mnt2

    # now we unmount the root-filesystem; believe me, its possible and /mnt2 is
    still there
    umount /mnt

    # Now we change the root permanently to the chroot-dir and we can do every
    operation that is needed (remount, unmount, ...)

    /bin/pivot_root /mnt2 /mnt2/initrd

    Of course you can sue the comments and just have the script so compact :

    #!/static/sh
    insmod /modules/jbd.o
    insmod /modules/ext3.o
    mount -t proc proc /proc
    echo 256 > /proc/sys/kernel/real-root-dev
    umount /proc
    mount -t ext3 /dev/hda5 /mnt
    /bin/mount --bind /mnt/home/knoppix/newroot /mnt2
    umount /mnt
    /bin/pivot_root /mnt2 /mnt2/initrd

    I tried this and it did work ... I was really suprised, but I think its an
    kind of easy way to test several copied knoppix systems or bootstrapped and
    then knoppised debian's ).

    If anyone knows an easier way, I'm interested to learn it (Or if anyone
    knows this way from another source on the web ...)

    btw. lilo.conf:

    image=/boot/vmlinuz-2.4.20-xfs
    label=Chroot
    append="hda=scsi hdb=scsi hdc=scsi hdd=scsi hde=scsi hdf=scsi hdg=scsi
    hdh=scsi apm=power-off nomce ramdisk_size=100000 lang=de init=/etc/init"
    initrd=/boot/chroot_initrd
    read-only

    I think it would be possible to also have all this pointing to
    /home/knoppix/newroot/vmlinuz|boot/chroot_initrd ...

    But as I had the same kernel, I'm lazy ... )

    cu

    Fabian

    PS: I hope this is useful to someone ...
    PPS: So you can finally start your changed system and such USE sortlists and
    so optimise the system more and more without the need of an extra-partition
    ...

  2. #2
    Senior Member registered user
    Join Date
    Mar 2003
    Posts
    872
    I am confused. What do you want to achieve ? I use pivot_root in the normal initrd to boot into a real root fs(say a clooped device, or a loopback device on FAT/NTFS) but don't quite understand what you want to do in this post. pivot_root is sort of like a 'chain boot' to me and there is no way one can get back to the previous root system. I believe UML is a better way to test out a new distribution within a running system.

    BTW, in general people seldom do a pivot_root to absolute path "/..." but rather :

    cd /your_new_root
    pivot_root . etc/init(this is a under the new root system and note the absence of / before etc)

  3. #3
    Senior Member registered user
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    297
    Quote Originally Posted by garyng
    I am confused. What do you want to achieve ? I use pivot_root in the normal initrd to boot into a real root fs(say a clooped device, or a loopback device on FAT/NTFS) but don't quite understand what you want to do in this post. pivot_root is sort of like a 'chain boot' to me and there is no way one can get back to the previous root system. I believe UML is a better way to test out a new distribution within a running system.

    BTW, in general people seldom do a pivot_root to absolute path "/..." but rather :

    cd /your_new_root
    pivot_root . etc/init(this is a under the new root system and note the absence of / before etc)
    If you want to test Knoppix-features like hw-detection, I think UML is no choice as you need real test-circumstances ...

    I want to boot a directory /home/knoppix/newroot as if everything in newroot was in its own partition!

    So /mnt/home/knoppix/newroot -> /

    But with pivot_root this is not possible ... (Neither with relative nor absolute path)

    You need the trick, I've described above ...

    cu

    Fabian

    PS: Btw and yes, you CAN change the System, while running with pivot_root and you can also go back (if you don
    't unmount the initrd) ...

Similar Threads

  1. Newbie - howto boot with out x11
    By astranberg in forum Hardware & Booting
    Replies: 1
    Last Post: 05-10-2005, 04:15 AM
  2. HOWTO? ssh start at boot-up
    By A. Jorge Garcia in forum General Support
    Replies: 4
    Last Post: 05-08-2004, 01:35 PM
  3. chroot: /bin/bash: no such file or directory
    By kevinonknoppix in forum Customising & Remastering
    Replies: 0
    Last Post: 02-24-2004, 08:45 AM
  4. chroot error:no such file or directory
    By bongski55 in forum Customising & Remastering
    Replies: 3
    Last Post: 06-21-2003, 11:16 AM
  5. howto use KDiskfree mount,can see chinese directory name?
    By babo in forum Customising & Remastering
    Replies: 0
    Last Post: 03-06-2003, 03:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Mini Computer Vacuum USB Keyboard Cleaner PC Laptop Brush Dust Cleaning Kit NEW picture

Mini Computer Vacuum USB Keyboard Cleaner PC Laptop Brush Dust Cleaning Kit NEW

$13.89



Mini Computer Vacuum Cleaner & Compressed Air Duster 14500Pa, 110000RPM, Cordles picture

Mini Computer Vacuum Cleaner & Compressed Air Duster 14500Pa, 110000RPM, Cordles

$53.99



Cordless Air Duster & Vacuum Cleaner for Keyboard & PC Cleaning - 110000RPM Powe picture

Cordless Air Duster & Vacuum Cleaner for Keyboard & PC Cleaning - 110000RPM Powe

$53.99



2-in-1 Compressed Air Duster & Vacuum, Brushless Motor, 320000RPM picture

2-in-1 Compressed Air Duster & Vacuum, Brushless Motor, 320000RPM

$37.99



MAYKU FormBox Desktop Vacuum Forming Machine W / Starter Kit picture

MAYKU FormBox Desktop Vacuum Forming Machine W / Starter Kit

$399.00



US Mini Computer Vacuum USB Keyboard Cleaner PC Laptop Brush Dust Cleaning Kits picture

US Mini Computer Vacuum USB Keyboard Cleaner PC Laptop Brush Dust Cleaning Kits

$13.89



Vacloong Vacuum-Sealed 3D Printing Filament Kit, 20 Packs PUMP+20P, White  picture

Vacloong Vacuum-Sealed 3D Printing Filament Kit, 20 Packs PUMP+20P, White

$18.99



2 in 1 Compressed Air Duster Air Blower & Vacuum Cleaner Cordless Duster Blower picture

2 in 1 Compressed Air Duster Air Blower & Vacuum Cleaner Cordless Duster Blower

$16.99



LEVOIT Cordless Vacuum Cleaner, Stick Vac with Tangle-Resistant Design, Up to... picture

LEVOIT Cordless Vacuum Cleaner, Stick Vac with Tangle-Resistant Design, Up to...

$162.04



Cordless Handheld Vacuum Cleaner Compatible with DeWalt 20V Battery picture

Cordless Handheld Vacuum Cleaner Compatible with DeWalt 20V Battery

$107.67