LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 08-26-2010, 03:29 PM   #1
ceazar123
LQ Newbie
 
Registered: Jun 2009
Location: India
Distribution: CentOS
Posts: 15

Rep: Reputation: 0
Read Write access to a iso9660 filesystem..mount a .iso image as read write


Hi Guys,

I have made a boot-able iso image which mounts vmlinuz and initrd.img into the RAM using initramfs. The initrd.img mounts a basic file system that takes me to a busybox shell.

From this shell, I run a small shell scripts that is as follows:

#!/bin/sh

echo Creating a mount point
mkdir /mnt
echo Mounting the Root File System
mount /dev/hdc /mnt ==> this mounts the iso image in the cd-rom to /mnt
echo changing Root
mount -o bind /proc /mnt/boot/proc/
mount -o bind /sys /mnt/boot/mnt/
export HOME=/root
chroot /mnt/boot

After this it boots fine, and I can see my file system that is loaded on my cd (.iso image). However, this is a read-only file system and I am not able to do anything.

I have already tried mounting a directory as tmpfs and binding a few directories to it, however it does not server my purpose.

So, I am stuck with a read only file system. Please can anyone point me to the right direction of create a read write on the file system.

Thanks and Regards,
-=Srijan
 
Old 08-27-2010, 09:06 AM   #2
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 4,202

Rep: Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642
^ if you are mounting the cd-rom drive (/dev/hdc) how are you expecting to write to the cd (the contents of the cd are not really on your ram-disk -- the mounted directory on your ram-disk points back to the read-only cd-rom) ?

i think what you would like to do is copy the contents of the cd somewhere and be able to read-write to that location.

would this give you more mileage ?:
Code:
#!/bin/sh

echo Creating a mount point
mkdir /mnt2 /mnt
echo Mounting the Root File System
mount /dev/hdc /mnt2 #==> this mounts the iso image in the cd-rom to /mnt
cp -r /mnt2/* /mnt
# chmod -R 744 /mnt
# umount /mnt2
echo changing Root
mount -o bind /proc /mnt/boot/proc/
mount -o bind /sys /mnt/boot/mnt/
export HOME=/root
chroot /mnt/boot

Last edited by schneidz; 08-27-2010 at 09:09 AM.
 
Old 08-27-2010, 10:02 AM   #3
ceazar123
LQ Newbie
 
Registered: Jun 2009
Location: India
Distribution: CentOS
Posts: 15

Original Poster
Rep: Reputation: 0
Hi schneidz,

Actually I have a CentOS Server, running 2.6.29. I have configured a small firewall, with iptables, snort_inline, zebra, keepalived etc. I wanted to make an iso image of my own distro, so that I can give it to my friends so that they can use a ready made Firewall.

To accomplish this, I created an initrd image using busybox that has an init file. The contents of the init file is:

#!/bin/nash

mount -t proc /proc /proc
setquiet
echo Mounting proc filesystem
echo Mounting sysfs filesystem
mount -t sysfs /sys /sys
echo Creating /dev
mkdir /dev/shm
mount -o mode=0755 -t tmpfs /dev/shm /dev/shm
mkdir /dev/pts
mount -t devpts -o gid=5,mode=620 /dev/pts /dev/pts
echo Creating initial device nodes
mknod /dev/null c 1 3
mknod /dev/zero c 1 5
mknod /dev/urandom c 1 9
mknod /dev/systty c 4 0
mknod /dev/tty c 5 0
mknod /dev/console c 5 1
mknod /dev/ptmx c 5 2
mknod /dev/rtc c 10 135
mknod /dev/tty0 c 4 0
mknod /dev/tty1 c 4 1
mknod /dev/tty2 c 4 2
mknod /dev/tty3 c 4 3
mknod /dev/ttyS0 c 4 64
mknod /dev/ttyS1 c 4 65
mknod /dev/ttyS2 c 4 66
mknod /dev/root c 3 1
mknod /dev/hdc b 22 0
mknod /dev/sda b 8 0
mknod /dev/sda1 b 8 1
mknod /dev/root b 8 1
echo Setting up hotplug.
hotplug
echo Creating block device nodes.
mkblkdevs
echo "Loading ehci-hcd.ko module"
insmod /lib/ehci-hcd.ko
echo "Loading ohci-hcd.ko module"
insmod /lib/ohci-hcd.ko
echo "Loading uhci-hcd.ko module"
insmod /lib/uhci-hcd.ko
mount -t usbfs /proc/bus/usb /proc/bus/usb
echo "Loading scsi_transport_spi.ko module"
insmod /lib/scsi_transport_spi.ko
echo "Loading mptbase.ko module"
insmod /lib/mptbase.ko
echo "Loading mptscsih.ko module"
insmod /lib/mptscsih.ko
echo "Loading mptspi.ko module"
insmod /lib/mptspi.ko
echo "Loading usb-storage.ko module"
insmod /lib/usb-storage.ko
mkblkdevs
echo My Shell
/bin/sh

Along with the initrd.img and vmlinuz, I have made an iso image.

Once I boot the iso image, it gives me the busybox shell. However it is still in initramfs state. Then I try to mount the files in the iso to a /mnt directory and chroot to the environment according to this script:

#!/bin/sh

echo Creating a mount point
mkdir /mnt
echo Mounting the Root File System
mount /dev/hdc /mnt ==> this mounts the iso image in the cd-rom to /mnt
echo changing Root
mount -o bind /proc /mnt/boot/proc/
mount -o bind /sys /mnt/boot/mnt/
export HOME=/root
chroot /mnt/boot

As I have a ram size of around 256Mb, mounting the entire contents of the cd in the ram and then copying from the ram would not be possible.

I cannot do much as the file system mounted is read only. I need a read write environment, so that I can get things modified and certain files that uses /var can write to it.

If possible can I have the entire file system as read only, however have certain directories such as /dev, /var, /proc as read write.

Thanks and Regards,
-=Srijan
 
Old 08-27-2010, 10:35 AM   #4
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 4,202

Rep: Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642
Quote:
Originally Posted by ceazar123 View Post
As I have a ram size of around 256Mb, mounting the entire contents of the cd in the ram (?) and then copying from the ram would not be possible.
as i understand it the contents in the read-only cd-rom drive are not on the ram-fs. are you able to run df -h ? (how big is the iso ?)

Quote:
Originally Posted by ceazar123 View Post
If possible can I have the entire file system as read only, however have certain directories such as /dev, /var, /proc as read write.
probably, maybe your iso can contain symlinks of /dev /var /proc to places on the ram-fs.

Last edited by schneidz; 08-27-2010 at 10:36 AM.
 
Old 08-27-2010, 10:55 AM   #5
eyemole80
Member
 
Registered: Jun 2004
Distribution: Fedora Core 1
Posts: 47
Blog Entries: 1

Rep: Reputation: 16
I think you are trying to create your own customized full blown CentOS installer CD. But it seems you are fine with even LiveCD as well. If you are looking to create a customized CentOS Live CD. There is much simpler way to do it. Using kickstart and live-cd creator tool you can create customized LiveCDs for Redhat/Fedora/CentOS based distributions.

Last edited by eyemole80; 08-27-2010 at 11:19 AM.
 
Old 08-27-2010, 11:23 AM   #6
ceazar123
LQ Newbie
 
Registered: Jun 2009
Location: India
Distribution: CentOS
Posts: 15

Original Poster
Rep: Reputation: 0
Hi eyemole,

You got me right. I tried that, however was not able to do so. So I had to figure out a hard way to do it.

schneidz

The initrd.img and the vmlinuz boots to the ram. The contents of the CD-Rom are opened after wards when I get to the busybox shell using the init script. After boot up, a df -hT shows the following;

/dev/shm 123.3M 0 123.3M 0% /dev/shm

after mounting my cd-rom and then chroot'ing to the environment shows me this:

Filesystem Size Used Avail Use% Mounted on
/dev/sda1 2.5G 2.5G 0 100% /
devpts 2.5G 2.5G 0 100% /dev/pts
tmpfs 2.5G 2.5G 0 100% /dev/shm
sunrpc 2.5G 2.5G 0 100% /var/lib/nfs/rpc_pipefs

However, my /proc/mounts shows that actual;

rootfs / rootfs rw 0 0
/proc /proc proc rw 0 0
/sys /sys sysfs rw 0 0
/dev/shm /dev/shm tmpfs rw,mode=755 0 0
/dev/pts /dev/pts devpts rw,mode=600 0 0
/proc/bus/usb /proc/bus/usb usbfs rw 0 0
/dev/hdc /mnt iso9660 ro 0 0
/proc /proc proc rw 0 0
/sys /sys sysfs rw 0 0



Quote:
probably, maybe your iso can contain symlinks of /dev /var /proc to places on the ram-fs.

I tried that as well. Once I have mounted the contents of the cd. I chroot to it. There I can see the files in read only. So i tried mounting /var as tmpfs. As soon as I do so, it removes all the previously contained files.

-=Srijan
 
Old 08-27-2010, 01:12 PM   #7
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 4,202

Rep: Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642
i wonder why your df -h doesnt say anything about your cd-rom (/dev/hdc).

i just booted knoppix-live and i see this snippet on the start-up:
Code:
accessing knoppix cd at /dev/sr0
found primary knoppix compressed image at /cdrom/knoppix/knoppix
creating /ramdisk on shared memory... done
creating unified filesystem and symlinks on ramdisk
read-only cd system successfully merged with read-write /ramdisk.
maybe you can peruse the knoppix source and figure out how they do it.
 
Old 08-27-2010, 02:14 PM   #8
ceazar123
LQ Newbie
 
Registered: Jun 2009
Location: India
Distribution: CentOS
Posts: 15

Original Poster
Rep: Reputation: 0
The initrd.img along with the compressed linux kernel (vmlinuz) boots off well from the cd-rom. Because of this I get the shell. I just got a few snippets from dmesg, that shows the boot procedure.

Memory: 249536k/262144k available (3746k kernel code, 11764k reserved, 2181k data, 332k init, 0k highmem)
virtual kernel memory layout:
fixmap : 0xffc5a000 - 0xfffff000 (3732 kB)
pkmap : 0xff800000 - 0xffa00000 (2048 kB)
vmalloc : 0xd0800000 - 0xff7fe000 ( 751 MB)
lowmem : 0xc0000000 - 0xd0000000 ( 256 MB)
.init : 0xc09d3000 - 0xc0a26000 ( 332 kB)
.data : 0xc07a8926 - 0xc09ca0ec (2181 kB)
.text : 0xc0400000 - 0xc07a8926 (3746 kB)

checking if image is initramfs... it is
Freeing initrd memory: 2237k freed

After I get a shell, it's still in ram memory. That's why, when I do a df -hT here I see /dev/shm mounted on /dev/shm.

As I have around 2.6Gb data on the cd, that's the reason I couldn't throw everything on the ram at boot up time. Or else I would need around 3 GB RAM to suuport that.

To counter that, I mounted a small file system on the ram, so that it could take me to a shell. Now once I get the shell, I mount my cd-rom, that contains all the data I want to mount. Here after mounting the cd-rom, I do a chroot to the /mnt directory.

Once here if I do a df -hT, I still do not get the cd-rom drive listed as it is not there in my fstab or mtab. However, if I see /proc/mounts, it shows the actual files loaded. It's here that you would see my cd-rom mounted:

/proc/mounts shows that actual:

rootfs / rootfs rw 0 0
/proc /proc proc rw 0 0
/sys /sys sysfs rw 0 0
/dev/shm /dev/shm tmpfs rw,mode=755 0 0
/dev/pts /dev/pts devpts rw,mode=600 0 0
/proc/bus/usb /proc/bus/usb usbfs rw 0 0
/dev/hdc /mnt iso9660 ro 0 0
/proc /proc proc rw 0 0
/sys /sys sysfs rw 0 0

I shall definitely try the knoppix source and try to figure out how they do it.

Thanks,
-=Srijan
 
Old 08-28-2010, 12:02 PM   #9
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 4,202

Rep: Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642
i think i am in territory that mite be out of my comprehension. (the part i cant get beyond is chroot /mnt/boot -- to me it seems like you are chroot-ing to a read-only place ?)

it mite help if you demonstrate the error you are getting while trying to use something like touch.
Code:
[schneidz@hyper ~]$ ll /mnt/cdrom
total 5
-r-xr-xr-x. 1 root root   46 Nov  2  2004 autorun.inf
dr-xr-xr-x. 1 root root 2048 Nov 17  2007 i386
dr-xr-xr-x. 1 root root 2048 Nov 17  2007 programs
-r-xr-xr-x. 1 root root    0 Nov 17  2007 win51ic
-r-xr-xr-x. 1 root root    0 Nov 17  2007 win51ic.sp2
[schneidz@hyper ~]$ touch /mnt/cdrom/hello.test
touch: cannot touch `/mnt/cdrom/hello.test': Read-only file system

Last edited by schneidz; 08-28-2010 at 12:08 PM.
 
Old 08-29-2010, 04:11 AM   #10
ceazar123
LQ Newbie
 
Registered: Jun 2009
Location: India
Distribution: CentOS
Posts: 15

Original Poster
Rep: Reputation: 0
Hi Schneidz,

Yes you are right, I am chroot-ing to the read only file system on the cd-rom. I just tried to touch /var/log/messages and I get the same message.

-bash-3.2# touch /var/log/messages
touch: cannot touch `/var/log/messages': Read-only file system

This is right as I am chroot-ing to the iso9660 file system, which is read only. Can I somehow mount the cd-rom, then chroot to it and then after that can I somehow make the /var, /proc and /dev directories as read write?

Thanks,
-=Srijan
 
Old 08-29-2010, 10:56 AM   #11
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 4,202

Rep: Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642
^ maybe you can create 3 ram-disks and create mount points for them in your iso.
 
Old 08-29-2010, 11:57 AM   #12
ceazar123
LQ Newbie
 
Registered: Jun 2009
Location: India
Distribution: CentOS
Posts: 15

Original Poster
Rep: Reputation: 0
Hi Schneidz,

Yeah that works, I tried that earlier. After chroot-ing in, I did a "mount -t tmpfs tmpfs /var", thereafter I was able to get /var as read write. However, just a small glitch. As soon as I mount /var as tmpfs, it empties the entire contents of that directory. Then I have to recreate each and every file in /var. This was just an example....would I have to do the same for /var, /tmp/ as well?

Thanks and Regards,
-=Srijan
 
Old 08-30-2010, 08:20 AM   #13
ceazar123
LQ Newbie
 
Registered: Jun 2009
Location: India
Distribution: CentOS
Posts: 15

Original Poster
Rep: Reputation: 0
I did a little more research on the iso image that I have created.

When I power on the iso image, the kernel boots ups and runs the initrd image. This is the initial root file system that boots prior to the real root file system. Till this time it accesses the RAM and boots off it. Here if I do a df -h, I can see the /dev/shm file system mounted on /dev/shm. This tells me that it is being accessed from the RAM.

Now if I do a fdisk /dev/hda, I can see my hard drive. So I partitioned hda1 and set it as a boot device.

After that I mount my cd-rom (/dev/hdc) to the mount point /mnt. Till this time I can see my hard drive. After that as soon as I do a chroot to /mnt, I can see my original file system that was in my CentOS Server. However, I can not do any modifications as iso9660 is a read only file system. Now here, I can no longer view my hard drive. A fdisk -l comes up with nothing.

Can I get my mounted file system to see the hard drive and may be copy the files to it and then I can remount them as 'rw' and access them.

Thanks and Regards,
-=Srijan

Last edited by ceazar123; 08-30-2010 at 09:52 AM.
 
Old 08-31-2010, 10:31 AM   #14
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 4,202

Rep: Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642Reputation: 642
Quote:
Originally Posted by ceazar123 View Post
...Now here, I can no longer view my hard drive. A fdisk -l comes up with nothing.

Can I get my mounted file system to see the hard drive and may be copy the files to it and then I can remount them as 'rw' and access them.
i dont have much experience with chroot but i dont understand how your hard drive can physically disappear after a chroot.

are you able to exit your chroot jail and see the hd listed in fdisk -l ?
 
Old 09-01-2010, 03:16 AM   #15
ceazar123
LQ Newbie
 
Registered: Jun 2009
Location: India
Distribution: CentOS
Posts: 15

Original Poster
Rep: Reputation: 0
I got it to work....:-), though there are some rough edges, which I shall try to smoothen.

I already had the initrd image booting from the RAM, that gave me the busybox standalone shell. From this shell, I first mounted my hard drive to /root. Formatted it and changed the file system. Then I mounted my cd-rom to /mnt, which was after all a read only file system. Then I copied the contents of the /mnt to /root. Then I chroot-ed, into /root and that gave me a read write environment. So it's done.

The only thing that needs to be done now is that after chroot-ing in /root, I need to run /sbin/init....which is not happening as of now. As a workaround I have create a bash script, that manually starts the processes I need. As it is a Firewall that I have made, I just start ssh, iptables, snort_inline, zebra...to name a few.

Thanks and Regards,
-=Srijan
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Read Write access to a iso9660 filesystem..mount a .iso image as read write ceazar123 Linux - General 2 08-26-2010 04:32 PM
Making a iso filesystem read/write Korupt Linux - General 5 03-31-2009 10:13 PM
Mount ISO with read/write access the-yikes Slackware 3 08-06-2007 09:26 PM
Diskless node cant mount root NFS filesystem for read/write leontini Linux - Networking 0 01-31-2007 02:03 AM
Mount ISO Read/Write Johnsernickle Linux - Software 4 06-03-2005 04:19 PM


All times are GMT -5. The time now is 05:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration