linux不重启挂载磁盘安装grub
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux不重启挂载磁盘安装grub相关的知识,希望对你有一定的参考价值。
挂载、分区、grub
通过给一块新磁盘安装grub回顾磁盘挂载、分区文件系统创建等操作:
该实验基于(CtonOS6.8;kernel:2.6.32-642.15.1.el6.x86_64)
1.通过VMware Workstationg添加一块磁盘(SCSI);
2./sys下SCSI扫描,查看主机总线号,磁盘肯定是有总线连接着:
1 [[email protected] Test]# ls /sys/class/scsi_host/ 2 host0 host1 host2 3 [[email protected] Test]# echo "- - -" > /sys/class/scsi_host/host0/scan 4 [[email protected] Test]# echo "- - -" > /sys/class/scsi_host/host1/scan 5 [[email protected] Test]# echo "- - -" > /sys/class/scsi_host/host2/scan 6 [[email protected] Test]# fdisk -l
3.创建分区:
1 [[email protected] 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 to 10 switch off the mode (command ‘c‘) and change display units to 11 sectors (command ‘u‘). 12 13 Command (m for help): n 14 Command action 15 e extended 16 p primary partition (1-4) 17 p 18 Partition number (1-4): 1 19 First cylinder (1-2610, default 1): 20 Using default value 1 21 Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +200M 22 23 Command (m for help): n 24 Command action 25 e extended 26 p primary partition (1-4) 27 p 28 Partition number (1-4): 2 29 First cylinder (27-2610, default 27): 30 Using default value 27 31 Last cylinder, +cylinders or +size{K,M,G} (27-2610, default 2610): +2G 32 33 Command (m for help): t 34 Partition number (1-4): 2 35 Hex code (type L to list codes): 82 36 Changed system type of partition 2 to 82 (Linux swap / Solaris) 37 38 Command (m for help): n 39 Command action 40 e extended 41 p primary partition (1-4) 42 p 43 Partition number (1-4): 3 44 First cylinder (289-2610, default 289): 45 Using default value 289 46 Last cylinder, +cylinders or +size{K,M,G} (289-2610, default 2610): +5G 47 48 Command (m for help): w 49 The partition table has been altered! 50 51 Calling ioctl() to re-read partition table. 52 Syncing disks. 53 [[email protected] Test]# partx -a /dev/sdb 54 BLKPG: Device or resource busy 55 error adding partition 1 56 BLKPG: Device or resource busy 57 error adding partition 2 58 BLKPG: Device or resource busy 59 error adding partition 3 60 [roo[email protected] Test]# cat /proc/partitions 61 major minor #blocks name 62 63 8 0 125829120 sda 64 8 1 204800 sda1 65 8 2 5242880 sda2 66 8 3 2097152 sda3 67 8 4 1 sda4 68 8 5 10487075 sda5 69 8 6 5253223 sda6 70 8 7 8393931 sda7 71 8 16 20971520 sdb 72 8 17 208813 sdb1 73 8 18 2104515 sdb2 74 8 19 5253255 sdb3
4.创建文件系统:
1 [[email protected] Test]# mke2fs -t ext4 /dev/sdb1 2 [[email protected] Test]# mke2fs -t ext4 /dev/sdb3 3 [[email protected] Test]# mkswap /dev/sdb2
5.挂载分区:
1 [[email protected] ~]# mkdir /mnt/boot 2 [[email protected] ~]# mount /dev/sdb1 /mnt/boot/ 3 [[email protected] ~]# ls /mnt/boot/ 4 lost+found
6.安装grub:
1 [[email protected] ~]# 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/sda 10 (hd1) /dev/sdb 11 [[email protected] ~]# ls /mnt/boot/ 12 grub lost+found 13 [[email protected] ~]# ls /mnt/boot/grub/ 14 device.map ffs_stage1_5 minix_stage1_5 stage2 xfs_stage1_5 15 e2fs_stage1_5 iso9660_stage1_5 reiserfs_stage1_5 ufs2_stage1_5 16 fat_stage1_5 jfs_stage1_5 stage1 vstafs_stage1_5
7.配置grub:
1 [[email protected] ~]# cp /boot/vmlinuz-2.6.32-642.el6.x86_64 /mnt/boot/vmlinuz 2 [[email protected] ~]# cp /boot/initramfs-2.6.32-642.el6.x86_64.img /mnt/boot/initramfs.img 3 [[email protected] ~]# 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 [[email protected] ~]# mkdir /mnt/sysroot 2 [[email protected] ~]# mount /dev/sdb3 /mnt/sysroot/ 3 [[email protected] ~]# cd /mnt/sysroot/ 4 [[email protected] sysroot]# mkdir -p etc bin sbin lib lib64 dev proc sys tmp var usr home mnt media 5 [[email protected] sysroot]# ls 6 bin dev etc home lib lib64 lost+found media mnt proc sbin sys tmp usr var 7 [[email protected] sysroot]# cp /bin/bash /mnt/sysroot/bin/ (复制程序bash) 8 [[email protected] 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 [[email protected] sysroot]# cp /lib64/libtinfo.so.5 /mnt/sysroot/lib64/ 15 [[email protected] sysroot]# cp /lib64/libdl.so.2 /mnt/sysroot/lib64/ 16 [[email protected] sysroot]# cp /lib64/libc.so.6 /mnt/sysroot/lib64/ 17 [[email protected] sysroot]# cp /lib64/ld-linux-x86-64.so.2 /mnt/sysroot/lib64/ 18 [[email protected] sysroot]# cd 19 [[email protected] ~]# chroot /mnt/sysroot/ (切换根) 20 bash-4.1# 21 bash-4.1# exit 22 exit
9.编辑启动init为/bin/bash:
[[email protected] ~]# vim /mnt/boot/grub/grub.conf default=0 timeout=5 title CentOS (Express) root (hd0,0) kernel /vmlinuz ro root=/dev/sda3 init=/bin/bash initrd /initramfs.img [[email protected] ~]# sync
note:该操作把bash当做第一个用户空间运行进程启动;
note:sync命令的作用是,将有关文件系统的存储器常驻信息送入物理介质内。在暂停系统之前,比如要重新启动机器,一定要去执行sync命令。
以上是关于linux不重启挂载磁盘安装grub的主要内容,如果未能解决你的问题,请参考以下文章