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 ...
随机推荐
- Windows Socket和Linux Socket编程的区别 ZZ
socket相关程序从Windows移植到Linux下需要注意的: 1)头文件 Windows下winsock.h/winsock2.h Linux下sys/socket.h 错误处理:errno.h ...
- Python 词云 【中/英】小白简单入门教程
1. 分析 构建词云需要具备: 原料即文章等内容 将内容进行分词 将分词后的内容利用构建词云的工具进行构建 保存成图片 2. 需要的主要模块 jieba 中文分词 wordcloud 构建词云 3. ...
- Python学习---Django的基础学习
django实现流程 Django学习框架: #安装: pip3 install django 添加环境变量 #1 创建project django-ad ...
- Hibernate 一次查询分多次返回 避免内存溢出
public void grpcGpioDevice(StreamObserver<NI_GetAllDeviceListResponse> responseObserver, Map&l ...
- nohup使用相关知识
常规用法nohup ./abc.sh > abc.out & --输出nohup的日志到abc.outnohup ./abc.sh & ...
- [Assignment] C++2
作业要求:PAT1025 翻转链表 代码在这里
- [19/04/20-星期六] Java的动态性_字节码操作(Javassist类库(jar包),assist:帮助、援助)
一.概念 [基本] /** * */ package cn.sxt.jvm; import javassist.ClassPool; import javassist.CtClass; import ...
- 用firefox的插件下载网页中的视频
对于网页中的一些视频,直接下载不了,可以用专用下载软件下载,也可以用firefox的NetVideohunter Video Downloader插件下载网页中的视频,方便快捷. 工具/原料 fi ...
- Kali-linux使用Nessus
Nessus号称是世界上最流行的漏洞扫描程序,全世界有超过75000个组织在使用它.该工具提供完整的电脑漏洞扫描服务,并随时更新其漏洞数据库.Nessus不同于传统的漏洞扫描软件,Nessus可同时在 ...
- Kali-linux使用Maltego收集信息
Maltego是一个开源的漏洞评估工具,它主要用于论证一个网络内单点故障的复杂性和严重性.该工具能够聚集来自内部和外部资源的信息,并且提供一个清晰的漏洞分析界面.本节将使用Kali Linux操作系统 ...