linux不重启挂载磁盘安装grub
linux不重启挂载磁盘安装grub
挂载、分区、grub
通过给一块新磁盘安装grub回顾磁盘挂载、分区文件系统创建等操作:
该实验基于(CtonOS6.8;kernel:2.6.32-642.15.1.el6.x86_64)
1.通过VMware Workstationg添加一块磁盘(SCSI);
2./sys下SCSI扫描,查看主机总线号,磁盘肯定是有总线连接着:
1 [root@cl Test]# ls /sys/class/scsi_host/2 host0 host1 host23 [root@cl Test]# echo "- - -" > /sys/class/scsi_host/host0/scan4 [root@cl Test]# echo "- - -" > /sys/class/scsi_host/host1/scan5 [root@cl Test]# echo "- - -" > /sys/class/scsi_host/host2/scan6 [root@cl Test]# fdisk -l
3.创建分区:
1 [root@cl Test]# fdisk /dev/sdb 2 Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel 3 Building a new DOS disklabel with disk identifier 0xa61749e4. 4 Changes will remain in memory only, until you decide to write them. 5 After that, of course, the previous content won't be recoverable. 6 7 Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) 8 9 WARNING: DOS-compatible mode is deprecated. It's strongly recommended to10 switch off the mode (command 'c') and change display units to11 sectors (command 'u').12 13 Command (m for help): n14 Command action15 e extended16 p primary partition (1-4)17 p18 Partition number (1-4): 119 First cylinder (1-2610, default 1): 20 Using default value 121 Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +200M22 23 Command (m for help): n24 Command action25 e extended26 p primary partition (1-4)27 p28 Partition number (1-4): 229 First cylinder (27-2610, default 27): 30 Using default value 2731 Last cylinder, +cylinders or +size{K,M,G} (27-2610, default 2610): +2G32 33 Command (m for help): t34 Partition number (1-4): 235 Hex code (type L to list codes): 8236 Changed system type of partition 2 to 82 (Linux swap / Solaris)37 38 Command (m for help): n39 Command action40 e extended41 p primary partition (1-4)42 p43 Partition number (1-4): 344 First cylinder (289-2610, default 289): 45 Using default value 28946 Last cylinder, +cylinders or +size{K,M,G} (289-2610, default 2610): +5G47 48 Command (m for help): w49 The partition table has been altered!50 51 Calling ioctl() to re-read partition table.52 Syncing disks.53 [root@cl Test]# partx -a /dev/sdb54 BLKPG: Device or resource busy55 error adding partition 156 BLKPG: Device or resource busy57 error adding partition 258 BLKPG: Device or resource busy59 error adding partition 360 [root@cl Test]# cat /proc/partitions 61 major minor #blocks name62 63 8 0 125829120 sda64 8 1 204800 sda165 8 2 5242880 sda266 8 3 2097152 sda367 8 4 1 sda468 8 5 10487075 sda569 8 6 5253223 sda670 8 7 8393931 sda771 8 16 20971520 sdb72 8 17 208813 sdb173 8 18 2104515 sdb274 8 19 5253255 sdb3
4.创建文件系统:
1 [root@cl Test]# mke2fs -t ext4 /dev/sdb12 [root@cl Test]# mke2fs -t ext4 /dev/sdb33 [root@cl Test]# mkswap /dev/sdb2
5.挂载分区:
1 [root@cl ~]# mkdir /mnt/boot2 [root@cl ~]# mount /dev/sdb1 /mnt/boot/3 [root@cl ~]# ls /mnt/boot/4 lost+found
6.安装grub:
1 [root@cl ~]# grub-install --root-directory=/mnt /dev/sdb1 (指明/的位置在mnt下) 2 Probing devices to guess BIOS drives. This may take a long time. 3 Installation finished. No error reported. 4 This is the contents of the device map /mnt/boot/grub/device.map. 5 Check if this is correct or not. If any of the lines is incorrect, 6 fix it and re-run the script `grub-install'. 7 8 (fd0) /dev/fd0 9 (hd0) /dev/sda10 (hd1) /dev/sdb11 [root@cl ~]# ls /mnt/boot/12 grub lost+found13 [root@cl ~]# ls /mnt/boot/grub/14 device.map ffs_stage1_5 minix_stage1_5 stage2 xfs_stage1_515 e2fs_stage1_5 iso9660_stage1_5 reiserfs_stage1_5 ufs2_stage1_516 fat_stage1_5 jfs_stage1_5 stage1 vstafs_stage1_5
7.配置grub:
1 [root@cl ~]# cp /boot/vmlinuz-2.6.32-642.el6.x86_64 /mnt/boot/vmlinuz2 [root@cl ~]# cp /boot/initramfs-2.6.32-642.el6.x86_64.img /mnt/boot/initramfs.img3 [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.创建根文件目录:
1 [root@cl ~]# mkdir /mnt/sysroot 2 [root@cl ~]# mount /dev/sdb3 /mnt/sysroot/ 3 [root@cl ~]# cd /mnt/sysroot/ 4 [root@cl sysroot]# mkdir -p etc bin sbin lib lib64 dev proc sys tmp var usr home mnt media 5 [root@cl sysroot]# ls 6 bin dev etc home lib lib64 lost+found media mnt proc sbin sys tmp usr var 7 [root@cl sysroot]# cp /bin/bash /mnt/sysroot/bin/ (复制程序bash) 8 [root@cl sysroot]# ldd /bin/bash (查看程序依赖库文件) 9 linux-vdso.so.1 => (0x00007fffd39f9000)10 libtinfo.so.5 => /lib64/libtinfo.so.5 (0x0000003cc3800000)11 libdl.so.2 => /lib64/libdl.so.2 (0x0000003cc1c00000)12 libc.so.6 => /lib64/libc.so.6 (0x0000003cc2000000)13 /lib64/ld-linux-x86-64.so.2 (0x0000003cc1800000)14 [root@cl sysroot]# cp /lib64/libtinfo.so.5 /mnt/sysroot/lib64/15 [root@cl sysroot]# cp /lib64/libdl.so.2 /mnt/sysroot/lib64/16 [root@cl sysroot]# cp /lib64/libc.so.6 /mnt/sysroot/lib64/17 [root@cl sysroot]# cp /lib64/ld-linux-x86-64.so.2 /mnt/sysroot/lib64/18 [root@cl sysroot]# cd19 [root@cl ~]# chroot /mnt/sysroot/ (切换根)20 bash-4.1# 21 bash-4.1# exit22 exit
9.编辑启动init为/bin/bash:
[root@cl ~]# vim /mnt/boot/grub/grub.conf default=0timeout=5title CentOS (Express)root (hd0,0)kernel /vmlinuz ro root=/dev/sda3 init=/bin/bashinitrd /initramfs.img [root@cl ~]# sync
note:该操作把bash当做第一个用户空间运行进程启动;
note:sync命令的作用是,将有关文件系统的存储器常驻信息送入物理介质内。在暂停系统之前,比如要重新启动机器,一定要去执行sync命令。
补充:模拟破坏和修复方法一:
1 [root@cl ~]# dd if=/dev/sda of=/root/mbr.bak count=1 bs=512 2 1+0 records in 3 1+0 records out 4 512 bytes (512 B) copied, 0.000155983 s, 3.3 MB/ 5 [root@cl ~]# dd if=/dev/zero of=/dev/sda bs=200 count=1 6 1+0 records in 7 1+0 records out 8 200 bytes (200 B) copied, 0.000307597 s, 650 kB/s 9 [root@cl ~]# sync10 [root@cl ~]# grub-install --root-directory=/ /dev/sda11 Installation finished. No error reported.12 This is the contents of the device map //boot/grub/device.map.13 Check if this is correct or not. If any of the lines is incorrect,14 fix it and re-run the script `grub-install'.15 16 # this device map was generated by anaconda17 (hd0) /dev/sda
模拟破坏和修复方法二:
1 [root@cl ~]# dd if=/dev/zero of=/dev/sda bs=200 count=1 2 1+0 records in 3 1+0 records out 4 200 bytes (200 B) copied, 0.0170366 s, 11.7 kB/s 5 [root@cl ~]# sync 6 [root@cl ~]# grub 7 Probing devices to guess BIOS drives. This may take a long time. 8 9 10 GNU GRUB version 0.97 (640K lower / 3072K upper memory)11 12 [ Minimal BASH-like line editing is supported. For the first word, TAB13 lists possible command completions. Anywhere else TAB lists the possible14 completions of a device/filename.]15 grub> root (hd0,0)16 root (hd0,0)17 Filesystem type is ext2fs, partition type 0x8318 grub> setup (hd0)19 setup (hd0)20 Checking if "/boot/grub/stage1" exists... no21 Checking if "/grub/stage1" exists... yes22 Checking if "/grub/stage2" exists... yes23 Checking if "/grub/e2fs_stage1_5" exists... yes24 Running "embed /grub/e2fs_stage1_5 (hd0)"... 27 sectors are embedded.25 succeeded26 Running "install /grub/stage1 (hd0) (hd0)1+27 p (hd0,0)/grub/stage2 /grub/grub.conf"... succeeded27 Done.28 grub> quit29 quit30 [root@cl ~]# sync
模拟破坏和修复方法三:(重启后救援模式修复)
重启:
[root@cl ~]# dd if=/dev/zero of=/dev/sda bs=200 count=11+0 records in1+0 records out200 bytes (200 B) copied, 0.000283877 s, 705 kB/s [root@cl ~]# sync[root@cl ~]# rebootBroadcast message from root@cl.y.dba(/dev/pts/0) at 15:21 ...The system is going down for reboot NOW!
修复:1.选择镜像光盘:
2.重启系统选择救援模式:
3.进入shell:
4.修复并重启:
转载于:https://blog.51cto.com/lqs001/1961256
linux不重启挂载磁盘安装grub相关推荐
- Linux记录-重启后磁盘丢失问题解决方案
Linux记录-重启后磁盘丢失问题解决方案 参考文章: (1)Linux记录-重启后磁盘丢失问题解决方案 (2)https://www.cnblogs.com/xinfang520/p/7999405 ...
- linux利用vi挂载磁盘,如何在linux环境上挂载磁盘
1.1 fdisk -l 命令 查看可用的磁盘信息(如果没有显示可用的磁盘,可重启一下主机:reboot) 1.2 df –h 命令 可查看已挂的磁盘情况 1.3 pvs ...
- linux挂载1t硬盘,linux如何挂载硬盘linux服务器上挂载磁盘(图文)
博主最近在研究服务器运维,由于Linux服务器相对比较困难,所以博主对她情有独钟.而window服务器几乎跟我们平常使用的电脑一样,相对简单感觉索然无味.下面正式进入主题教大家linux如何挂载硬盘. ...
- linux如何挂载硬盘linux服务器上挂载磁盘(图文详解)
博主最近在研究服务器运维,由于Linux服务器相对比较困难,所以博主对她情有独钟.而window服务器几乎跟我们平常使用的电脑一样,相对简单感觉索然无味.下面正式进入主题教大家linux如何挂载硬盘. ...
- linux查看已挂载磁盘,linux查看与挂载磁盘
HQY (1) 用命令fdisk -l查看磁盘 (2) 新建一个文件夹,作为将来访问vdb1的标识 mkdir /data1 (3) 查看磁盘vdb1的文件系统类型 df -T (4) 挂 ...
- linux yum自动挂载_LINUX6安装YUM仓库和实现开机自动挂载
# LINUX6安装YUM仓库和实现开机自动挂载 ---------------------------------安装环境------------------------------- Redhat ...
- 红旗Linux启动修复,红旗linux系统,重启后就进入grub,不能开启Linux,请教高手!!!!!!...
首先还是不确定你出错之前对系统做了什么操作,无法对症下药,可加q 954334555讨论! 另外为你找了一篇比较实用的博文,希望能解决你的问题!!! Grub2不同问题的几种修复方法 1. Grub ...
- Python计算Linux服务器所有挂载磁盘的使用率
0. 依赖包 import os import commands from collections import namedtuple 1. 获取磁盘挂载点路径 def getPath():outpu ...
- Linux 重命名挂载磁盘
1.查看当前所有分区 sudo fdisk -l 2.先卸载要修改名称的分区: sudo umount /dev/sda5 3.修改名称: sudo ntfslabel /dev/sda5 music ...
最新文章
- Linux系统下载linux系统源码
- r语言必学的十个包肖凯_家长专栏自闭症儿童语言康复训练
- python中re模块_python中re模块的使用以及一些正则表达式的总结
- 入门干货之用DVG打造你的项目主页-Docfx、Vs、Github
- 第三章 使用单元测试测试简单的首页
- hadoop--Shuffle机制
- 萌新的Python练习菜鸟100例(十一)生兔子练习
- 读javascript高级程序设计04-canvas
- Oracle数据库案例整理-Oracle系统执行时故障-内存过少导致分配共享内存失败
- java 获取当前年_java中的反射(三) - kelexin
- 原子操作--sync/atomic的用法
- 隐藏于世的网站内页seo优化技术
- 开关电源matlab仿真,用数学方法建立一种开关电源全系统的仿真模型
- java魂斗罗_魂斗罗java源代码分享
- 弘辽科技:拼多多新店推广的5个方法是什么?怎么推广?
- 产品读书《极简生活法则》
- Jboss RichFaces + Skin的简单运用示例代码
- flash actionscript MovieClip(电影剪辑)控制
- Python——调用百度AI实现图片上文字识别
- 接手了屎一样的代码 怎么办?