Linux-file system management

Source: Internet
Author: User
Tags hex code dmesg
Related links: linux that thing (1) http://www.2cto.com/ OS /201205/131407.html?linuxthat thing (2) http://www.2cto.com/ OS /201205/131408.html?linuxthat thing (3) http://www.2cto.com/ OS /201205/13140
Related links: linux (1) events (2) http://www.2cto.com/ OS /201205/131408.html?linuxlinux( 3) Events (4) ---- User management details (5) ---- common user management commands (6) ---- process management details http://www.2cto.com/ OS /201205/132474.html if you are a loyal windows user, then now please open the C drive, open WINDW Which files and directories are stored in the OS directory! Even people who have been using windows for many years. Amount! In fact, I also know what is put under the WINDOWS directory. in my memory, I almost never opened that directory. This is windows. Linux requires us to have a long history, and we will fall in love with it only after learning about it.
In linux, all the things in the linux file system are file system Hierarchy Standard (FHS), that is, hierarchical tree directory structure. At the top of this structure is the root directory "/" (slash), and then under this root directory is another directory and sub-directory www.2cto.com

Like DOS and Windows, Linux uses "paths" to indicate the levels of files or directories in the file system. A path consists of multiple directory name strings separated by "/", which are divided into absolute paths and relative paths. An absolute path is a method that starts from the root directory "/" to indicate the location of a file or directory in the system. For example, if an absolute path is used to represent the bin directory in the 4th-layer directory in the figure, it should be "/usr/local/bin ". The relative path is based on the current directory, indicating the location of a file or directory in the file system. If the current working directory is "/home", the relative path is used to represent the bin directory in the 4th-layer directory in the figure, which should be "hls/bin" or ". /hls/bin ", where ". /"indicates the current directory, which can be omitted. The Linux file system is organized differently from the Windows operating system. For devices used in Linux, without the need to create drive letters like Windows, Linux recognizes all devices including local disks, network file systems, CD-ROM and USB disks as device files, and embedded in the Linux file system for management. A device file does not occupy any space in the file system. it is only the entry to access a device driver. In Linux, there are two types of special files: character-oriented special files and block-oriented special files. The former allows I/O operations to be performed in the form of characters, while the latter uses the memory buffer to implement data read/write operations in the form of data blocks. When an I/O operation is performed on a device file, the operation is transferred to the corresponding device driver. A device file is represented by the master device number (indicating the device type) and the slave device number (indicating the first devices of this type). you can create a device file using the mknod command. Representation of typical device files such as floppy disk, CD, and hard disk in Linux. Representation of typical device files in Linux
Linux file names can contain a maximum of 256 characters, including numbers, characters, and symbols such as ".", "-", and. Linux file names are not like DOS or Windows. they are composed of the primary file name and the extended file name. Linux does not have the extension concept. In Linux, file names are Case sensitive. for example, test.txtand test.txt are recognized as two different files, whereas DOS or Windows platforms do not use Case sensitivity. File system structure/usr/bin,/bin: ------------- stores all commands that can be executed by users/usr/sbin,/sbin: ----------- stores commands that can only be executed by root/home: -------------------- the user's default home directory/proc: --------------------- virtual file system, stores the current memory Image/dev: -------------------- stores the device file/lib: KeyStore stores the shared library/lost + foud required by the system program: --------------- store some system error check results/tmp: ----------------------- store temporary files/etc: ----------------------- system configuration file/var: -------------------- contains files that frequently change, such as: email, Log files, scheduled tasks, etc./usr: -------------------- store all commands, libraries, manual pages, and so on. it is similar to the windows directory/mnt: -------------------- installation point of the temporary file system/boot: --------------------- the storage location of kernel files and self-lifting Program files. in windows, we are used to placing installed programs under the Program files directory. in linux, we are used to putting programs under/user/local. View file commands view partition usage: df view file, directory size: du detection repair file system: fsck, e2fsck (executed in single user mode) determine file type: file df: View linux disk partitions. in windows, it is very easy to view the partition of our hard disk. open "My Computer" and you will know that there are several disks. move the mouse over the drive letter to display the disk size, in linux, how can we check it? it's actually very simple. a command thing [root @ bogon ~] # Df-hFilesystem capacity in use available % mount point/dev/sda1 9.7G 3.3G 5.9G 37%/none 506 M 0 506 M 0%/dev/shm/dev/sda2 2.9G 37 M 2.7G 2%/hzh/dev/sda5 6.2G 47 M 5.9G 1%/web du view file and directory size in windows right-click the file and directory size-properties, for linux, run the "du" command. Root @ fnngj-H24X:/hzh # du-h test. test ------ view the file size 4.0 K test. test root @ fnngj-H24X:/# du-sh/etc ------ view the directory size 7.1 M/etc file to determine the file type we know that the file in linux is not the same as the suffix name to determine the type, if a file does not have a suffix, you can use the file command to view the suffix. Root @ fnngj-H24X:/hzh # file test. test. test: ASCII text is used to add disks, partitions, formatting, and attaching www.2cto.com. this is a problem we encounter when playing linux servers. according to the initial plan, you have a GB hard disk on linux, after a while, it is not enough. What should I do? Replace a 1 TB hard disk, reload the system, and copy the original data to the new hard disk. This method is acceptable, but too stupid. Simply add a hard disk to the original system. What we need to know now is how to let the newly added hard disk work for us.

Settings --- add a new virtual hard disk as prompted by the image! This is the benefit of virtual machines. it can help us simulate adding multiple hard disks. Create a file system (mkfs) by partitioning (fdisk) and try to mount and write the configuration file (/etc/fstab) to view the hard disk information of the newly added partition: [root @ bogon ~] # Dmesg | grep sdb is the second hard drive SCSI device sdb: 20971520 512-byte hdwr sectors (10737 MB) sdb: cache data unavailablesdb: assuming drive cache: write throughSCSI device sdb: 20971520 512-byte hdwr sectors (10737 MB) sdb: cache data unavailablesdb: assuming drive cache: write throughsdb: unknown partition tableAttached scsi disk sdb at scsi0, channel 0, id 1, lun 0 if the dmesg | grep sdb command does not have any information, the problem will be big. Your system does not recognize the newly added Hu hard disk. Partition the hard disk. Next, let's take a look at the information of the second hard disk we added. [Root @ bogon ~] # Fdisk-l/dev/sdbDisk/dev/sdb: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylindersUnits = cylinders of 16065*512 = 8225280 bytesDisk/dev/sdb doesn't contain a valid partition table sdb B represents the second hard disk, if you want to view the information of the first hard disk, enter sda.
[Root @ bogon ~] # Fdisk-l/dev/sdaDisk/dev/sda: 21.4 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065*512 = 8225280 bytesDevice Boot Start End Blocks Id System/dev/sda1 * 1 1275 10241406 83 Linux/dev/sda2 1276 1657 83 Linux/dev/sda3 1658 1788 1052257 + 82 Linux swap/dev/sda4 1789 2610 6602715 5 Extended/dev/sda5 1789 2610 6602683 + 83 Linux start partitioning hard disks. [root @ bo Gon ~] # F disk/dev/sdbThe number of cylinders for this disk is set to 2610. there is nothing wrong with that, but this is larger than 1024, and cocould in certain setups cause problems with: 1) software that runs at boot time (e.g ., old versions of LILO) 2) booting and partitioning software from other OSs (e.g ., dos fdisk, OS/2 FDISK) Command (m for help): m ----- press m to get help information Command actiona toggle a bootable flag B edit bsd disklabelc toggle the dos compatibility flagd delete a partition ----- delete partition l list known partition typesm print this menun add a new partition ----- add a new partition o create a new empty DOS partition tablep print the partition table ----- display partition table q quit without saving changes ----- do not save and exit s create a new empty Sun disklabelt change a partition's system id ----- change file system type u change display/ entry units www.2cto. Com v verify the partition tablew write table to disk and exit ----- save and exit x extra functionality (experts only) partition to add the first primary partition ---------------------- Command (m for help ): p ----- display partition table Disk/dev/sdb: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylindersUnits = cylinders of 16065*512 = 8225280 bytesDevice Boot Start End Blocks Id Sys TemCommand (m for help): n ----- Add new partition Command actione extended e is the extended partition p primary partition (1-4) ---- p is the primary partition, we can add up to four primary partitions p ----- by p, which means we want to divide the primary Partition number (1-4 ): 1 ----- give the primary partition a number 1 First cylinder (1-1305, default 1): ----- this 1-1305 refers to the fan surface, this is more troublesome, press enter Using default value 1 Last cylinder or + size or + sizeM or + sizeK (1-1305, default 1305) without selecting ): + 5120 M ---- we need to specify the partition size in this place. we can specify the partition size in bytes. the hard disk is 10 GB for China and 5 GB for China. Command (m for help): p ----- now check the partition table Disk/dev/sdb: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylindersUnits = cylinders of 16065*512 = 8225280 bytesDevice Boot Start End Blocks Id System/dev/sdb1 1 623 5004216 83 Linux ----- information about the first primary partition is displayed. primary partition --------------------------------- Command (m for help): n ----- continue partitioning by n Command actione extendedp primary partition (1-4) p ----- p then draws a primary Partition partition number (1-4 ): 2 ----- input 2 indicates the second primary partition First cylinder (624-1305, default 624 ): using default value 624 Last cylinder or + size or + sizeM or + sizeK (624-1305, default 1305): ----- we want to give the remaining space to 2, press enter Using default value 1305 Command (m for help): p ----- to view the partition table Disk/dev/sdb: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylindersUnits = cylinders of 16065*512 = 8225280 bytesDevice Boot Start End Blocks Id System/dev/sdb1 1 1 623 5004216 83 Linux/dev/sdb2 624 1305 5478165 83 Linux ----- two partitions divided the format of the specified disk on www.2cto.com is displayed. Next, it refers to the type of the file system, the current window partition FAT32 and NTFS are two common partitions, so the disk formats supported in linux are very much. note: do not exit the fdisk mode Command (m for help): t ---- specify the Partition table Partition number (1-4 ): 1 ---- the Hex code (type L to list codes) of the primary partition whose part number is 1: L ---- we do not know the number here. you can use L to view all the partition formats.

83 Linux ----- this is the format of the two primary partitions we just divided. Hex code (type L to list codes): 83 ---- if you do not want to change the original format, enter 83 and press enter to delete the partition. if you find that your partition is not properly divided, you want to delete a partition, re-division. Note: do not exit the fdisk mode Command (m for help): d ---- delete Partition number (1-4 ): 2 ---- delete the 2nd Partition Command (m for help): PDisk/dev/sdb: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylindersUnits = cylinders of 16065*512 = 8225280 bytesDevice Boot Start End Blocks Id System/dev/sdb1 1 1 63 506016 83 Linux ---- we have only one partition left. save and exit when we after dividing, you must save and exit to save the partition. Other normally exited partitions cannot be saved. Note: This is The time when we want to exit The fdisk mode. when we exit The fdisk mode, The Command _ ^ Command (m for help): w -- w is to save and exit, and q is not to save and exit The partition table has been altered! Calling ioctl () to re-read partition table. Syncing disks. the disk format is OK! The partition has been completed. Should I format the hard disk? [root @ bogon ~] # Mk -- enter mk and press the tab key twice. you will see many partition commands in linux: mkafmmap mkdosfs mkfs. ext2 mkisofs mktempmkbootdisk mke2fs mkfs. ext3 mklost + found mkxauthmkcfm mkfifo mkfs. msdos mkmanifest mkzftreemkcramfs mkfontdir mkfs. vfat mknod mkzonedbmkdict mkfontscale mkhtmlindex mkSimNodeDirmkdir mkfs mkhybrid mksock www.2cto.com mkdirhier mkfs. cramfs mkinitrd mkswap
When formatting in windwos, we can specify FAT32 and NTFS. the popular formats in linux are ext2 and ext3. here we format the 1st partitions, select the ext3 format [root @ bogon ~] # Mkfs. ext3/dev/sdb1mke2fs 1.35 (28-Feb-2004) Filesystem label = OS type: LinuxBlock size = 4096 (log = 2) Fragment size = 4096 (log = 2) 626496 inodes, 1251054 blocks62552 blocks (5.00%) reserved for the super userFirst data block = 0 Maximum filesystem blocks = 128345702439 block groups32768 blocks per group, 32768 fragments per group16064 inodes per groupSuperblock backups stored on blocks: 32768,983 04, 163840, 229376,294 912, 819200,884 8192 Writing inode tables: doneCreating journal (blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 25 mounts or180 days, whichever comes first. use tune2fs-c or-I to override. mount partition OK! Now the hard disk partition has been divided and formatted. we need to use this partition below. In use, we need to mount it. Just like hanging on a CD. Run the mount command. [Root @ bogon/] # mkdir/newsdb ----- create a mount point directory under the root directory/newsdb [root @ bogon/] # mount/dev/sdb1/newsdb/ ---- then mount the 1st formatted partitions/dev/sdb1 to the/newsdb Directory [root @ bogon/] # df-hFilesystem capacity used available % mount point/dev/sda1 9.7G 3.3G 5.9G 37%/none 506 M 0 506 M 0%/dev/shm/dev/sda2 2.9G 37 M 2.7G 2%/hzh/dev/sda5 6.2G 47 M 5.9G 1%/web/dev/sdb1 4.7G 42 M 4.5G 1%/newsdb ----- look! Is there an extra disk in our system !! How does www.2cto.com solve the problem of attaching each restart? the above method is complete, but there is a problem. after we restart the system, the new sdb1 partition disappears, we also need to re-mount. To solve this problem, we need to write the configuration file (/etc/fatab) [root @ bogon/] # vi/etc/fstab ---- Let's take a look at what is stored in this configuration file.

LABEL = // ext3 defaults 1 (/0) 1 (0/1/2) LABEL =/physical partition name/volume LABEL/Mount point ext3 file system defaults default setting 1 (/0) whether to detect, O not detect, 1 Detection 1 (0/1/2) detection sequence, O not detect, 1 priority detection, 2 secondly detection we know the meaning of each part, add the information of the partition we created, so when the system restarts, it will automatically load our hard disk partition, and we do not need to manually load it. /Dev/sdb1/newsdb ext3 defaults 1 2: how to increase the virtual memory? what is this virtual memory? I will not explain it here. add the virtual memory mode in windows. I believe you know it! If you don't understand, you can skip this section. Haha! The following describes how to increase the virtual memory of LINUX. 1. # mkdir/var/swap # chmod 700/var/swap2, # dd if =/dev/zero of =/var/swap/file. swp bs = 1024 count = 655263, # mkswap/wap/swap/file. swp4, # vi/etc/fstab/var/swap/file. swp swap defaults 0 05, free www.2cto.com 6, swapon/var/swap/file. swp7 and free explain the following ideas: 1. mkdir creates a virtual memory Directory. chmod gives this directory only the administrator permission. 2. dd has a powerful copy command, in Magic linux, you can create an empty file and specify its size. in windows, the file size depends on the content stored in the file. if the file is empty, the file must be 0 bytes. In linux, empty and small files can be created, which meets the requirements of our virtual memory. 3. set the swap area for mkswap and set file. swp to the swap area. 4. edit the fstab file and write the file with the virtual memory configured. 5. The free command displays the memory usage, including the physical memory, virtual swap file memory, shared memory segments, and the system core buffer. 6. swapon enables the virtual memory creator
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.