Linux to create special device files

Source: Internet
Author: User

The devices under Linux are very special, and the system always reads the device in one way, and the difference between the devices is done by the device driver. Because of this, it is very easy to manage the equipment. Linux also provides virtual device files, that is, no actual physical hardware corresponding to the device, they are often used in the actual work of learning, are described as follows

(a)-the first thing to say is, of course, loopback devices, loop device, what is this? is to simulate the file into a device, and then can be like the actual device to carry out the relevant operation, is familiar with the installation of optical disc mirror, such as Mount Centos-5.2-i386-bin-dvd.iso This, then in the shell input and LS to see its contents

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

[[email protected] ~]# dd If=/dev/zero of=hd.img bs=1k count=10000
10000+0 Records in
10000+0 Records out
10240000 bytes (Ten MB) copied, 0.0853896 seconds, + MB/s
[[email protected] ~]# file hd.img
Hd.img:data

The file command hd.img the data files and now hangs it up as a virtual hard disk with loop device

losetup /dev/loop1 hd.img

/dev/loop0: [0805]:1245190 (/mnt/iso/ Centos-5.2-i386-bin-dvd/centos-5.2-i386-bin-dvd.iso)

The hd.img corresponds to the LOOP1, and Centos-5.2-i386-bin-dvd/centos-5.2-i386-bin-dvd.iso corresponds to the loop0,

Now we can use the/DEV/LOOP1 to operate the hd.img, it is like a real device, you can partition, create file system, etc.

partitioning with Fdisk and then creating the file system:


Second, create the partition: Mkfs-t EXT2/DEV/LOOP1

Three, Mount: Mount-t ext2/dev/loop1/mnt

Four, the solution hangs: umount-l/mnt

Five, uninstall: Losetup-a can see/DEV/LOOP1 is in use, using losetup-d/dev/loop1 to uninstall.




This article is from the "cultivate a Perseverance" blog, please be sure to keep this source http://huangfuligang.blog.51cto.com/9181639/1675424

Linux to create special device files

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.