Disque virtuel

Disque virtuel - Linux et OS Alternatifs

Marsh Posté le 07-01-2002 à 01:41:12    

Voilà, j'aimerais optimiser ma linux box (machine dédiée sous linux qui gère et partage le net sur mon réseau local), en la rendant silencieuse. L'idée est de virer le disque dur, qui est occupé à 500 MO environ. Voici le principe de la chose :

  • créer une image disque de mon disque dur actuel (ghost par exemple)
  • virer le disque dur et poser une barette de 512 MO de ram
  • réaliser un cd bootable qui créerait dans la ram un disque virtuel, qui y décompresserait mon image ghost, et qui booterait dessus
  • dans le bios, déclarer le cd en tant que lecteur de boot par défaut (bien que normalement cette machine ne soit jamais rebootée), et laisser le cd en permanence dans le lecteur


Outre l'intérêt de la chose (PC silencieux), c'est surtout la faisabilité d'un tel projet qui m'interesse. Est-ce possible, et y-a t-il des travaux qui ont été faits dans ce sens ?
 
Je pense que c'est sur ce principe que fonctionnent les mini-distributions qui tiennent sur une disquette (ex : LOAF), ce qui me laisse penser que ca doit être à peu près la même chose avec un cd.

Reply

Marsh Posté le 07-01-2002 à 01:41:12   

Reply

Marsh Posté le 07-01-2002 à 09:54:47    

intéresse-toi aux "ramdisk" (typiquement le faux disk-dur en mémoire) et à la possiblité de monter une iso dans l'arborescence (certainement en lecture seule par contre :/ )
 
c'est très certainement faisable.
 
si cette machine ne sert qu'au partage de connexion, on s'en sort très bien avec des mini-distros.
 
Sur le Ramdisk

Citation :

Using the RAM disk block device with Linux
------------------------------------------
 
Contents:
 
 1) Overview
 2) Kernel Command Line Parameters
 3) Using "rdev -r" With New Kernels
 4) An Example of Creating a Compressed RAM Disk  
 
 
1) Overview
-----------
 
As of kernel v1.3.48, the RAM disk driver was substantially changed.
 
The older versions would grab a chunk of memory off the top before
handing the remainder to the kernel at boot time. Thus a size parameter
had to be specified via "ramdisk=1440" or "rdev -r /dev/fd0 1440" so
that the driver knew how much memory to grab.
 
Now the RAM disk dynamically grows as more space is required. It does
this by using RAM from the buffer cache. The driver marks the buffers
it is using with a new "BH_Protected" flag so that the kernel does  
not try to reuse them later. This means that the old size parameter
is no longer used, new command line parameters exist, and the behavior
of the "rdev -r" or "ramsize" (usually a symbolic link to "rdev" )
command has changed.
 
Also, the new RAM disk supports up to 16 RAM disks out of the box, and can
be reconfigured in rd.c to support up to 255 RAM disks.  To use multiple
RAM disk support with your system, run 'mknod /dev/ramX b 1 X' and chmod
(to change its permissions) it to your liking.  The default /dev/ram(disk)
uses minor #1, so start with ram2 and go from there.
 
The old "ramdisk=<ram_size>" has been changed to "ramdisk_size=<ram_size>"
to make it clearer.  The original "ramdisk=<ram_size>" has been kept around
for compatibility reasons, but it will probably be removed in 2.1.x.
 
The new RAM disk also has the ability to load compressed RAM disk images,
allowing one to squeeze more programs onto an average installation or  
rescue floppy disk.
 
Notes: You may have "/dev/ram" or "/dev/ramdisk" or both. They are
equivalent from the standpoint of this document. Also, the new RAM disk
is a config option. When running "make config", make sure you enable
RAM disk support for the kernel with which you intend to use the RAM disk.
 
 
2) Kernel Command Line Parameters
---------------------------------
 
 ramdisk_start=NNN
 =================
 
To allow a kernel image to reside on a floppy disk along with a compressed
RAM disk image, the "ramdisk_start=<offset>" command was added. The kernel
can't be included into the compressed RAM disk filesystem image, because
it needs to be stored starting at block zero so that the BIOS can load the  
boot sector and then the kernel can bootstrap itself to get going.
 
Note: If you are using an uncompressed RAM disk image, then the kernel can
be a part of the filesystem image that is being loaded into the RAM disk,
and the floppy can be booted with LILO, or the two can be separate as
is done for the compressed images.
 
If you are using a two-disk boot/root setup (kernel on #1, RAM disk image
on #2) then the RAM disk would start at block zero, and an offset of
zero would be used. Since this is the default value, you would not need
to actually use the command at all.
 
If instead, you have a "zImage" of about 350 kB, and a "fs_image.gz" of
say about 1 MB, and you want them both on the same disk, then you
would use an offset. If you stored the "fs_image.gz" onto the floppy
starting at an offset of 400 kB, you would use "ramdisk_start=400".
 
 
 load_ramdisk=N
 ==============
 
This parameter tells the kernel whether it is to try to load a
RAM disk image or not. Specifying "load_ramdisk=1" will tell the
kernel to load a floppy into the RAM disk. The default value is
zero, meaning that the kernel should not try to load a RAM disk.
 
 
 prompt_ramdisk=N
 ================
 
This parameter tells the kernel whether or not to give you a prompt
asking you to insert the floppy containing the RAM disk image. In
a single floppy configuration the RAM disk image is on the same floppy
as the kernel that just finished loading/booting and so a prompt
is not needed. In this case one can use "prompt_ramdisk=0". In a
two floppy configuration, you will need the chance to switch disks,
and thus "prompt_ramdisk=1" can be used. Since this is the default  
value, it doesn't really need to be specified.
 
 ramdisk_size=N
 ==============
 
This parameter tells the RAM disk driver to set up RAM disks of N k size.  The
default is 4096 (4 MB).  
 
3) Using "rdev -r" With New Kernels
-----------------------------------
 
The usage of the word (two bytes) that "rdev -r" sets in the kernel image
has changed. The low 11 bits (0 -> 10) specify an offset (in 1 k blocks)  
of up to 2 MB (2^11) of where to find the RAM disk (this used to be the  
size). Bit 14 indicates that a RAM disk is to be loaded, and bit 15
indicates whether a prompt/wait sequence is to be given before trying
to read the RAM disk. Since the RAM disk dynamically grows as data is
being written into it, a size field is no longer required. Bits 11
to 13 are not currently used and may as well be zero. These numbers
are no magical secrets, as seen below:
 
./arch/i386/kernel/setup.c:#define RAMDISK_IMAGE_START_MASK     0x07FF
./arch/i386/kernel/setup.c:#define RAMDISK_PROMPT_FLAG          0x8000
./arch/i386/kernel/setup.c:#define RAMDISK_LOAD_FLAG            0x4000
 
Consider a typical two floppy disk setup, where you will have the  
kernel on disk one, and have already put a RAM disk image onto disk #2.
 
Hence you want to set bits 0 to 13 as 0, meaning that your RAM disk
starts at an offset of 0 kB from the beginning of the floppy.
The command line equivalent is: "ramdisk_start=0"
 
You want bit 14 as one, indicating that a RAM disk is to be loaded.
The command line equivalent is: "load_ramdisk=1"
 
You want bit 15 as one, indicating that you want a prompt/keypress
sequence so that you have a chance to switch floppy disks.
The command line equivalent is: "prompt_ramdisk=1"
 
Putting that together gives 2^15 + 2^14 + 0 = 49152 for an rdev word.
So to create disk one of the set, you would do:
 
 /usr/src/linux# cat arch/i386/boot/zImage > /dev/fd0
 /usr/src/linux# rdev /dev/fd0 /dev/fd0
 /usr/src/linux# rdev -r /dev/fd0 49152
 
If you make a boot disk that has LILO, then for the above, you would use:
 append = "ramdisk_start=0 load_ramdisk=1 prompt_ramdisk=1"
Since the default start = 0 and the default prompt = 1, you could use:
 append = "load_ramdisk=1"
 
 
4) An Example of Creating a Compressed RAM Disk  
----------------------------------------------
 
To create a RAM disk image, you will need a spare block device to
construct it on. This can be the RAM disk device itself, or an
unused disk partition (such as an unmounted swap partition). For this  
example, we will use the RAM disk device, "/dev/ram".
 
Note: This technique should not be done on a machine with less than 8 MB
of RAM. If using a spare disk partition instead of /dev/ram, then this
restriction does not apply.
 
a) Decide on the RAM disk size that you want. Say 2 MB for this example.
   Create it by writing to the RAM disk device. (This step is not currently
   required, but may be in the future.) It is wise to zero out the
   area (esp. for disks) so that maximal compression is achieved for
   the unused blocks of the image that you are about to create.
 
 dd if=/dev/zero of=/dev/ram bs=1k count=2048
 
b) Make a filesystem on it. Say ext2fs for this example.
 
 mke2fs -vm0 /dev/ram 2048
 
c) Mount it, copy the files you want to it (eg: /etc/* /dev/* ...)
   and unmount it again.
 
d) Compress the contents of the RAM disk. The level of compression
   will be approximately 50% of the space used by the files. Unused
   space on the RAM disk will compress to almost nothing.
 
 dd if=/dev/ram bs=1k count=2048 | gzip -v9 > /tmp/ram_image.gz
 
e) Put the kernel onto the floppy
 
 dd if=zImage of=/dev/fd0 bs=1k
 
f) Put the RAM disk image onto the floppy, after the kernel. Use an offset
   that is slightly larger than the kernel, so that you can put another
   (possibly larger) kernel onto the same floppy later without overlapping
   the RAM disk image. An offset of 400 kB for kernels about 350 kB in
   size would be reasonable. Make sure offset+size of ram_image.gz is
   not larger than the total space on your floppy (usually 1440 kB).
 
 dd if=/tmp/ram_image.gz of=/dev/fd0 bs=1k seek=400
 
g) Use "rdev" to set the boot device, RAM disk offset, prompt flag, etc.
   For prompt_ramdisk=1, load_ramdisk=1, ramdisk_start=400, one would
   have 2^15 + 2^14 + 400 = 49552.
 
 rdev /dev/fd0 /dev/fd0
 rdev -r /dev/fd0 49552
 
That is it. You now have your boot/root compressed RAM disk floppy. Some
users may wish to combine steps (d) and (f) by using a pipe.
 
--------------------------------------------------------------------------

Reply

Marsh Posté le 07-01-2002 à 10:28:41    

Intéresse toi aussi au projet Demolinux (http://www.demolinux.org ) qui crée un système complet à partir d'un CD bootable.
C'est tout-à-fait possible, et il n'y a pas besoin de 500 Mo pour faire ça (l'idée de copier l'image ghost en RAMdisk et de booter dessus, j'y crois moyen quand même).
Cherche les diskless howto.

Reply

Marsh Posté le 07-01-2002 à 11:28:10    

Merci pour vos avis. Comme la nuit porte conseil, j'ai eu de nouvelles idées pour la réalisation de ce projet : le cd bootable charge un bon vieux ms-dos, qui s'occupe de créer le disque virtuel avec RamDrive, puis décompression de l'image ghost, et lancement du système avec loadlin. Par contre je me demande si RamDrive sait créer autre chose qu'un disque avec une partition fat32. Je vais faire des essais.

Citation :

Intéresse toi aussi au projet Demolinux (http://www.demolinux.org ) qui crée un système complet à partir d'un CD bootable.


Le problème c'est que mon modem (Bewan adsl pci st) est assez chiant à configurer, et que pour l'instant je n'y arrive que sous Mandrake 8.1. L'idéal évidemment serait de pouvoir générer un demolinux personnalisé à partir de mon installation actuelle, mais je ne crois pas que ce soit possible (sujet évoqué dans le paragraphe 4.1 de la faq, mais apparemment c'est pas simple pour l'instant). Je vais quand même récupérer et graver la  pour voir de quoi il en retourne exactement.

Citation :

intéresse-toi aux "ramdisk" (typiquement le faux disk-dur en mémoire) et à la possiblité de monter une iso dans l'arborescence (certainement en lecture seule par contre  )  
 
c'est très certainement faisable.  
 
si cette machine ne sert qu'au partage de connexion, on s'en sort très bien avec des mini-distros.


Aucune minidistrib ne gère mon modem (pour l'instant seules Mandrake 8.1 et Redhat 7.2 le supportent après moults efforts -> merci le support tech de Bewan).
 
Merci pour tes infos sur les ramdisks. La partie qui m'interesse est bien sur :

Citation :

Note: If you are using an uncompressed RAM disk image, then the kernel can  
be a part of the filesystem image that is being loaded into the RAM disk,  
and the floppy can be booted with LILO, or the two can be separate as  
is done for the compressed images.


Mais j'ai peur que ce soit assez chaud à mettre en place.
Je vais faire quelques tests dans la semaine.

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed