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 ...
随机推荐
- 将eChart图片利用POI导出到Excel
在使用POI进行将数据导出到Excel时, 若要将eChart在前端生成的统计图(如柱状图.折线图.饼图等)一并导出,使用POI在后台构建数据图比较复杂,因此我选择将eChart在前端的统计图的bas ...
- 10分钟开始.Net Core
.Net Core 2.0发布了,API也越来越多.此时不用.Net Core,更待何时? 安装.Net Core SDK 首先,我们当然要先装.Net Core SDK,在这里下载( ...
- oracle sql练习 菜鸟入门!
进入公司 ,首先是进行SQL培训 一下是针对oracle的emp与dept表进行的基础查询 --1.选择部门30中的所有员工: ; --2.列出所有办事员(CLERK)的姓名,编号和部门编号: sel ...
- css 笔记1
type="text/css"的作用是什么?它是CSS样式的标记.type->类型,这里是style的属性text/css ->文本/css,即css文本type=&q ...
- August 31st 2017 Week 35th Thursday
Whatever happened in the past is gone, the best is always yet to come. 无论过去发生什么,最好的永远尚未到来. Correct j ...
- Redis 拒绝连接
1.本地防火墙是否关闭 2.服务器的防火墙是否关闭 检查方法: service iptables status 查看防火墙状态 service iptables s ...
- 中间人攻击利用框架bettercap测试
0x00前言 上篇提到内网渗透很有趣,这次就从一款新工具说起: bettercap 0x01简介 bettercap可用来实现各种中间人攻击,模块化,便携.易扩展 0x02特点 提到中间人攻击,最知名 ...
- iOS NSRunloop的简单理解
最近学习了下NSRunloop. 作一下简单的理解: 1.runloop与线程的关系,每一个线程创建是都会有伴有一个runloop诞生,runloop用来接收事件源,让线程执行事件.当没有事件处理时, ...
- socket端口复用问题一二
实际上,默认的情况下,如果一个网络应用程序的一个套接字 绑定了一个端口( 占用了 8000 ),这时候,别的套接字就无法使用这个端口( 8000 ), 验证例子如下: #include <std ...
- JavaScript脚本的执行原理?
JavaScript是一种动态.弱类型.基于原型的语言,通过浏览器可以直接执行. 当浏览器遇到\<script>标记的时候,浏览器会执行之间的JavaScript代码.嵌入的js代码是顺序 ...