File programming in Linux (IV)

Source: Internet
Author: User

Install a file system for Linux File Programming

Preface:

Maybe we have two Linux operating systems and XP, so we can generally access files under XP in Linux, but we cannot access Linux under XP, why?

 

 

1. Install the File System

 

1. because ext2/ext3 is a standard file system in Linux, the system regards the disk partition of the ext2 file system as the root file system of the system. The file system other than ext2 (such as the FAT32 File System of window) it is installed in a directory under the root file system and becomes a branch in the tree structure of the system. Install a file system using the mount command.
2. Mount the top-level directory of a file system to the subdirectory of another file system to make them a whole called "Mount )". This subdirectory is called "mount point )".

3. File System creation example
Step 1: Create an initialized file (use the DD command to create a file of the specified size (use/dev/zero as the source to copy the file)
Dd If =/dev/Zero of = tiger BS = 1 k count = 10000

Process instance:

Think @ Ubuntu :~ $ Dd If =/dev/Zero of = tiger BS = 1 k count = 10000
Recorded 10000 + 0 reads
Records 10000 + 0 writes
10240000 bytes (10 MB) Copied, 0.0890382 seconds, 115 MB/second

 

(If you are not familiar with or interested in DD commands, refer to here)

Tiger-John note:

Copy the/dev/zero input file to the tiger output file. The size of the input/output block is 1 K, and a total of 10000 parts are copied.

Now we have created a 10 MB tiger file.

Step 2: Use the losetup command to associate a cyclic device with this file to make it look like a block device, rather than a regular file in the file system. (Use super permissions at this time)

Sudo losetup/dev/loop0 Tiger

Process example:

Think @ Ubuntu :~ $ Sudo losetup/dev/loop0 Tiger
[Sudo] password for think:
Losetup:/dev/loop0: device is busy

Tiger-John note:

When sudo losetup/dev/loop0 is used, the system prompts the following error: losetup:/dev/loop0: device is busy.

It indicates that a device is using a loopback device. We can use/dev/loop1 or/dev/loop2 to replace/dev/loop0 until there is an idle loopback device.

So we need to run the sudo losetup/dev/loop1tiger command and try again.

Process example:

Think @ Ubuntu :~ $ Sudo losetup/dev/loop1 Tiger
[Sudo] password for think

If no error is displayed, the operation is successful. At this time, the tiger file is now available as a block device (represented by/dev/loop1)

Step 3: Use mke2fs to create a file system on this device. This command creates a new ext2 File System of the specified size.

Mke2fs-C/dev/loop1 10000

Indicates that a 10 MB ext2 file system is created on the/dev/loop0 device.

Process example:

Think @ Ubuntu :~ $ Sudo mke2fs-C/dev/loop1 10000
[Sudo] password for think:
Mke2fs 1.41.11 (14-Mar-2010)

Step 4: Use the mount command to install the tiger file represented by the cyclic device (/dev/loop1) to the installation point/mnt/point1. Note that the file system type is ext2.

Mkdir/mnt/point1 indicates: Create an installation point
Mount-T ext2/dev/loop1/mnt/point1: Install the ext2 File System on the Installation Point.

Process example:

Think @ Ubuntu :~ $ Sudo mkdir/mnt/point1
Think @ Ubuntu :~ $ Mount-T ext2/dev/loop1/mnt/point1
Mount: only the root user can perform this operation.

Think @ Ubuntu :~ $ Su

Root @ Ubuntu:/home/think # Mount-T ext2/dev/loop1/mnt/point1

Tiger-John note:

The Mount operation can only be performed with the root permission. Therefore, we use the command: su to switch to the root user.

Step 5: After installation, you can use this installation point as a new file system. For example, you can use the LS command to view the file system.

Process instance:

Root @ Ubuntu:/home/think # ls/mnt/point1
Lost + found
Tiger-John note:

Lost + found indicates the default file directory in the New File System

The next file system is installed on Linux.

So how can I uninstall it?

Step 6: run the following command:Umount/mnt/VFS and Losetup-D/dev/loop0 to uninstall the file system we just loaded.

Process instance:

Root @ Ubuntu:/home/think # umount/mnt/point1
Root @ Ubuntu:/home/think # losetup-D/dev/loop1
Root @ Ubuntu:/home/think # ls/mnt/point1
Root @ Ubuntu:/home/think #

At this time, we can no longer see our file system through ls/mnt/pont1. It indicates that the uninstall is successful.

Tiger-John note:

From the above learning, we learned to use shell commands to mount and detach a file system. Do you have any questions? How is the system implemented when we use these shell commands? If you are interested, come here to see the http://blog.csdn.net/tigerjb/archive/2010/11/17/6015530.aspx


 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.