Inodes are associated with precisely one directory entry at a time. However, with hard links it is possible to associate multiple directory entries with a single inode. To create a hard link use ln command as follows:
# ln /root/file1 /root/file2
# ls -l
Above commands create a link to file1. Symbolic links refer to:
Linux获取CPU,内存和硬盘信息
本文目的
本文搜集了Linux上常用的获取机器配置信息和实时信息相关命令。这些命令在开发运维相关程序时,比较常用。
CPU
- CPU位数(32或64): getconf LONG_BIT
- CPU配置信息:cat /proc/cpuinfo
- CPU实时信息:top -n 1 | grep Cpu | cut -d ',' -f 4 (获取实时CPU空闲率)
P.S.: 上面命令中最后的4可以换成其他值,以获取不同CPU实时信息
Memeory
- 内存实时数据:free
P.S.:第二行数据以系统角度,第三行数据以用户角度
- 内存实时统计数据:cat /proc/meminfo
Hard Disk
- 硬盘实时数据:df
- 获取目录下每个文件大小:du
Top
top程序可以获取当前时刻系统cpu,mem的相关信息,可以使用相关shell命令,抓取你所需要的特定信息,正如上面获取CPU实时信息中使用的方式。
硬连接指通过索引节点来进行连接。在Linux的文件系统中,保存在磁盘分区中的文件不管是什么类型都给它分配一个编号,称为索引节点号(Inode Index)。在Linux中,多个文件名指向同一索引节点是存在的。一般这种连接就是硬连接。硬连接的作用是允许一个文件拥有多个有效路径名,这样用户就可以建立硬连接到重要文件,以防止“误删”的功能。其原因如上所述,因为对应该目录的索引节点有一个以上的连接。只删除一个连接并不影响索引节点本身和其它的连接,只有当最后一个连接被删除后,文件的数据块及目录的连接才会被释放。也就是说,文件真正删除的条件是与之相关的所有硬连接文件均被删除。
另外一种连接称之为符号连接(Symbolic Link),也叫软连接。软链接文件有类似于Windows的快捷方式。它实际上是一个特殊的文件。在符号连接中,文件实际上是一个文本文件,其中包含的有另一文件的位置信息。
(2)关于 I节点的问题 。硬连接不管有多少个,都指向的是同一个I节点,会把结点连接数增加,只要结点的连接数不是 0,文件就一直存在 ,不管你删除的是源文件还是连接的文件。只要有一个存在,文件就 存在(其实也不分什么 源文件连接文件的 ,因为他们指向都是同一个 I节点)。 当你修改源文件或者连接文件任何一个的时候,其他的 文件都会做同步的修改 。
Understanding UNIX / Linux symbolic (soft) and hard links
A symbolic path indicating the abstract location of another file.
Hard links refer to:
The specific location of physical data.
Hard link vs. Soft link in Linux or UNIX
- Hard links cannot link directories.
- Cannot cross file system boundaries.
Soft or symbolic links are just like hard links. It allows to associate multiple filenames with a single file. However, symbolic links allows:
- To create links between directories.
- Can cross file system boundaries.
These links behave differently when the source of the link is moved or removed.
- Symbolic links are not updated.
- Hard links always refer to the source, even if moved or removed.
How do I create symbolic link?
You can create symbolic link with ln command:
$ ln -s /path/to/file1.txt /path/to/file2.txt
$ ls -ali
Above command will create a symbolic link to file1.txt.
Task: Symbolic link creation and deletion
Let us create a directory called foo, enter:
$ mkdir foo
$ cd foo
Copy /etc/resolv.conf file, enter:
$ cp /etc/resolv.conf .
View inode number, enter:
$ ls -ali
Sample output:
total 152 1048600 drwxr-xr-x 2 vivek vivek 4096 2008-12-09 20:19 . 1015809 drwxrwxrwt 220 root root 143360 2008-12-09 20:19 .. 1048601 -rwxr-xr-x 1 vivek vivek 129 2008-12-09 20:19 resolv.conf
Now create soft link to resolv.conf, enter:
$ ln -s resolv.conf alink.conf
$ ls -ali
Sample output:
total 152 1048600 drwxr-xr-x 2 vivek vivek 4096 2008-12-09 20:24 . 1015809 drwxrwxrwt 220 root root 143360 2008-12-09 20:19 .. 1048602 lrwxrwxrwx 1 vivek vivek 11 2008-12-09 20:24 alink.conf -> resolv.conf 1048601 -rwxr-xr-x 1 vivek vivek 129 2008-12-09 20:19 resolv.conf
The reference count of the directory has not changed (total 152). Our symbolic (soft) link is stored in a different inode than the text file (1048602). The information stored in resolv.conf is accessible through the alink.conf file. If we delete the text file resolv.conf, alink.conf becomes a broken link and our data is lost:
$ rm resolv.conf
$ ls -ali
If alink.conf was a hard link, our data would still be accessible through alink.conf. Also, if you delete the soft link itself, the data would still be there. Read man page of ln for more information.
Continue reading rest of the Understanding Linux file system series (this is part VI):
- Part I – Understanding Linux superblock
- Part II – Understanding Linux superblock
- Part III – An example of Surviving a Linux Filesystem Failures
- Part IV – Understanding filesystem Inodes
- Part V – Understanding filesystem directories
- Part VI – Understanding UNIX/Linux symbolic (soft) and hard links
- Part VII – Why isn’t it possible to create hard links across file system boundaries?
-
grub配置文件默认为:/boot/grub/grub.conf
cat /etc/grub.conf(为软链接)default 定义缺省启动 系统 (多系统有意思)timeout 定义默认等待时间splashimage 定义GRUB界面图片title 定义菜单项名称root 定义内核所在分区kernel 指定内核文件所在位置initrd 指定镜像文件所在位置单用户是干嘛的? 能干嘛? 其实就跟window的安全模式一样 假如你的密码忘记 进去可以修改 单用户也可就是init1 级别进入单用户模式 开机后进grub界面。按下e进入菜单项,选中kernel行,再次按下e进入编辑模式,在行后空格并输入1,火车保存按b键引导,既可以进入单用户模式要是想修改你的启动画面等 都可以都这里设置
9.2. GRUB
The GNU GRand Unified Boot loader (GRUB) is a program which enables the selection of the installed operating system or kernel to be loaded at system boot time. It also allows the user to pass arguments to the kernel.
This section discusses the specific role GRUB plays when booting an x86 system. For a look at the overall boot process, refer to Section 30.2, “A Detailed Look at the Boot Process”.
GRUB loads itself into memory in the following stages:
-
The Stage 1 or primary boot loader is read into memory by the BIOS from the MBR[4]. The primary boot loader exists on less than 512 bytes of disk space within the MBR and is capable of loading either the Stage 1.5 or Stage 2 boot loader.
-
The Stage 1.5 boot loader is read into memory by the Stage 1 boot loader, if necessary. Some hardware requires an intermediate step to get to the Stage 2 boot loader. This is sometimes true when the /boot/partition is above the 1024 cylinder head of the hard drive or when using LBA mode. The Stage 1.5 boot loader is found either on the /boot/ partition or on a small part of the MBR and the /boot/ partition.
-
The Stage 2 or secondary boot loader is read into memory. The secondary boot loader displays the GRUB menu and command environment. This interface allows the user to select which kernel or operating system to boot, pass arguments to the kernel, or look at system parameters.
-
The secondary boot loader reads the operating system or kernel as well as the contents of /boot/sysroot/ into memory. Once GRUB determines which operating system or kernel to start, it loads it into memory and transfers control of the machine to that operating system.
The method used to boot Red Hat Enterprise Linux is called direct loading because the boot loader loads the operating system directly. There is no intermediary between the boot loader and the kernel.
The boot process used by other operating systems may differ. For example, the Microsoft®Windows® operating system, as well as other operating systems, are loaded using chain loading. Under this method, the MBR points to the first sector of the partition holding the operating system, where it finds the files necessary to actually boot that operating system.
GRUB supports both direct and chain loading boot methods, allowing it to boot almost any operating system.