选择步骤1(ubuntu B)创建的磁盘;
1,搭建环境
在virtualbox创建一个Ubuntu 64的虚拟机,磁盘2G即可,其它参数默认,后称Ubuntu B;
2,挂在磁盘
在virtualbox已安装Ubuntu 16.04 server的虚拟机中(后称Ubuntu A)挂载步骤1的磁盘,步骤如下:
设置-->Storage --> Controller: SATA --> Adds Hard disk -->选择步骤1(ubuntu B)创建的磁盘;
3,磁盘分区
启动Ubuntu A,查看磁盘情况:
phoebus@ubuntu:~$ ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda5 /dev/sdb
可以看到,我们添加的Ubuntu B的磁盘在这里是/dev/sdb,我们对它进行分区(1个区):
phoebus@ubuntu:~$ sudo fdisk /dev/sdb
[sudo] password for phoebus:
Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x9dea8caa.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-4194303, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-4194303, default 4194303):
Created a new partition 1 of type 'Linux' and of size 2 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
phoebus@ubuntu:~$
4,安装grub
a,把/dev/sdb1格式化为ext4
phoebus@ubuntu:~$ sudo mkfs.ext4 /dev/sdb1
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 524032 4k blocks and 131072 inodes
Filesystem UUID: e5b6c7af-d316-4082-99a4-7f322363c0e6
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
phoebus@ubuntu:~$
b,挂载/dev/sdb1到/mnt
sudo mount /dev/sdb1 /mnt/
c,安装grub
phoebus@ubuntu:~$ sudo grub-install --root-directory=/mnt /dev/sdb
Installing for i386-pc platform.
Installation finished. No error reported.
phoebus@ubuntu:~$
5,添加grub.cfg
a,复制ubuntu的grub.cfg
sudo cp /boot/grub/grub.cfg /mnt/boot/grub/
b,修改uuid
查看uuid
phoebus@ubuntu:~$ ll /dev/disk/by-uuid/
total 0
drwxr-xr-x 2 root root 100 Jun 24 11:35 ./
drwxr-xr-x 5 root root 100 Jun 24 11:27 ../
lrwxrwxrwx 1 root root 10 Jun 24