Several useful device files in the CentOS System

Source: Internet
Author: User

As we all know, linux devices are very special. The system always reads the device in the same way, and the difference between devices is done by the device driver. Because of this, it is very easy to manage devices. Linux also provides virtual device files, that is, devices with no actual physical hardware. They are often used in practical work and learning.

(1)-the first thing we will talk about is loop device and loop device. What is this? Is to simulate the file into a device, and then you can do the relevant operations like the actual device, is everyone familiar with the mounting disc mirror, such as mounting CentOS-5.2-i386-bin-DVD.iso this, input in SHELL and use ls to view its content

[root@xx ~]# mount -o loop /mnt/iso/CentOS-5.2-i386-bin-DVD/CentOS-5.2-i386-bin-DVD.iso /media
[root@xx ~]# ls /media -l

Total 462

Drwxr-xr-x 2 root 397312 06-19 23:23 CentOS
-Rw-r-7 root 212 06-15 06:32 EULA
-Rw-r-7 root 18009 06-15 06:32 GPL
Drwxr-xr-x 4 root 2048 06-19 23:22 images
Drwxr-xr-x 2 root 2048 06-19 isolinux (omitted below)

How many loop devices are in a system? Let's take a look.

[root@xx ~]# ls /dev |grep ^loop
loop0
loop1
loop2
loop3
loop4
loop5
loop6
loop7

In general, there are so many images in a system. Of course you can add them on your own. Let's see which loop device is used for the image you just hung up.

[root@xx ~]# losetup -a
/Dev/loop0: [0805]: 1245190 (/mnt/iso/CentOS-5.2-i386-bin-DVD/CentOS-5.2-i386-bin-DVD.iso)

(2)/dev/zero: What is this device doing? It outputs a byte every time it reads it. Now it is used as a 10 m data file, then you can run the file command to view

[root@xx ~]# dd if=/dev/zero of=hd.img bs=1k count=10000
10000+0 records in
10000+0 records out
10240000 bytes (10 MB) copied, 0.0853896 seconds, 120 MB/s
[root@xx ~]# file hd.img
hd.img: data

The file command hd. img is a data file. Now loop device is used to mount it into a virtual hard disk.

losetup /dev/loop1 hd.img

[root@xx ~]# losetup -a
/dev/loop0: [0805]:1245190 (/mnt/iso/CentOS-5.2-i386-bin-DVD/CentOS-5.2-i386-bin-DVD.iso)
/dev/loop1: [fd00]:2586037 (hd.img)

We know that hd. img corresponds to loop1, and CentOS-5.2-i386-bin-DVD/CentOS-5.2-i386-bin-DVD.iso corresponds to loop0,

Now we can operate on hd. img through/dev/loop1, which is like a real device, which can be partitioned, created file system, etc.

[Root @ xx ~] # Fdisk/dev/loop1
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
Until you decide to write them. After that, of course, the previous
Content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w (rite)

Command (m for help ):

Partition with fdisk, create a file system, and view the attributes of hd. img with file.

[Root @ xx ~] # Mkfs-t ext2/dev/loop1
Mke2fs 1.39 (29-may-2006)
Filesystem label =
OS type: Linux
Block size = 1024 (log = 0)
Fragment size = 1024 (log = 0)
2512 inodes, 10000 blocks
500 blocks (5.00%) reserved for the super user
First data block = 1
Maximum filesystem blocks = 10485760
2 block groups
8192 blocks per group, 8192 fragments per group
1256 inodes per group
Superblock backups stored on blocks:
8193

Writing inode tables: done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first. Use tune2fs-c or-I to override.
[Root @ xx ~] # File hd. img
Hd. img: Linux rev 1.0 ext2 filesystem data

You can use loop device to learn LVM, RAID, and loop device to create multiple virtual hard disks.

(3)/dev/null

This will be known when learning SHELL programming. All the information sent to this device will become none. By using redirection, you can delete all the information that does not need to be displayed in the SHELL window.

Use cat to display the content of the c. c file

[Root @ xx ~] # Cat c. c
Main ()
{}

Then, redirect it to/dev/null and find that nothing will appear in the SHELL window.
[Root @ xx ~] # Cat c. c>/dev/null
[Root @ xx ~] #


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.