Linux raw is a raw data format, which means "naked device" in Linux, also called naked partition and raw partition; linux raw is a data format that has not been formatted and cannot be read by Unix/Linux through the file system. The special character device obtained; the raw device can be bound to a partition or a disk.
#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.
What is the format of linux raw?
Original data format.
Linux raw device detailed explanation
Naked device overview
Bare device: also called raw partition (raw partition), it is a type that has not been formatted , a special character device that is not read by Unix/Linux through the file system. A raw device can be bound to a partition or a disk.
Character device: Reading and writing character devices do not need to go through the OS buffer. It cannot be mounted by the file system.
Block device: Reading and writing to the block device need to go through the OS buffer, which can be mounted to the file system.
This is related to the Linux version. In the old version, there can only be a maximum of 256 bare devices. Under Linux 4, you can bind 81Array2 bare devices. However, under Linux, there can only be a maximum of 255 partitions. Therefore, if you use a raw device to bind a partition, you can only bind a maximum of 255 raw devices. If you are using lvm, there is no such restriction.
A single disk can have up to 15 partitions under Linux. 3 primary partitions, 1 extended partition and 11 logical partitions.
The recommended partitioning method is: first divide into 3 primary partitions, the fourth partition is an extended partition, and then divide the extended partition into 11 logical partitions.
Note that raw devices should not be bound to extended partitions.
If you need to use bare devices under Linux, you need to bind them manually, but not under Unix.
Because every block device in Unix has a corresponding character device for unbuffered I/O, this is its corresponding raw device. Rawio in Linux implements a set of unbound (unbound) raw devices /dev/rawN or /dev/raw/rawN and a control device /dev/rawct to bind them to block devices. So when you need to use a raw device, you need to match it with a real block device. This step actually completes the automatic mapping of a non-cached character device in Unix.
major and minor device number
In unix/linux systems, everything is a file. All hard disks, floppy disks, keyboards and other devices are represented by files, corresponding to files under /dev. For applications, these device files can be opened, closed, read and written like ordinary files. However, such file names, such as /dev/sda and /dev/raw/raw1, are all user space names, and the OS Kernel does not know what this name refers to. In the kernel space, devices are distinguished by major and minor device numbers.
major device number can be regarded as a device driver. Devices managed by the same device driver have the same major device number. This number is actually the index of the device driver table in Kernel, which stores different devices. driver. The minor device number is used to represent the specific device being accessed. That is to say, Kernel finds the device driver based on the major device number, and then obtains the device location and other attributes from the minor device number. All these major device numbers are pre-allocated. Details can be viewed at http://www.lanana.org/docs/device-list/devices-2.6.txt.
For example, the raw device is 162 and the scsi block device is 8
/etc/udev/rules.d/60-raw.rules
The configuration of the raw device on the Redhat platform has changed after redhat 5. Before redhat 5, the /etc/sysconfig/rawdevices file was directly configured and the startup and shutdown of raw devices were managed through /etc/init.d/rawdevices. After Redhat 5, the original raw device interface has been cancelled, and redhat 5 is configured through udev rules. To configure, you need to edit the file /etc/udev/rules.d/60-raw.rules.
cat /etc/udev/rules.d/60-raw.rules # Enter raw device bindings here. # # An example would be: # ACTION=="add", KERNEL=="sda", RUN+="/bin/raw /dev/raw/raw1 %N" # to bind /dev/raw/raw1 to /dev/sda, or # ACTION=="add", ENV{MAJOR}=="8", ENV{MINOR}=="1", RUN+="/bin/raw /dev/raw/raw2 %M %m" # to bind /dev/raw/raw2 to the device with major 8, minor 1.
where
ACTION=="add", KERNEL="<device name>", RUN+="raw /dev/raw/rawX %N"
configure the device name, replace
Major/minor number:
ACTION=="add", ENV{MAJOR}="A", ENV{MINOR}="B", RUN+="raw /dev/raw/rawX %M %m"
"A" and "B" are the major/minor numbers of the device, and X is the raw device number used by the system.
My personal understanding of the process of managing raw in redhat is: in redhat 5, raw devices are managed through udev, and udev identifies raw devices through MAJOR and MINOR. Therefore, the device number and the raw device number need to be bound, and the major device number and minor device number can be specified by yourself or automatically assigned by the system. According to the example of raw.rule in red hat's official documentation, it is said that KERNEL==.. or ENV{MAJOR}... only needs to be configured arbitrarily. However, some netizens have tested and verified that both must be configured at the same time. .
Configure /etc/udev/rules.d/60-raw.rules file
Check the disk partition situation
# fdisk -l /dev/sdb Disk /dev/sdb: 4880 MB, 4880072704 bytes 255 heads, 63 sectors/track, 593 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 25 200781 83 Linux /dev/sdb2 26 50 200812+ 83 Linux
Configure /etc/udev/rules.d/60 -raw.rules file
# grep -v ^# /etc/udev/rules.d/60-raw.rules ACTION=="add", KERNEL=="sdb1", RUN+="/bin/raw /dev/raw/raw1 %N" ACTION=="add", KERNEL=="sdb2", RUN+="/bin/raw /dev/raw/raw2 %N" ACTION=="add", ENV{MAJOR}=="3", ENV{MINOR}=="2", RUN+="/bin/raw /dev/raw/raw1 %M %m" ACTION=="add", ENV{MAJOR}=="7", ENV{MINOR}=="2", RUN+="/bin/raw /dev/raw/raw2 %M %m"
Start the raw device
# start_udev Starting udev: [ OK ]
View the configuration
# raw -qa /dev/raw/raw1: bound to major 8, minor 17 /dev/raw/raw2: bound to major 8, minor 18
I don’t know why the main device number and the complex device number are not the same as mine/ etc/udev/rules.d/60-raw.rules is the same as specified in etc/udev/rules.d/60-raw.rules. Readers who want to know more about it will be informed that the system kernel information is as follows
# uname -a Linux rac1 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:54 EDT 2009 i686 i686 i386 GNU/Linux # cat /etc/redhat-release Red Hat Enterprise Linux Server release 5.4 (Tikanga)
You can specify the major device number and complex device number in the following way
# raw /dev/raw/raw1 1 1 /dev/raw/raw1: bound to major 1, minor 1 raw /dev/raw/raw[n] /dev/xxx
其中n的范围是0-8191。raw目录不存在的话会被自动创建。执行这个命令,就会在/dev/raw下生成一个对应的raw[n]文件用命令方式绑定裸设备在系统重启后会失效。
删除裸设备
# raw /dev/raw/raw2 0 0 /dev/raw/raw2: bound to major 0, minor 0 # raw -qa /dev/raw/raw1: bound to major 1, minor 1
以上设置必须同时修改/etc/udev/rules.d/60-raw.rules才能保证重启后生效,否则重启后系统会重新读取/etc/udev/rules.d/60-raw.rules
如需设置raw设备的用户和权限信息,可在/etc/udev/rules.d/60-raw.rules文件里添加如下信息:
ACTION=="add", KERNEL=="raw1", OWNER="dave", GROUP="tianlesoftware", MODE="660"
如果有多个raw设备,可以写成:
ACTION=="add", KERNEL=="raw[1-4]", OWNER="dave", GROUP="tianlesoftware", MODE="660" #chown oracle:oinstall /dev/raw/raw[1-4] #chmod 775 /dev/raw/raw[1-4]
注意:在内核2.6.9-89.5AXS2之前使用/etc/sysconfig/rawdevices和/etc/udev/permissions.d/50-udev.permissions进行raw设备的配置和权限管理。在内核 2.6.18-128.7AXS3以后则使用了本文介绍的/etc/udev/rules.d/60-raw.rules进行raw设备的管理
确定裸设备的大小
比较笨的办法是,找出看裸设备对应的是那个实际的块设备,然后用fdisk -l /dev/[h,s]dXN看那个块设备的大小就好了。比较简单的办法是用blockdev命令来计算,如:
#blockdev --getsize /dev/raw/raw1
11718750
11718750表示有多少OS BLIOCK。
一般一个OS BLOCK大小是512字节,所以11718750*512/1024/1024= 5722(m) 就是裸设备的大小。
使用裸设备作为oracle的数据文件的注意事项
1、一个裸设备只能放置一个数据文件
2、数据文件的大小不能超过裸设备的大小
如果是日志文件,则裸设备最大可用大小=裸设备对应分区大小 - 1 * 512 (保留一个redo lock)
如果是数据文件,则裸设备最大可用大小=裸设备对应分区大小 - 2 * db_block_size(保留两个block)
为了简单起见,对所有的文件设置称比裸设备小1M即可。
3、数据文件最好不要设置称自动扩展,如果设置称自动扩展,一定要把maxsize设置设置为比裸设备小
4、linux下oracle不能直接把逻辑卷作为裸设备,也要进行绑定。unix下就不需要。
相关推荐:《Linux视频教程》
The above is the detailed content of What is the format of linux raw?. For more information, please follow other related articles on the PHP Chinese website!