1. modify an existing File System
Set the file system compressed file to ramdisk.gz.
1. Extract # Cd ramdisk.gz directory # Gunzip ramdisk.gz After decompression, obtain the file system image file ramdisk, which overwrites the original compressed file.
2. Image File Mounting The image file must be mounted to view the directories and details in the file system.
# Mkdir/mnt/loop/*/mnt/loop is the directory to which the file system is mounted.
# Mount-o loop ramdisk/mnt/Loop
Operate the file system in the Mount directory/mnt/Loop # Cd/mnt/Loop # Do_whatever_you_want_to_do/* add, delete, or modify file system content as needed
4. Unload the File System Jump out of the/mnt/loop directory; otherwise, the installation cannot be uninstalled, prompting busy
# Directory of CD ramdisk # Umount/mnt/Loop 5. compressed file system # Gzip-V9 ramdisk/* generate the ramdisk.gz compressed file
2. Build your own root file system
1. Create a temporary mount point for the loop device # Mkdir/mnt/Loop 2. Create a temporary file with a size of 15 MB # Dd If =/dev/Zero of =/tmp/loop_tmp BS = 1 k count = 15360
Note that you can create a proper file system based on your needs and change the Count size.
Run the DD command to create a 15360kb file system image stored in/tmp/loop/tmp and initialize it with. Dev/zero. This method is used to initialize the file system. Later, when we use the gzip command to compress the entire image, we will obtain the maximum compression ratio for unused parts of the file system.
3. associate a device file with a temporary file # Losetup/dev/loop0/tmp/loop_tmp
Associate the device file/dev/loop0 with the temporary image file/tmp/loop_tmp./dev/loop0 is a block device.
If "IOCTL: loop_set_fd: the device or resource is busy" is displayed, the/dev/loop0 device also contacts a file and can be viewed by losetup/dev/loop0 and deleted by-D.
4. Format/dev/loop0 as the ext2 file system.
# Mke2fs-M 0/dev/loop0 -M 0 indicates that you do not have to reserve any blocks for the "superuser" on the file system.
The Linux kernel recognizes two types of ramdisk file systems that can be tested directly. They are minix and ext2, and minix is the file system used in earlier Linux versions. It comes from the minix operating system, ext2 has better performance.
5. Attach a virtual disk to a node, MNT, or loop. # Mount-T ext2/dev/loop0/mnt/Loop
6. Run the CP-AF command to copy the required files to the virtual disk. CP-help to view CP usage. CP-Arn... -R indicates copying a directory.
/Bin,/dev,/etc,/lib, Proc,/sbin,/usr are all indispensable directories. We recommend that you keep/tmp,/var, but it can be empty. All directories (such as/home,/mnt,/OPT, And/root) that provide extensible environments for multiple users should be omitted.
When using CP to copy files, we recommend that you copy all the content in the established file system. This is relatively simple and requires no compilation or installation of busybox. Of course, you can do that yourself.
7. Uninstall the file system. The obtained/tmp/loop_tmp is the file system image.
# Directory other than CD/mnt/loop (otherwise, a message indicating that the device cannot be uninstalled and the device is busy)
# Umount/mnt/Loop 8. compress the file system image # Gzip-V9/tmp/loop_tmp>/tftpboot/ramdisk.gz
Ramdisk.gz is generated under/tftpboot, so that a memory file image is generated.
Or if it is only # gzip-V9/tmp/loop_tmp, The loop_tmp.gz file is generated under/tmp.
In the above self-built file system, the first 3rd losetup commands are used to associate the block Device File/dev/loop0 with the temporary file/tmp/loop_tmp, my understanding is that/tmp/loop_tmp must be a block device file. Therefore, use/dev/loop0 to associate with it, And then perform operations on/dev/loop0 and its virtual disk, it indirectly works on the file system image/tmp/loop_tmp.
3. Build your own root file system (different from the second one)
1. Create a temporary mount point for the loop device # Mkdir/mnt/Loop 2. Create a file system image # Dd If =/dev/Zero of =/tmp/loop_tmp BS = 1 k count = 15360
The above two items are the same as those in the second Middle School. 3. mke2fs-F-v-M 0/tmp/loop_tmp
Here, the-F option forces mkefs2 to run on the file. Otherwise, mke2fs will complain that/tmp/loop_tmp is not a block device (as mentioned above, my understanding is that the/tmp/loop_tmp file image must be a block device file, the previous practice is to associate the block Device File/dev/loop0 with it ). -V option indicates that mke2fs should be executed in verbose mode, and-M 0 indicates that it is not necessary to reserve any blocks for "superusers" on the file system, because in embedded systems, mke2fs is usually a single-user system, it makes no sense to reserve blocks for "Super Users.
4. Mount the image file # Munt-o loop/tmp/loop_tmp/mnt/Loop
After mounting, you can operate the file system content under/mnt/loop.
5. CP operations, with 6th records in the second Middle School 6. Uninstall the image file # Umount/mnt/Loop 7. Compress image files # Gzip-V9/tmp/loop_tmp The third method is different from the second method. In the second method, the block Device File/dev/loop0 is associated with the image file/tmp/loop_tmp, then, the/dev/loop0 and Virtual Disks are operated on/ltmp/loop_tmp.
In the third stage, the image file/tmp/loop_tmp is operated directly, and mke2fs-F... Use it as a block device file. |