1 /* guestfish - the filesystem interactive shell
2 * Copyright (C) 2010 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 prep_prelaunch_bootroot (const char *filename, prep_data *data)
33 if (alloc_disk (filename, data->params[2], 0, 1) == -1)
34 prep_error (data, filename, _("failed to allocate disk"));
38 prep_postlaunch_bootroot (const char *filename, prep_data *data, const char *device)
41 if (parse_size (data->params[3], &bootsize) == -1)
42 prep_error (data, filename, _("could not parse boot size"));
44 int sector = guestfs_blockdev_getss (g, device);
46 prep_error (data, filename, _("failed to get sector size of disk: %s"),
47 guestfs_last_error (g));
49 if (guestfs_part_init (g, device, data->params[4]) == -1)
50 prep_error (data, filename, _("failed to partition disk: %s"),
51 guestfs_last_error (g));
53 off_t lastbootsect = 64 + bootsize/sector - 1;
54 if (guestfs_part_add (g, device, "primary", 64, lastbootsect) == -1)
55 prep_error (data, filename, _("failed to add boot partition: %s"),
56 guestfs_last_error (g));
58 if (guestfs_part_add (g, device, "primary", lastbootsect+1, -64) == -1)
59 prep_error (data, filename, _("failed to add root partition: %s"),
60 guestfs_last_error (g));
63 if (asprintf (&part, "%s1", device) == -1) {
67 if (guestfs_mkfs (g, data->params[0], part) == -1)
68 prep_error (data, filename, _("failed to create boot filesystem: %s"),
69 guestfs_last_error (g));
72 if (asprintf (&part, "%s2", device) == -1) {
76 if (guestfs_mkfs (g, data->params[1], part) == -1)
77 prep_error (data, filename, _("failed to create root filesystem: %s"),
78 guestfs_last_error (g));
83 prep_prelaunch_bootrootlv (const char *filename, prep_data *data)
85 if (vg_lv_parse (data->params[0], NULL, NULL) == -1)
86 prep_error (data, filename, _("incorrect format for LV name, use '/dev/VG/LV'"));
88 if (alloc_disk (filename, data->params[3], 0, 1) == -1)
89 prep_error (data, filename, _("failed to allocate disk"));
93 prep_postlaunch_bootrootlv (const char *filename, prep_data *data, const char *device)
96 if (parse_size (data->params[4], &bootsize) == -1)
97 prep_error (data, filename, _("could not parse boot size"));
99 int sector = guestfs_blockdev_getss (g, device);
101 prep_error (data, filename, _("failed to get sector size of disk: %s"),
102 guestfs_last_error (g));
104 if (guestfs_part_init (g, device, data->params[5]) == -1)
105 prep_error (data, filename, _("failed to partition disk: %s"),
106 guestfs_last_error (g));
108 off_t lastbootsect = 64 + bootsize/sector - 1;
109 if (guestfs_part_add (g, device, "primary", 64, lastbootsect) == -1)
110 prep_error (data, filename, _("failed to add boot partition: %s"),
111 guestfs_last_error (g));
113 if (guestfs_part_add (g, device, "primary", lastbootsect+1, -64) == -1)
114 prep_error (data, filename, _("failed to add root partition: %s"),
115 guestfs_last_error (g));
119 if (vg_lv_parse (data->params[0], &vg, &lv) == -1)
120 prep_error (data, filename, _("incorrect format for LV name, use '/dev/VG/LV'"));
123 if (asprintf (&part, "%s1", device) == -1) {
127 if (guestfs_mkfs (g, data->params[1], part) == -1)
128 prep_error (data, filename, _("failed to create boot filesystem: %s"),
129 guestfs_last_error (g));
132 if (asprintf (&part, "%s2", device) == -1) {
136 if (guestfs_pvcreate (g, part) == -1)
137 prep_error (data, filename, _("failed to create PV: %s: %s"),
138 part, guestfs_last_error (g));
140 char *parts[] = { part, NULL };
141 if (guestfs_vgcreate (g, vg, parts) == -1)
142 prep_error (data, filename, _("failed to create VG: %s: %s"),
143 vg, guestfs_last_error (g));
145 /* Create the smallest possible LV, then resize it to fill
146 * all available space.
148 if (guestfs_lvcreate (g, lv, vg, 1) == -1)
149 prep_error (data, filename, _("failed to create LV: /dev/%s/%s: %s"),
150 vg, lv, guestfs_last_error (g));
151 if (guestfs_lvresize_free (g, data->params[0], 100) == -1)
152 prep_error (data, filename,
153 _("failed to resize LV to full size: %s: %s"),
154 data->params[0], guestfs_last_error (g));
156 if (guestfs_mkfs (g, data->params[2], data->params[0]) == -1)
157 prep_error (data, filename, _("failed to create root filesystem: %s"),
158 guestfs_last_error (g));