Strengthen the study of disk management
1. Contrastive memory
mount /dev/sr0 /mnt/cdrom /mnt/cdrom is the mount point
ln -s ../data/f2 /root/f2_link2 /root/f2_link2 is the link file
2. The partition used to be divided by cylinder, and a single cylinder is about 8M
[root@centos6 ~]# fdisk -l
Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0008cf29
Device Boot Start End Blocks Id System
/dev/sda1 * 1 128 1024000 83 Linux
Partition 1 does not end on cylinder boundary. #It can be seen that Centos6 is divided into cylinders, and the size of a single cylinder is about 8M
/dev/sda2 128 6502 51200000 83 Linux
/dev/sda3 6502 7777 10240000 83 Linux
/dev/sda4 7777 13055 42392576 5 Extended
/dev/sda5 7777 8032 2048000 82 Linux swap / Solaris
3. Up to 4 primary partitions, there can be 1 table extended partition, pay attention to the size of the extended partition.
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 2G 0 part
├─sdb2 8:18 0 2G 0 part
├─sdb3 8:19 0 3G 0 part
├─sdb4 8:20 0 1K 0 part
└─sdb5 8:21 0 2G 0 part
4.echo -e 'n \ np \ n \ n \ n + 2G \ nw \ n' | fdisk / dev / sda
fdisk /dev/sdc <<EOF
5. Dumpe2fs /dev/sda2 In centos6, check the block (the smallest unit that stores files) groups, including file system information, and each group has a backup of super blocks
6.tune2fs -l /dev/sda1 View file system information
tune2fs -l /dev/sda1 (dumpe2fs -h/dev/sda2)
Using dumpe2fs /dev/sda1 will produce more block group information than tune2fs -l /dev/sda1
7. The block size supported by the linux file system is 1k 2k 4k
8.mkfs.ext4 /dev/sdb2 -b 1024 specifies the block size
9. Reserve space for root to use mkfs.ext4 /dev/sdb2 -b 1024 -m 0.1 0.1 times the block count, you can set the reserved space size -m option
10. An inode <--> a file --> may occupy multiple blocks, a large file may occupy multiple blocks, inode and file are one-to-one relationship
11.tune2fs -O has_journal /dev/sda2 can add journal function to ext2, after adding it becomes ext3 file system
tune2fs -O ^has_journal /dev/sda2 Change back to ext2 file system after disabling
tune2fs -l View, modify the file system -j (journal) Add the log function, after adding it becomes an ext3 file system
12.mkfs.ext4 uses the volume label to use -L as the mount point directory, which is the same for easy management
13.blkid -U `grep ....| sed`
blkid -U `grep | cut ...`
14.e2label Modify or display the volume label
15.findfs LABEL=/dev/sdb Find device name by volume label
16. Device name (partition name), label name and UUID name can identify a device, but it is safer to use UUID to identify a device, because the device name may change as the device is added or deleted.
17. umount first when fsck is repaired
18.tune2fs -l /dev/sda1 can check whether the disk file system is faulty, such as: Filesystem state: clean The file system is not faulty
Filesystem state: not clean, the file system is faulty There will be a superblock backup in each block group, but not all block groups have a superblock backup
dd if=/dev/zero of=dev/sdb1 bs=20M count=1 Simulate a fault of 20M, and then check the Filesystem state by tune2fs -l /dev/sdb1
19.e2fsck -f forcibly detect the disk, without -f preliminary detection, the detection may be incomplete, using the -f option will detect the whole disk, the speed is slow, you must umount before the detection
20. fsck automatically invokes related tools to detect the xfs file system, and the fsck prompt information can be viewed through the specific command to achieve the detection
21.xfs is not compatible with ext file system
22. The file can be accessed only after it is mounted. The mounted folder is the entry to access the file.
23.1 A mount point (folder) can only be mounted on one partition, an empty folder should be used for the mount point, and multiple folders can be mounted on one device
24. The data is stored on the mounted partition, but the folder is stored on the partition belonging to it
25.cat /etc/mtab automatically updates the mount table as it mounts
26.mount LABEL=/data/sdb2 /data/sdb2
27.mount UUID="e0b2b1fd-38dd-48b4-8e52-9642bb1364b6" /data/sdb2, blkid can view UUID, you can use uuidgen to generate uuid
28.blkid to see if there is a file system
29.mount -r /dev/sdb1 /data/sdb1 read-only mount is read-write mount by default
30.cat /proc/mounts You can only see the hidden mounts by looking at this file. You can also see mount -n ... (Hidden and invisible in centos6) The links point to different
31. Mount the directory using the -B (--bind) option
32.37 mounts trigger checking fsck
33.tune2fs -C(-c) times
34.tune2fs -o acl /dev/sdb1 Add acl function, after remounting, it will take effect and remove the use ^
mount -o acl /dev/sdb1 /data/sdb1
mount -o noacl,remount /dev/sdb1 ... Modify the mount option, use it when umount cannot be used
35.mount -o remount,ro /data/sdb1
36.fuser -v /data/sdb1 View the usage process of the mounted directory (/data/sdb1 is not /dev/sdb1) (lsof /data/sdb1)
fuser -km /data/sdb1 Force kick out of the user to uninstall (use with caution)
37.findmnt /data/sdb1 Check whether the folder is in the mounted state (you can check whether it is mounted when the directory is mounted)
findmnt mount_point|device View mount status
[root@centos7 ~]#findmnt /data/sdb1
TARGET SOURCE FSTYPE OPTIONS
/data/sdb1 /dev/sdb1 ext4 rw,relatime,data=ordered #You can view mount options and file system types
[root@centos7 ~]#findmnt /dev/sdb1
TARGET SOURCE FSTYPE OPTIONS
/data/sdb1 /dev/sdb1 ext4 rw,relatime,data=ordered
find /home to see if home is the mount directory
[root@centos7 ~]#findmnt /home
[root@centos7 ~]#findmnt /bin
[root@centos7 ~]#findmnt /
TARGET SOURCE FSTYPE OPTIONS
/ /dev/sda2 xfs rw,relatime,attr2,inode64,noquota
38. When writing data, put it into the buffer buffer first, and write to the disk when the system is not busy (asynchronous: default)
Synchronization will be directly written to the disk, which is not efficient. When the file is written to the memory from the disk, the data is first written to the memory cache. When the data in the memory is to be written to the disk, the data is first written to the buffer. , so when a disk writes data to another disk, it is disk 1 --> cache cache --> cache buffer --> write to another disk
39.noatime Whether the time of reading the file is updated, it can improve the performance mount -o option
40. The mount option noexece does not allow the execution of executable files, you can use bash *.sh to execute
mount -o remount,noexec ...
41. mknod zero c 1 5 is not -c
dd can pass in data, can use device files
mount -o remount, nodev
dd cannot pass in data and cannot use device files
42. All file attributes are determined by the middle attribute of the mount point where they are located
43.vim has root permission to modify all files, because it has suid permission, use mount -o nosuid to disable
44.mount -o loop mounts the file on the directory, the file simulates the use of the partition
dd if=/dev/zero of=/root/p1 bs=1M count=100
mkfs.ext4 p1
Use blkid p1 to view the file system, but blkid can't view it
mount -o loop /root/p1 /mnt
mount can directly mount files without loop option
45. losetup -a can view the mapping relationship between the mounted /dev/loop0 and the file name (can be viewed in centos6 mount)
46.ls /dev/loop* Up to 8 loop devices, you can create multiple mknod /dev/loop8 b 7 8 (centos6, centos7 unlimited loop devices)
47. losetup /dev/loop8 p2 p2 file establishes a relationship with loop8
48.mount /dev/loop8 ..
49. Add max_loop=100 /boot/grub/grub.conf configuration file to the kernel line, and modify the number of loop devices after restarting
50. Partition mountable folder mountable -B (--bind) file mount (-o loop)
51. Accessing files needs to go through folders, so mount through folders
52. The command mount is a temporary mount, and a permanent mount modifies the configuration file (/etc/fstab)
tune2fs -o acl /dev/sdb1 is the modified source data, on disk
53. Device name, volume label name, UUID name (best) can be (/etc/fstab)
UUID mount point file system defaults (ro, nouser) 1 (backup time, 1 means backup once a day, it needs to be used in conjunction with backup tools, not commonly used, 0 means no backup.) 1 Check the file system integrity order 1 means it is the first Check, 0 means do not check
54.mount -a remounts /etc/fstab, if there is an auto option, you can mount -a to reread the default with the auto option
55. The /etc/fstab file is important and can be considered for backup
56. When MBR partitions, the single largest partition is 2T, because 32 bits are used to represent the number of sectors (2**32=4G, the number of deleted bytes is 512B 4G*512G=2048/1024=2T), and the partition does not exceed 2T , 512 bytes of track 0 sector 0 have special purpose
446 bytes to store the bootloader, 64 bytes to store the partition table, 2 bytes to store whether the partition has been divided (55AA)
57.vim /etc/grub.conf (link file of /boot/grub/grub.conf)
kernel /vmlinuz-2.6.32-696.el6.x86_64 ro root=UUID=b6032312-9cab-4be8-845b-b4a266d3d7c8 rd_NO_LUKS rd_NO_LVM.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet max_loop=20
58. I remember the link files: /etc/grub.conf and /etc/sysconfig/selinux
[root@centos6 dev]# ll /etc/grub.conf
lrwxrwxrwx. 1 root root 22 Mar 27 17:35 /etc/grub.conf -> ../boot/grub/grub.conf
[root @ centos6 dev] # vi / boot / gull ^ C
[root@centos6 dev]# ll /etc/sysconfig/selinux
lrwxrwxrwx. 1 root root 17 Mar 27 17:23 /etc/sysconfig/selinux -> ../selinux/config
59. You cannot directly use mount -a to modify the fstab file, you need to umount first
You can directly mount -o remount /data/sdb2 to directly modify the entry
60.tune2fs -U `uuidgen` /dev/sdb2 Modify UUID
61. mount -o rw, remount / executes when the repair state cannot be written, if the UUID is wrong (the system startup will not be affected after the mount point is deleted), when the check is 0, the system can be started but an error is reported
If it is not 0, an error will be reported, the system will not be able to start, and it will be read-only after entering the root password. So try to use 0 (the last bit)
62.dd if=dev/zero of=/dev/sdb bs=1 count=512 can clear the partition
partx -d --nr 1-2 /dev/sdb
63.init 1 single user, can prevent someone from modifying data during backup
64. Home directory migration
1. Backup /home
2. fdisk partition
3. mkfs.ext4 -L /home /dev/sdc1 -L specifies the volume label
4. mkdir /mnt/home; mount /dev/sdb1 /mnt/home
5. init 1 single user (network disconnection)
6. cp -av / home / * / mnt / home
7. rm -rf /home/*
8. vim /etc/fstab
UUID=xxx /home ext4 defaults 0 0
mount -a
ls / home / mnt / home -l
9. rm -rf /mnt/home umount /mnt/home;
10. init 5
65. When the file is mounted, the device name must be used in /etc/fstab, instead of UUID /root/p1 /mnt/p1 ext4 loop 0 0
66. CD mount /dev/sr0 /mnt/cdrom iso9660 defaults 0 0
67. Folder hanging folder /boot /mnt/boot none bind 0 0
68. The free -m command uses buffer for memory writing to disk, and cache for disk-related memory writing. Buffer and cache are two separate areas in memory
Memory used contains buffer cache space
-/+ used - buffer cache | free + cache buffer
69. Sometimes the data in the buffer and the cache are the same, and the buffer cache is allocated in memory
70 dd if=dev/zero of=/dev/null bs=2048M count=1 more than 1g swap appears to be used
71. Increase the swap partition and place it on the outermost track 0 to access the speed block
Specify when partition selection id is 82 partition
mkswap /dev/sdb1 -L swap_sdb1 create a filesystem
r!blkid /dev/sdb1 directly reads the command output to vim /etc/fstab
swapon -a re-read swap cannot use mount to read swap
swapon -s (cat /proc/swaps is read) to view swap information -1 -2 The larger the partition value -1 the higher the priority, the higher the priority
defaults,pri=100 modify priority
swapoff /dev/sdb1
swapon -a effective priority
72. To delete a partition, you can use fdisk or dd to destroy the partition table 512 bytes dd command
73. Create swap partition
1.fdisk /dev/sdb1 t 82
dd if=/dev/zero of=/swapfile bs=1M count=2048
2.mkswap /dev/sdb1 -L swap_sdb1
3.vim /etc/fstab
UUID=xxx swap swap defaults,pri=100 0 0
4.swapon -a
5. swapon -s View swap partition information
[root @ centos7 ~] #swapon -s
Filename Type Size Used Priority
/dev/sda3 partition 2047996 1748 -1
6.swapoff /dev/sdb1 disable swap
74./dev/cdrom --> sr0 mount /dev/cdrom general ll /dev/cdrom link
75.eject eject the CD, which can locate the faulty server
76.cp /devsr0 /data/centos.iso Make a mirror iso file, which can be used to boot the system
77.mount /data/centos7.iso /mnt/iso
78.dd if=/dev/sr0 of=/data/**.iso
79.mkisofs -r -o etc.iso /etc/
file etc.iso
centos7 does not need -o loop centos6 needs to use -o loop
80. Make an iso collection
Create a folder and copy the existing image files into it
Using mkisofs the collection cannot be used as a boot system
81.wiki.centos.org , search for mkdvdiso, scripting guide collection iso
82.tail /var/log/messages -f There is information after the U disk is recognized
83. When copying data to the U disk, you need to sync it, otherwise the data will not be transferred in the buffer
Sync is executed 3 times to prevent an unsuccessful execution
84. The smallest allocation unit of a file is a block
85.dd if=f1 of=f2 will overwrite the target file bs=1 count=3 skip?
86.dd if=/dev/zero of=/dev/sda bs=1 count=64 skip=446 seek=446
87./dev/urandom random device/dev/mem memory device/dev/cdrom optical disc device
88. raid0 split unit chunk 256 stripe set
raid5 at least 3 1-bit checksums
raid6 at least 4 two-bit checksum
89. Hard raid can only see one hard disk, soft raid is mdN
90.dd if=/dev/zero of=/dev/sda bs=64 count=1 seek=446 fill only 46 bytes of the partition table