linux不重启挂载磁盘安装grub
挂载、分区、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的更多相关文章
- centos、linux查找未挂载磁盘格式化并挂载?
centos.linux查找未挂载磁盘格式化并挂载? df -h 查看当前linux服务器硬盘: fdisk -l /dev/sda 第一块硬盘 /dev/sdb 第二块硬盘 依此类推 以/d ...
- 如何在linux环境上挂载磁盘
1.1 fdisk -l 命令 查看可用的磁盘信息(如果没有显示可用的磁盘,可重启一下主机:reboot) 1.2 df –h 命令 可查看已挂的磁盘情况 1.3 pvs ...
- Linux阿里云挂载磁盘,并开机自动挂载
Linux下磁盘挂载 公司新订购阿里云ECS,需要挂载当前的磁盘.暂时没有运维,自己动手挂载磁盘. 具体步骤如下: 1.查看是否已经分配 [root@iZ2ze1tefvghtbgkdur3xfZ / ...
- linux下如何挂载磁盘
1.显示磁盘使用情况:#df 2.显示磁盘:#fdisk -l 3.格式化分区:#mkfs.ext4 /dev/vdb1 //注:将/dev/vdb1格式化为ext4类型(文件类型 ...
- Linux记录-重启后磁盘丢失问题解决方案
1.df -TH 查看挂载情况 2.fdisk -l 查看磁盘情况 3.blkid 查看磁盘文件系统 4.vim /etc/fstab 加入 /dev/xvdf ext4 defaults 0 ...
- Linux基础二(挂载、关机重启与系统等级)
一.Linux 基础之挂载 1. 挂载和查询 1.1 挂载 什么叫挂载?装系统的时候要给硬盘分区,在 Windows 中要分 C 盘 D 盘 DEF 盘,这个操作我们叫做分配盘符,分配盘符之后我们就可 ...
- linux下玩转磁盘管理与挂载硬盘
前言 本文将带来linux下的磁盘管理中的硬盘挂载,Linux操作系统挂载硬盘需要了解的一些知识.这可能是迄今为止介绍的最最最实用的linux硬盘挂载的文章了,比较详细.由于工作原因,平时使用的比较多 ...
- Linux根据UUID自动挂载磁盘分区
一般服务器都有多个硬盘分区,在重启后,这些分区的逻辑位置加载时可能会发生变动,如果使用传统的设备名称(例如:/dev/sda)方式挂载磁盘,就可能因为磁盘顺序变化而造成混乱. Linux环境中每个Bl ...
- Raid5之后安装系统,挂载磁盘
配置RAID5 略 2.U盘安装centos系统(我的版本是centos7.0) 这一步骤网上很多,可以参考这篇:http://jingyan.baidu.com/article/359911f571 ...
随机推荐
- Java学习---InetAddress类的学习
基础知识 1.InetAddress类 在网络API套接字,InetAddress类和它的子类型对象使用域名DNS系统,处理主机名到主机IPv4或IPv6地址的转换.如图1-1所示. 由于InetAd ...
- php给$_POST赋值会导致值为空
在调试一个程序的时候发现很奇怪的现象,post传过来的值再某些地方为空,先看下面的代码 <?php if($_POST['submit'] == 'Add'){ if($_POST['type' ...
- Git 解决方案 commit your changes or stash them before you can merge
error: Your local changes to the following files would be overwritten by merge: *********** Please, ...
- post注入及提权思路
我们这次的目标有点敏感 性感的马赛克是必须有的 登陆表单 那么我们来看看是不是存在post注入 Setp1:设置代理 Step2:账户admin密码随意 提交上去 抓个包 把抓到的包复制到本地的一 ...
- HTML 教程
HTML5 标准 超文本标记语言(英语:HyperText Markup Language,简称:HTML) 是一种用于创建网页的标准标记语言. 您可以使用 HTML 来建立自己的 WEB 站点,HT ...
- java多态-向上转型和向下转型
向上转型:符合“is a”,是安全的,子类向上到父类,多余的属性和方法会丢弃 向下转型:不安全的,用instanceof提前判断一下,以免抛出异常 instanceof用法: result = obj ...
- JavaScript的DOM_通过计算后样式来获取
虽然可以通过 style 来获取单一值的 CSS 样式,但对于复合值的样式信息,就需要通过计算样式来获取. DOM2 级样式,window 对象下提供了 getComputedStyle()方法.接受 ...
- JavaScript浏览器检测之navigator 对象
一.使用客户端检测的原因 由于每个浏览器都具有自己独到的扩展,所以在开发阶段来判断浏览器是一个非常重要的步骤. 虽然浏览器开发商在公共接口方面投入了很多精力,努力的去支持最常用的公共功能: 但在现实中 ...
- JavaScript正则表达式_常用的正则
一.检查邮政编码 var pattern = /[1-9][0-9]{5}/; //共 6 位数字,第一位不能为0 {5}表示后面5位0到9 var str = '224000'; alert(pa ...
- UVa 12230 - Crossing Rivers(数学期望)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...