将虚拟机上的linux放到U盘上

1.   将电子盘分区并格式化

##sudo fdisk /dev/sda                                             /*进入fdisk命令操作空间*/

##Command (m for help): m                             /*命令查看*/

Command action

   a   toggle a bootable flag

   b   edit bsd disklabel

   c   toggle the dos compatibility flag

   d   delete a partition                                               /*删除分区*/

   l   list known partition types

   m   print this menu

   n   add a new partition                                           /*增加分区*/

   o   create a new empty DOS partition table

   p   print the partition table                                     /*输出分区表*/

   q   quit without saving changes

   s   create a new empty Sun disklabel

   t   change a partition's system id

   u   change display/entry units

   v   verify the partition table

   w   write table to disk and exit                           

                                         /*写分区表,在对盘操作完需要此步才能效*/

   x   extra functionality (experts only)

/*先把所有的分区都删掉*/

##Command (m for help): d

Selected partition 2

##Command (m for help): p                          /*查看此时已无分区*/

Disk /dev/sda: 2055 MB, 2055208960 bytes

64 heads, 62 sectors/track, 1011 cylinders

Units = cylinders of 3968 * 512 = 2031616 bytes

Disk identifier: 0x00000000

 

   Device Boot      Start         End      Blocks   Id  System

/*下边给磁盘增加一分区并格式化*/

##Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

##p                                                                        /*增加主分区*/

##Partition number (1-4): 1

##First cylinder (1-1011, default 1):                     /*回车默认(从那开始)*/

Using default value 1

##Last cylinder, +cylinders or +size{K,M,G} (1-1011, default 1011): 

                                                                    /*回车默认(空间大小)*/

Using default value 1011

##Command (m for help): p                                   /*此时有sda1分区*/

Disk /dev/sdb: 2055 MB, 2055208960 bytes

64 heads, 62 sectors/track, 1011 cylinders

Units = cylinders of 3968 * 512 = 2031616 bytes

Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1               1        1011     2005793   83  Linux

 

##Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

##p                                                                             /*增加主分区*/

##Partition number (1-4): 2

##First cylinder (1-1011, default 1):                          /*回车默认(从那开始)*/

Using default value 1

##Last cylinder, +cylinders or +size{K,M,G} (1-1011, default 1011):       

/*回车默认(空间大小)*/

Using default value 1011

##Command (m for help): p                                        /*此时有sda2分区*/

Disk /dev/sdb: 2055 MB, 2055208960 bytes

64 heads, 62 sectors/track, 1011 cylinders

Units = cylinders of 3968 * 512 = 2031616 bytes

Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1               1        1011     2005793   83  Linux

/dev/sda2              1        8000     2005793   83  Linux

##Command (m for help): w                                    /*最后写入分区表*/

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

##sudo mkfs.ext3 -n disk /dev/sda1                   /*格式化*/

##sudo mkfs.ext3 -n disk /dev/sda2                   /*格式化*/

   2.   将电子盘的2个分区挂载起来

     a. ##mkdri /root/boot /root/root                      /*做为挂载电子盘的节点用*/

     b. ##mount /dev/sda1 /root/boot

     c. ##mount /dev/sda2 /root/root

   3.   复制文件到电子盘中

     a.  ##cp –ra /boot      /root/boot/

     b.  ##cp –ra /bin        /root/root/

     c.  ##cp –ra /dev        /root/root/

     d.  ##cp –ra /etc        /root/root/

     e.  ##cp –ra /home      /root/root/

     f.   ##cp –ra /lib          /root/root/

     g.  ##cp –ra /media      /root/root/

     h.  ##cp –ra /mnt         /root/root/

     i.    ##cp –ra /opt        /root/root/

     j.    ##cp –ra /sbin        /root/root/

     k.  ##cp –ra /srv        /root/root/

     l.    ##cp –ra /tmp       /root/root/

     m.   ##cp –ra /usr       /root/root/

     n.  ##cp –ra /var       /root/root/

     o. ##mkdir                  /roor/root/proc              /roor/root/selinux         /roor/root/sys      

     p. ##mkdir                   /root/root/root        /root/root/boot

     q.  ##cp –ra /root/.*  /*以点开头的隐藏文件*/           /root/root/root/

   4.   修改文件

     a. ##vi /root/boot//boot/grub/grub.conf

title CentOS (2.6.18-194.el5)

                 root (hd0,0)

kernel /boot/vmlinuz-2.6.18-194.el5 ro root=/dev/sdb2

                                         /*sdb是在实体机启动时识别的电子盘标签*/

                 initrd /boot/initrd-2.6.18-194.el5.img

     b. ##vi /root/root/etc/fstab

         /dev/sdb1               /boot                   ext3    defaults       0 1

/dev/sdb2               /                      ext3    defaults        0 2

     c. ##vi /root/root/etc/selinux/config (上面已经修改过了mysql)

# disabled - SELinux is fully disabled.

SELINUX=permissive

# SELINUXTYPE= type of policy in use. Possible values are:

   5.   修改initrd.img文件

     a. 解压img文件

##mkdir initrd

##cp /boot/initrd-2.6.18-194.el5.img  initrd.img.gz

##gunzip  initrd.img.gz

##mkdir  initrd

##mv  initrd.img  initrd

##cd  initrd

##cpio  -ivmd  < initrd.img

     b. 修改img中的文件

##cd  initrd

##vi  init 修改如下:

  在所有insmod的后面加:

         echo “”Loading usb-storage.ko nidule”

         inismod /lib/usb-storage.ko

##cp /lib/moudules/2.6.18-194.l5/kernel/sound/usb/storage/usb-storage.ko  /root/init/lib/

     c. 压缩img文件

##find . | cpio -H newc -o > ../initrd.new

##cd ../

##gzip -9 initrd.new

##cp –ra initrd.new.gz /root/boot/boot/initrd-2.6.18-194.el5.img

   6.   Boot loader设置 

##grub

     a. ##root  (hd1,0)                                 /*hd1是你的电子盘在计算机上是第几块磁盘*/

Filesystem type is ext2fs, partition type 0x83

     b. ##setup (hd1)

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 (hd1)"...  15 sectors are embedded.

succeeded

Running "install /grub/stage1 (hd1) (hd1)1+15 p (hd1,0)/grub/stage2 /grub/grub.conf"... succeeded

Done.

     c. ##quit

Make electronical disk completely.

   7.   重启并用U盘引导启动

注意:你U盘的分盘要与虚拟机的分盘一致,即你虚拟机有几个分区,U盘也要有几个分区。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值