Revision of disk parameters for Linux check gaps

Source: Internet
Author: User
Tags uuid

Linux Disk parameter revision

File representative device

Under Linux We all know that we can use the corresponding file to represent a device, such as the /dev/sdb1 first partition slot representing the SDB hard drive, which is used major minor to mark the corresponding replacement device.

brw-rw--1 root disk 8, 0 May 20:16/dev/sda
brw-rw--1 root disk 8, 1 May 19:48/dev/sda1
brw-rw--1 roo T disk 8, 10 May 19:48/dev/sda10
brw-rw--1 root disk 8, 11 May 19:48/dev/sda11
brw-rw--1 root disk 8, 12 May 19:48/dev/sda12
brw-rw--1 root disk 8, 13 May 19:48/dev/sda13
brw-rw--1 root disk 8, 2 May 12 19:48 /dev/sda2
brw-rw--1 root disk 8, 3 May 19:48/dev/sda3
brw-rw--1 root disk 8, 4 May 19:48/dev/sda4
B rw-rw--1 Root Disk 8, 5 May 19:48/dev/sda5
brw-rw--1 root disk 8, 6 May 19:48/dev/sda6
brw-rw--1 root D ISK 8, 7 May 19:48/dev/sda7
brw-rw--1 root disk 8, 8 May 19:48/dev/sda8
brw-rw--1 root disk 8, 9 May 12 1 9:48/DEV/SDA9
[email protected]:/media# ll/dev/sdb*
brw-rw--1 root disk 8, 16 May 20:16/dev/sdb
brw-rw--1 Root disk 8, 17 May 20:25/dev/sdb1
brw-rw--1 root disk 8, 18 May 20:18/dev/sdb2

The Linux kernel is through the corresponding major and minor to understand the corresponding device

Device Name Major Minor
/dev/sdb 8 0-15
/dev/sdba 8 16-31

mknod command
This command is primarily used to create a device file (make block or character special files)
Mknod [OPTION] ... NAME type [MAJOR MINOR]
where the types are mainly:
-B Block blocks device
-C char character device
-P pipe piping Equipment
Use example:

Create a new pipeline file

#mknod pipefile P
#echo This is a test line >> pipefile
# Cat pipefile

Create a new block file

#mknod blockfile B 8

Create a new character file

#mknod charfile C 4

Eventually there will be Three files
brw-r–r–1 root root 8, 100 May 21:15 blockfile
crw-r–r–1 root root 4, 100 May 21:16 charfile
PRW -r–r–1 root root 0 May 21:12 pipefile|

E2label command

Under Linux, each divider can be assigned a corresponding to label mark the divider, which is the C盘D盘 same as under Windows. If the disk divider specifies a label, then the/media directory is mounted under the name of the label, and if no label is specified, it will be mounted under the/media directory with the UUID of the split slot.

Under Linux can be specified by e2label the command to specify the corresponding slot of the label is what, a good thing to specify label is that the label does not change with the disk file name changes, we know that the mount order of disks under Linux determines the file name of the disk, For example, if you mount SATA disk 1, then disk 1 device name is /dev/sda , if you are hanging on SATA disk 2 lag and then Mount Disk 1, then disk 1 disk file is /dev/sdb ... But even if the disk file name is changed, the corresponding divider label will not change.

Use the e2label command:

E2LABEL/DEV/SDB1 "Newlabelname"

TUNE2FS command

TUNE2FS commands are very useful, here are some basic usage
--l equivalent to dumpe2fs-h display the superblock content of the divider slot
---l equivalent to E2label change the label of a separator slot
--j Convert ext2 file format to ext3 file format with log
More specific usage or man, please.

Automatic File system mount

We can change the system by changing the /etc/fstab data below to automatically mount the filesystem each time it is powered on, the following is something inside the/etc/fstab/file:

In this example, the file system is hung under the/home directory, there is no line of information to indicate the automatic mount file system, each item is separated by a space, the specific meaning of each item is:
- File system: The corresponding divider, yes UUID or no label name
- Mountpoint: mount points must be a directory, and the root directory must / take precedence over all file system mounts
- Type: Types of file systems
- Options: File system mount parameters, which are:

arg1 arg2
user nouser can a normal user mount the file system
async sync whether the disk reads and writes asynchronously
auto noauto can be mounted automatically, that is mount-a
RW ro file system is read-only or read-write
suid nosuid
defaults default configuration mode

- Dump: Indicates whether the file system is dump Backup: 0 marked not to do backup, 1 marked daily backup, 2 marked the occasional backup
- pass: with fsck to detect the file system is a problem, 0 mark does not detect, 1 marks the first detection (usually the root directory), 2 indicates the need to detect, only after 1 detection!

Now suppose we need to automatically mount the file system/dev/sdb1 to the/MEDIA/SDB1 directory at boot time, then we need to write under/etc/fstab;
/dev/sdb1 /media/sdb1 ext4 ro 1 2
Next we try to mount -a find that the file system is automatically mounted in read-only form /media/sdb1 under the directory, indicating that we have not written the wrong
Note: If you do not detect whether the new fstab inside the article is written correctly in a hurry to restart, then it is possible to boot can not be successful and into the single-player mode, this time you need mount -n =o remount.rw / to re-mount the root directory, and then we modify the /etc/fstab file

Mount-o Loop

The Mount-o loop option is used to mount a file as a hard disk partition on the system directory, especially if our partition is not reasonable, such as the partition of your root directory is very large, and its partition size is almost full, now you can resume a relatively large file, As a new device hangs on the system, now you have a partition, but this partition is only virtual, there is no corresponding partition slot on the disk to divide the division out of the OH.

Let's take a look at the actual application:

# we create a new directory  cd/tmp && mkdir Hello && cd Hello  #我们从/dev/ The zero file system begins where you copy 512 1M blocks into file1  dd If=/dev/zero of=./file1 bs=1  M count= 512  ll-h file1 #我们得到-rw-r--r--1 root root 512M May 13 2 3:49 File1 Create a new mount point  mkdir file1mountpoint #现在我们尝试挂载file1到file1MountPoint  Mount-o loop file1./file1mountpoint #发现挂载出错了 mount: You must specify the file system type, so we format the file  mkfs-t ext4./file1 #我们再次尝试挂载, found that the mount was successful because the contents of the first file were all 0, and the child was unable to mount a file that was all 0. We need to format this file in order to mount, that is, in the disk area where the file is located superblock inodetable blocktable Those things, mount the time will be read to mount   

Above we are from a device called/ dev/zero copy 512M content into the file, and now we try to put a file system with 100M capacity /dev/sdb1 All copied out into a new file file2 , see how it's going to be mounted again

 #查看那些挂载的目录  Df-l | Greo/dev/sdb1 #我们得到对应的挂载目录/dev/sdb1 99150 5647 88383 7%/media/sdb1   #我们进入到/media/sdb1 See  cd/media/sdb1 && ls; Cd/tmp/hello #我们发现这下面有三个文件 lost+found newfile newfile  dd if=/dev/sdb1 of =./ File2 bs=1  M count=512  && mkdir File2mountpoint #得到文件file2, our file2 size is only 100M, here we will be the/DEV/SDB1 in the contents of all copied out, We don't format this file directly to see if it's OK  mount-o loop/file2./file2mountpoint #没有报错.  Go to the file system and see  CD file2mountpoint && ls #发现里面有三个文件 lost+found NewFile NewFile   

The above file File2 is copied inside the /dev/sdb1 entire disk contents, so file2 inside content is the complete file system content, that is file2 inside the file data is the /dev/sdb1 file system inside all the data, including superBlock , inodeTable , and blockTable so on , so we can directly hang in this file, here can actually do a full backup of the file system

New for Swap partitions

The main function of the swap partition is to move the memory-occupied program to swap in case of insufficient physical memory, so that the physical memory can be used by the required program.
We can create a new swap file system

fdisk /deb/sdbn+2Gt682#改变文件系统id mkswap /dev/sdb6swapon /dev/sdb6

The above is to re-establish a swap partition with the hard disk partition
Create a new swap partition using the file form below

if=/dev/zeroof=./newSwapFile bs=1M count=500Mmkswap ./newSwapFileswapon ./newSwapFile

We can take swapon -s a look at the current number of swaps that are being mounted using
It can also be used swapoff to remove a swap partition that is in use within the system.
You can use the free command to view swap usage in the system (total, usage, remaining)

System ID

Under Linux, each filesystem has a corresponding ID, chewing the mouth. System ID
-Linux Ext4-->system id = 83
-Linux Swap-->system id = 82
-Windows ntfs--> System id = 7

Total Catalog Occupancy
When we execute the command under a directory, the top of the ll -l output will appear with this word 总用量 512032 ,
The total dosage and command of the total amount is du -s very similar, in fact, the total amount here is the directory below the number of block *block size

If you are splitting large hard disks, it is best to use commands parted to split

Revision of disk parameters for Linux check gaps

Related Article

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.