|
| 1 | +--- |
| 2 | +title: How to custom partition layout |
| 3 | +weight: 305 |
| 4 | +--- |
| 5 | + |
| 6 | +When users use the default `ros install`, ROS will automatically create one partition on the root disk. |
| 7 | +It will be the only partition with the label RANCHER_STATE. |
| 8 | +But sometimes users want to be able to customize the root disk partition to isolate the data. |
| 9 | + |
| 10 | +> The following defaults to MBR mode, GPT mode has not been tested. |
| 11 | +
|
| 12 | +### Use RANCHER_STATE partition |
| 13 | + |
| 14 | +As mentioned above, the default mode is that ROS will automatically create one partition with the label RANCHER_STATE. |
| 15 | + |
| 16 | +In addition, we can have other partitions, e.g.: two partitions, one is RANCHER_STATE and the other is a normal partition. |
| 17 | + |
| 18 | +First boot a ROS instance from ISO, then manually format and partition `/dev/sda` , the reference configuration is as follows: |
| 19 | + |
| 20 | +``` |
| 21 | +[root@rancher oem]# fdisk -l |
| 22 | +Disk /dev/sda: 5 GiB, 5377622016 bytes, 10503168 sectors |
| 23 | +Units: sectors of 1 * 512 = 512 bytes |
| 24 | +Sector size (logical/physical): 512 bytes / 512 bytes |
| 25 | +I/O size (minimum/optimal): 512 bytes / 512 bytes |
| 26 | +Disklabel type: dos |
| 27 | +Disk identifier: 0x9fff87e9 |
| 28 | +
|
| 29 | +Device Boot Start End Sectors Size Id Type |
| 30 | +/dev/sda1 * 2048 7503167 7501120 3.6G 83 Linux |
| 31 | +/dev/sda2 7503872 10503167 2999296 1.4G 83 Linux |
| 32 | +
|
| 33 | +[root@rancher oem]# blkid |
| 34 | +/dev/sda1: LABEL="RANCHER_STATE" UUID="512f212b-3130-458e-a2d1-1d601c34d4e4" TYPE="ext4" PARTUUID="9fff87e9-01" |
| 35 | +/dev/sda2: UUID="3828e3ac-b825-4898-9072-45da9d37c2a6" TYPE="ext4" PARTUUID="9fff87e9-02" |
| 36 | +``` |
| 37 | + |
| 38 | +Then install ROS to the disk with `ros install -t noformat -d /dev/sda ...`. |
| 39 | + |
| 40 | +After rebooting, you can use `/dev/sda2`. For example, changing the data root of user-docker: |
| 41 | + |
| 42 | +``` |
| 43 | +$ ros config set mounts '[["/dev/sda2","/mnt/s","ext4",""]]’ |
| 44 | +$ ros config set rancher.docker.graph /mnt/s |
| 45 | +$ reboot |
| 46 | +``` |
| 47 | + |
| 48 | +> In this mode, the RANCHER_STATE partition capacity cannot exceed 3.8GiB, otherwise the bootloader may not recognize the boot disk. This is the test result on VirtualBox. |
| 49 | +
|
| 50 | +### Use RANCHER_BOOT partition |
| 51 | + |
| 52 | +When you only use the RRACHER_STATE partition, the bootloader will be installed in the `/boot` directory. |
| 53 | + |
| 54 | +``` |
| 55 | +$ system-docker run -it --rm -v /:/host alpine |
| 56 | +ls /host/boot |
| 57 | +... |
| 58 | +``` |
| 59 | + |
| 60 | +If you want to use a separate boot partition, you also need to boot a ROS instance from ISO, then manually format and partition `/dev/sda`: |
| 61 | + |
| 62 | +``` |
| 63 | +[root@rancher rancher]# fdisk -l |
| 64 | +Disk /dev/sda: 5 GiB, 5377622016 bytes, 10503168 sectors |
| 65 | +Units: sectors of 1 * 512 = 512 bytes |
| 66 | +Sector size (logical/physical): 512 bytes / 512 bytes |
| 67 | +I/O size (minimum/optimal): 512 bytes / 512 bytes |
| 68 | +Disklabel type: dos |
| 69 | +Disk identifier: 0xe32b3025 |
| 70 | +
|
| 71 | +Device Boot Start End Sectors Size Id Type |
| 72 | +/dev/sda1 2048 2503167 2501120 1.2G 83 Linux |
| 73 | +/dev/sda2 2504704 7503167 4998464 2.4G 83 Linux |
| 74 | +/dev/sda3 7503872 10503167 2999296 1.4G 83 Linux |
| 75 | +
|
| 76 | +[root@rancher rancher]# mkfs.ext4 -L RANCHER_BOOT /dev/sda1 |
| 77 | +[root@rancher rancher]# mkfs.ext4 -L RANCHER_STATE /dev/sda2 |
| 78 | +[root@rancher rancher]# mkfs.ext4 /dev/sda3 |
| 79 | +
|
| 80 | +[root@rancher rancher]# blkid |
| 81 | +/dev/sda1: LABEL="RANCHER_BOOT" UUID="43baeac3-11f3-4eed-acfa-64daf66b26c8" TYPE="ext4" PARTUUID="e32b3025-01" |
| 82 | +/dev/sda2: LABEL="RANCHER_STATE" UUID="16f1ecef-dbe4-42a2-87a1-611939684e0b" TYPE="ext4" PARTUUID="e32b3025-02" |
| 83 | +/dev/sda3: UUID="9f34e161-0eee-48f9-93de-3b7c54dea437" TYPE="ext4" PARTUUID="c9b8f181-03" |
| 84 | +``` |
| 85 | + |
| 86 | +Then install ROS to the disk with `ros install -t noformat -d /dev/sda ...`. |
| 87 | + |
| 88 | +After rebooting, you can check the boot partition: |
| 89 | + |
| 90 | +``` |
| 91 | +[root@rancher rancher]# mkdir /boot |
| 92 | +[root@rancher rancher]# mount /dev/sda1 /boot |
| 93 | +[root@rancher rancher]# ls -ahl /boot/ |
| 94 | +total 175388 |
| 95 | +drwxr-xr-x 4 root root 4.0K Sep 27 03:35 . |
| 96 | +drwxr-xr-x 1 root root 4.0K Sep 27 03:38 .. |
| 97 | +-rw-r--r-- 1 root root 24 Sep 27 03:05 append |
| 98 | +-rw-r--r-- 1 root root 128 Sep 27 03:35 global.cfg |
| 99 | +-rw-r--r-- 1 root root 96.8M Sep 27 03:05 initrd |
| 100 | +``` |
| 101 | + |
| 102 | +If you are not using the first partition as a BOOT partition, you need to set BOOT flag via the fdisk tool. |
| 103 | + |
| 104 | +> In this mode, the RANCHER_BOOT partition capacity cannot exceed 3.8GiB, otherwise the bootloader may not recognize the boot disk. This is the test result on VirtualBox. |
| 105 | +
|
| 106 | +### Use RANCHER_OEM partition |
| 107 | + |
| 108 | +If you format any partition with the label RANCHER_OEM, ROS will mount this partition to `/usr/share/ros/oem`: |
| 109 | + |
| 110 | +``` |
| 111 | +[root@rancher rancher]# blkid |
| 112 | +/dev/sda2: LABEL="RANCHER_OEM" UUID="4f438455-63a3-4d29-ac90-50adbeced412" TYPE="ext4" PARTUUID="9fff87e9-02" |
| 113 | +
|
| 114 | +[root@rancher rancher]# df -hT | grep sda2 |
| 115 | +/dev/sda2 ext4 1.4G 4.3M 1.3G 0% /usr/share/ros/oem |
| 116 | +``` |
| 117 | + |
| 118 | +Currently, this OEM directory is hardcoded and not configurable. |
| 119 | + |
| 120 | +### Use RANCHER_SWAP partition |
| 121 | + |
| 122 | +Suppose you have a partition(`/dev/sda2`) and you want to use it as a SWAP partition: |
| 123 | + |
| 124 | +``` |
| 125 | +$ mkswap -L RANCHER_SWAP /dev/sda2 |
| 126 | +
|
| 127 | +$ blkid |
| 128 | +/dev/sda1: LABEL="RANCHER_STATE" UUID="512f212b-3130-458e-a2d1-1d601c34d4e4" TYPE="ext4" PARTUUID="9fff87e9-01" |
| 129 | +/dev/sda2: LABEL="RANCHER_SWAP" UUID="772b6e76-f89c-458e-931e-10902d78d3e4" TYPE="swap" PARTUUID="9fff87e9-02" |
| 130 | +``` |
| 131 | + |
| 132 | +After you install ROS to the disk, you can add the `runcmd` to enable SWAP: |
| 133 | + |
| 134 | +``` |
| 135 | +runcmd: |
| 136 | +- swapon -L RANCHER_SWAP |
| 137 | +``` |
| 138 | + |
| 139 | +Then check the memory information: |
| 140 | + |
| 141 | +``` |
| 142 | +[root@rancher rancher]# free -m |
| 143 | + total used free shared buffers cached |
| 144 | +Mem: 1996 774 1221 237 20 614 |
| 145 | +-/+ buffers/cache: 139 1856 |
| 146 | +Swap: 487 0 487 |
| 147 | +``` |
0 commit comments