挂载、分区、grub

通过给一块新磁盘安装grub回顾磁盘挂载、分区文件系统创建等操作:

该实验基于(CtonOS6.8;kernel:2.6.32-642.15.1.el6.x86_64

1.通过VMware Workstationg添加一块磁盘(SCSI);

2./sys下SCSI扫描,查看主机总线号,磁盘肯定是有总线连接着:

 [root@cl Test]# ls /sys/class/scsi_host/
host0 host1 host2
[root@cl Test]# echo "- - -" > /sys/class/scsi_host/host0/scan
[root@cl Test]# echo "- - -" > /sys/class/scsi_host/host1/scan
[root@cl Test]# echo "- - -" > /sys/class/scsi_host/host2/scan
[root@cl Test]# fdisk -l

3.创建分区:

 [root@cl Test]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xa61749e4.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u'). Command (m for help): n
Command action
e extended
p primary partition (-)
p
Partition number (-):
First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +200M Command (m for help): n
Command action
e extended
p primary partition (-)
p
Partition number (-):
First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +2G Command (m for help): t
Partition number (-):
Hex code (type L to list codes):
Changed system type of partition to (Linux swap / Solaris) Command (m for help): n
Command action
e extended
p primary partition (-)
p
Partition number (-):
First cylinder (-, default ):
Using default value
Last cylinder, +cylinders or +size{K,M,G} (-, default ): +5G Command (m for help): w
The partition table has been altered! Calling ioctl() to re-read partition table.
Syncing disks.
[root@cl Test]# partx -a /dev/sdb
BLKPG: Device or resource busy
error adding partition
BLKPG: Device or resource busy
error adding partition
BLKPG: Device or resource busy
error adding partition
[root@cl Test]# cat /proc/partitions
major minor #blocks name sda
sda1
sda2
sda3
sda4
sda5
sda6
sda7
sdb
sdb1
sdb2
sdb3

4.创建文件系统:

 [root@cl Test]# mke2fs -t ext4 /dev/sdb1
[root@cl Test]# mke2fs -t ext4 /dev/sdb3
[root@cl Test]# mkswap /dev/sdb2

5.挂载分区:

 [root@cl ~]# mkdir /mnt/boot
[root@cl ~]# mount /dev/sdb1 /mnt/boot/
[root@cl ~]# ls /mnt/boot/
lost+found

6.安装grub:

 [root@cl ~]# grub-install --root-directory=/mnt /dev/sdb1 (指明/的位置在mnt下)
Probing devices to guess BIOS drives. This may take a long time.
Installation finished. No error reported.
This is the contents of the device map /mnt/boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install'. (fd0) /dev/fd0
(hd0) /dev/sda
(hd1) /dev/sdb
[root@cl ~]# ls /mnt/boot/
grub lost+found
[root@cl ~]# ls /mnt/boot/grub/
device.map ffs_stage1_5 minix_stage1_5 stage2 xfs_stage1_5
e2fs_stage1_5 iso9660_stage1_5 reiserfs_stage1_5 ufs2_stage1_5
fat_stage1_5 jfs_stage1_5 stage1 vstafs_stage1_5

7.配置grub:

 [root@cl ~]# cp /boot/vmlinuz-2.6.-.el6.x86_64 /mnt/boot/vmlinuz
[root@cl ~]# cp /boot/initramfs-2.6.-.el6.x86_64.img /mnt/boot/initramfs.img
[root@cl ~]# vim /mnt/boot/grub/grub.conf

default=0
timeout=5
title CentOS (Express)
root (hd0,0)
kernel /vmlinuz ro root=/dev/sda3
initrd /initramfs.img

8.创建根文件目录:

 [root@cl ~]# mkdir /mnt/sysroot
[root@cl ~]# mount /dev/sdb3 /mnt/sysroot/
[root@cl ~]# cd /mnt/sysroot/
[root@cl sysroot]# mkdir -p etc bin sbin lib lib64 dev proc sys tmp var usr home mnt media
[root@cl sysroot]# ls
bin dev etc home lib lib64 lost+found media mnt proc sbin sys tmp usr var
[root@cl sysroot]# cp /bin/bash /mnt/sysroot/bin/ (复制程序bash)
[root@cl sysroot]# ldd /bin/bash (查看程序依赖库文件)
linux-vdso.so. => (0x00007fffd39f9000)
libtinfo.so. => /lib64/libtinfo.so. (0x0000003cc3800000)
libdl.so. => /lib64/libdl.so. (0x0000003cc1c00000)
libc.so. => /lib64/libc.so. (0x0000003cc2000000)
/lib64/ld-linux-x86-.so. (0x0000003cc1800000)
[root@cl sysroot]# cp /lib64/libtinfo.so. /mnt/sysroot/lib64/
[root@cl sysroot]# cp /lib64/libdl.so. /mnt/sysroot/lib64/
[root@cl sysroot]# cp /lib64/libc.so. /mnt/sysroot/lib64/
[root@cl sysroot]# cp /lib64/ld-linux-x86-.so. /mnt/sysroot/lib64/
[root@cl sysroot]# cd
[root@cl ~]# chroot /mnt/sysroot/ (切换根)
bash-4.1#
bash-4.1# exit
exit

9.编辑启动init为/bin/bash:

[root@cl ~]# vim /mnt/boot/grub/grub.conf 

default=
timeout=
title CentOS (Express)
root (hd0,)
kernel /vmlinuz ro root=/dev/sda3 init=/bin/bash
initrd /initramfs.img
[root@cl ~]# sync

note:该操作把bash当做第一个用户空间运行进程启动;

note:sync命令的作用是,将有关文件系统的存储器常驻信息送入物理介质内。在暂停系统之前,比如要重新启动机器,一定要去执行sync命令。

补充:模拟破坏和修复方法一

 [root@cl ~]# dd if=/dev/sda of=/root/mbr.bak count= bs=
+ records in
+ records out
bytes ( B) copied, 0.000155983 s, 3.3 MB/
[root@cl ~]# dd if=/dev/zero of=/dev/sda bs= count=
+ records in
+ records out
bytes ( B) copied, 0.000307597 s, kB/s
[root@cl ~]# sync
[root@cl ~]# grub-install --root-directory=/ /dev/sda
Installation finished. No error reported.
This is the contents of the device map //boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install'. # this device map was generated by anaconda
(hd0) /dev/sda

    模拟破坏和修复方法二

 [root@cl ~]# dd if=/dev/zero of=/dev/sda bs= count=
+ records in
+ records out
bytes ( B) copied, 0.0170366 s, 11.7 kB/s
[root@cl ~]# sync
[root@cl ~]# grub
Probing devices to guess BIOS drives. This may take a long time. GNU GRUB version 0.97 (640K lower / 3072K upper memory) [ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename.]
grub> root (hd0,)
root (hd0,)
Filesystem type is ext2fs, partition type 0x83
grub> setup (hd0)
setup (hd0)
Checking if "/boot/grub/stage1" exists... no
Checking if "/grub/stage1" exists... yes
Checking if "/grub/stage2" exists... yes
Checking if "/grub/e2fs_stage1_5" exists... yes
Running "embed /grub/e2fs_stage1_5 (hd0)"... sectors are embedded.
succeeded
Running "install /grub/stage1 (hd0) (hd0)1+27 p (hd0,0)/grub/stage2 /grub/grub.conf"... succeeded
Done.
grub> quit
quit
[root@cl ~]# sync

    模拟破坏和修复方法三:(重启后救援模式修复)

重启:

[root@cl ~]# dd if=/dev/zero of=/dev/sda bs= count=
+ records in
+ records out
bytes ( B) copied, 0.000283877 s, kB/s
[root@cl ~]# sync
[root@cl ~]# reboot Broadcast message from root@cl.y.dba
(/dev/pts/) at : ... The system is going down for reboot NOW!

修复:1.选择镜像光盘:

  2.重启系统选择救援模式:

  3.进入shell:

4.修复并重启:

linux不重启挂载磁盘安装grub的更多相关文章

  1. centos、linux查找未挂载磁盘格式化并挂载?

    centos.linux查找未挂载磁盘格式化并挂载? df -h 查看当前linux服务器硬盘: fdisk -l /dev/sda   第一块硬盘 /dev/sdb   第二块硬盘 依此类推 以/d ...

  2. 如何在linux环境上挂载磁盘

    1.1      fdisk -l 命令 查看可用的磁盘信息(如果没有显示可用的磁盘,可重启一下主机:reboot) 1.2      df –h 命令 可查看已挂的磁盘情况 1.3      pvs ...

  3. Linux阿里云挂载磁盘,并开机自动挂载

    Linux下磁盘挂载 公司新订购阿里云ECS,需要挂载当前的磁盘.暂时没有运维,自己动手挂载磁盘. 具体步骤如下: 1.查看是否已经分配 [root@iZ2ze1tefvghtbgkdur3xfZ / ...

  4. linux下如何挂载磁盘

    1.显示磁盘使用情况:#df 2.显示磁盘:#fdisk -l 3.格式化分区:#mkfs.ext4 /dev/vdb1           //注:将/dev/vdb1格式化为ext4类型(文件类型 ...

  5. Linux记录-重启后磁盘丢失问题解决方案

    1.df -TH 查看挂载情况 2.fdisk -l 查看磁盘情况 3.blkid 查看磁盘文件系统 4.vim /etc/fstab 加入  /dev/xvdf   ext4  defaults 0 ...

  6. Linux基础二(挂载、关机重启与系统等级)

    一.Linux 基础之挂载 1. 挂载和查询 1.1 挂载 什么叫挂载?装系统的时候要给硬盘分区,在 Windows 中要分 C 盘 D 盘 DEF 盘,这个操作我们叫做分配盘符,分配盘符之后我们就可 ...

  7. linux下玩转磁盘管理与挂载硬盘

    前言 本文将带来linux下的磁盘管理中的硬盘挂载,Linux操作系统挂载硬盘需要了解的一些知识.这可能是迄今为止介绍的最最最实用的linux硬盘挂载的文章了,比较详细.由于工作原因,平时使用的比较多 ...

  8. Linux根据UUID自动挂载磁盘分区

    一般服务器都有多个硬盘分区,在重启后,这些分区的逻辑位置加载时可能会发生变动,如果使用传统的设备名称(例如:/dev/sda)方式挂载磁盘,就可能因为磁盘顺序变化而造成混乱. Linux环境中每个Bl ...

  9. Raid5之后安装系统,挂载磁盘

    配置RAID5 略 2.U盘安装centos系统(我的版本是centos7.0) 这一步骤网上很多,可以参考这篇:http://jingyan.baidu.com/article/359911f571 ...

随机推荐

  1. leetcode coding base

    1. Contains Duplicate 2. Contains Duplicate II 3. Contains Duplicate III

  2. 编码学习---代码OJ网站

    代码OJ网站: https://leetcode-cn.com/accounts/login/

  3. MTK 官方 openwrt SDK 使用

    来源 1.https://github.com/unigent/openwrt-3.10.14 上面有个   问题:SDK 缺少 linux-3.10.14-p112871.tar.xz 在 http ...

  4. iptables常用配置

    常用的iptables模板 #!/bin/sh iptables -F iptables -X iptables -F -t mangle iptables -t mangle -X iptables ...

  5. Inno Setup 安装

    Inno Setup 安装 一.软件下载:http://www.jrsoftware.org/isdl.php#qsp 二.下载后,双击进行安装(包括inno Setup Compiler和Inno ...

  6. 随手练——HDU Safe Or Unsafe (小根堆解决哈夫曼问题)

    HDU 2527 :http://acm.hdu.edu.cn/showproblem.php?pid=2527 哈夫曼树,学完就忘得差不多了,题目的意思都没看懂,有时间复习下,看了别人的才知道是怎么 ...

  7. No.3 - CSS transition 和 CSS transform 配合制作动画

    课程概述 作业提交截止时间:09-01 任务目的 深度理解掌握 transition-timing-function 以及它的意义 学会配合使用 CSS transform 和CSS transiti ...

  8. ERDAS IMAGINE 2014 32位 破解安装

    1.        安装Install ERDAS Foundation 2014 2.        安装ERDAS IMAGINE 2014  32位 3.        安装Intergraph ...

  9. maven加速镜像

    <mirror> <id>repo3</id> <mirrorOf>central</mirrorOf> <name>Human ...

  10. iOS12适配及问题记录,Debug正常使用,Release数据为nil的报错

    Debug模式数据一切正常,打包出去的ipa,Release模式下数据为nil的错误,经排查,buiding中的Optimization Level, Release设为None,解决问题. IOS1 ...