百度智能云

All Product Document

          Cloud Compute Service

          Create a Linux Image Based on the Local System

          Application Scenarios

          It is mainly used to create custom images meeting platform requirements locally as expected by the user.

          This article introduces how to produce custom images based on the ubuntu 16.04 system.

          Operation Steps

          Preparation

          As the imported images required by Baidu AI Cloud are limited in format, drive and other aspects. Please have a detailed understanding of Image Import Limit and pre-configure the system if necessary. Baidu AI Cloud provides the Image Testing Tool to help you quickly check the related configurations.

          Search the system partition

          A complete Linux system image should at least contain mbr (Master Boot Record), root partition (/place for mount directories, including the file system body). Or we can't enter the system.

          If the two partitions are included: boot partition (mounting/boot directory, saving the files of system kernel and other startup processes) and home partition (mounting/home directory, including user directory), they should be copied at the same time.

          Execute the mount command to view the mount status:

              sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) 
              proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) 
              udev on /dev type devtmpfs (rw,nosuid,relatime,size=1002644k,nr_inodes=250661,mode=755) 
              devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000) 
              tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=204784k,mode=755) 
              /dev/sda1 on / type ext4 (rw,relatime,data=ordered) 
              securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime) 
              tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev) 
              tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k) 
              tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755) 
              cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/lib/systemd/systemd-cgroups-agent,name=systemd) 
              pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime) 
              cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset) 
              cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb) 
              cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio) 
              cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices) 
              cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct) 
              cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio) 
              cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer) 
              cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory) 
              cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event) 
              cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids) 
              mqueue on /dev/mqueue type mqueue (rw,relatime) 
              hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime) 
              debugfs on /sys/kernel/debug type debugfs (rw,relatime) 
              systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=35,pgrp=1,timeout=0,minproto=5,maxproto=5,direct) 
              fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime) 
              lxcfs on /var/lib/lxcfs type fuse.lxcfs (rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other) 
              tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=204784k,mode=700) 

          We can see that the boot and home partitions are not included. We can copy mbr and root partition only, namely, copy/dev/sda.

          Make an image

          1.Use qmeu-img to produce image:

          If there is no qemu-img command, run the following command to install:

              apt-get update 
              apt-get install qemu 

          Execute the following command to generate an image, and test.qcow2 is the generated image. The image is stored under a new disk or network directory/mnt/test/ for saving. - O specifies the output image format (you can select the format type according to requirements, including qcow2, vpc, vmdk, raw formats. Baidu AI Cloud currently only supports the import of images of raw and qcow2 formats).

          `qemu-img convert -f raw -O qcow2 /dev/sda /mnt/test/test.qcow2` 

          The operation takes several minutes. Then execute the following command for compatibility conversion.

          qemu-img amend -f qcow2 -o compat=0.10 test.qcow2

          Use qemu-img info to view the image information as below:

              image: test.qcow2 
              file format: qcow2 
              virtual size: 40G (42949672960 bytes) 
              disk size: 3.6G 
              cluster_size: 65536
              Format specific information: 
              compat: 0.10 
              refcount bits: 16 

          2.Use dd command to produce image:

          Execute the following command to copy the disk.

          dd if=/dev/sda of=/mnt/test/test.img bs=1M

          The above command is to copy the whole disk. If you want to copy one partition only, you can use the count parameter to specify: (and the value of bs * the value of count = the size to be copied)

          dd if=/dev/sda of=/mnt/test/test.img bs=1M count=1024

          It takes a few minutes. Then use qemu-img info to view the image information:

          image: test.img 
          file format: raw 
          virtual size: 40G (42949672960 bytes) 
          disk size: 40G 

          Format conversion

          Baidu AI Cloud currently supports the import of images of raw and qcow2 formats. If other formats such as vmdk and vpc are used, please refer to Format Conversion for conversion.

          Follow-up operation

          The generated image can be imported into Baidu AI Cloud to further create an instance.

          Previous
          Service Agreement for Baidu AI Cloud Image
          Next
          Network