]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/installer/hw.c
0025e7d7562680f0f3e5dfbda69640c0b85c180c
1 /*#############################################################################
3 # IPFire - An Open Source Firewall Distribution #
4 # Copyright (C) 2014 IPFire development team #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 #############################################################################*/
26 #include <blkid/blkid.h>
33 #include <sys/ioctl.h>
34 #include <sys/mount.h>
40 #include <libsmooth.h>
44 const char* other_filesystems
[] = {
51 static int system_chroot(const char* path
, const char* cmd
) {
52 char chroot_cmd
[STRING_SIZE
];
54 snprintf(chroot_cmd
, sizeof(chroot_cmd
), "/usr/sbin/chroot %s %s", path
, cmd
);
56 return mysystem(chroot_cmd
);
59 struct hw
* hw_init() {
60 struct hw
* hw
= malloc(sizeof(*hw
));
64 hw
->udev
= udev_new();
66 fprintf(stderr
, "Could not create udev instance\n");
73 void hw_free(struct hw
* hw
) {
80 static int strstartswith(const char* a
, const char* b
) {
81 return (strncmp(a
, b
, strlen(b
)) == 0);
84 int hw_mount(const char* source
, const char* target
, const char* fs
, int flags
) {
85 // Create target if it does not exist
86 if (access(target
, X_OK
) != 0)
87 mkdir(target
, S_IRWXU
|S_IRWXG
|S_IRWXO
);
89 return mount(source
, target
, fs
, flags
, NULL
);
92 int hw_umount(const char* target
) {
93 return umount2(target
, 0);
96 static int hw_test_source_medium(const char* path
) {
97 int ret
= hw_mount(path
, SOURCE_MOUNT_PATH
, "iso9660", MS_RDONLY
);
99 // If the source could not be mounted we
104 // Check if the test file exists.
105 ret
= access(SOURCE_TEST_FILE
, R_OK
);
107 // Umount the test device.
108 hw_umount(SOURCE_MOUNT_PATH
);
113 char* hw_find_source_medium(struct hw
* hw
) {
116 struct udev_enumerate
* enumerate
= udev_enumerate_new(hw
->udev
);
118 udev_enumerate_add_match_subsystem(enumerate
, "block");
119 udev_enumerate_scan_devices(enumerate
);
121 struct udev_list_entry
* devices
= udev_enumerate_get_list_entry(enumerate
);
123 struct udev_list_entry
* dev_list_entry
;
124 udev_list_entry_foreach(dev_list_entry
, devices
) {
125 const char* path
= udev_list_entry_get_name(dev_list_entry
);
126 struct udev_device
* dev
= udev_device_new_from_syspath(hw
->udev
, path
);
128 const char* dev_path
= udev_device_get_devnode(dev
);
130 // Skip everything what we cannot work with
131 if (strstartswith(dev_path
, "/dev/loop") || strstartswith(dev_path
, "/dev/fd") ||
132 strstartswith(dev_path
, "/dev/ram") || strstartswith(dev_path
, "/dev/md"))
135 if (hw_test_source_medium(dev_path
) == 0) {
136 ret
= strdup(dev_path
);
139 udev_device_unref(dev
);
141 // If a suitable device was found the search will end.
146 udev_enumerate_unref(enumerate
);
151 static struct hw_disk
** hw_create_disks() {
152 struct hw_disk
** ret
= malloc(sizeof(*ret
) * (HW_MAX_DISKS
+ 1));
157 static unsigned long long hw_block_device_get_size(const char* dev
) {
158 int fd
= open(dev
, O_RDONLY
);
162 unsigned long long size
= blkid_get_dev_size(fd
);
168 struct hw_disk
** hw_find_disks(struct hw
* hw
) {
169 struct hw_disk
** ret
= hw_create_disks();
170 struct hw_disk
** disks
= ret
;
172 struct udev_enumerate
* enumerate
= udev_enumerate_new(hw
->udev
);
174 udev_enumerate_add_match_subsystem(enumerate
, "block");
175 udev_enumerate_scan_devices(enumerate
);
177 struct udev_list_entry
* devices
= udev_enumerate_get_list_entry(enumerate
);
179 struct udev_list_entry
* dev_list_entry
;
180 unsigned int i
= HW_MAX_DISKS
;
181 udev_list_entry_foreach(dev_list_entry
, devices
) {
182 const char* path
= udev_list_entry_get_name(dev_list_entry
);
183 struct udev_device
* dev
= udev_device_new_from_syspath(hw
->udev
, path
);
185 const char* dev_path
= udev_device_get_devnode(dev
);
187 // Skip everything what we cannot work with
188 if (strstartswith(dev_path
, "/dev/loop") || strstartswith(dev_path
, "/dev/fd") ||
189 strstartswith(dev_path
, "/dev/ram") || strstartswith(dev_path
, "/dev/sr") ||
190 strstartswith(dev_path
, "/dev/md")) {
191 udev_device_unref(dev
);
195 // DEVTYPE must be disk (otherwise we will see all sorts of partitions here)
196 const char* devtype
= udev_device_get_property_value(dev
, "DEVTYPE");
197 if (devtype
&& (strcmp(devtype
, "disk") != 0)) {
198 udev_device_unref(dev
);
202 // Skip all source mediums
203 if (hw_test_source_medium(dev_path
) == 0) {
204 udev_device_unref(dev
);
208 // Skip devices with a size of zero
209 unsigned long long size
= hw_block_device_get_size(dev_path
);
211 udev_device_unref(dev
);
215 struct hw_disk
* disk
= malloc(sizeof(*disk
));
221 strncpy(disk
->path
, dev_path
, sizeof(disk
->path
));
226 const char* vendor
= udev_device_get_property_value(dev
, "ID_VENDOR");
228 vendor
= udev_device_get_sysattr_value(dev
, "vendor");
230 vendor
= udev_device_get_sysattr_value(dev
, "manufacturer");
233 strncpy(disk
->vendor
, vendor
, sizeof(disk
->vendor
));
235 *disk
->vendor
= '\0';
238 const char* model
= udev_device_get_property_value(dev
, "ID_MODEL");
240 model
= udev_device_get_sysattr_value(dev
, "model");
242 model
= udev_device_get_sysattr_value(dev
, "product");
245 strncpy(disk
->model
, model
, sizeof(disk
->model
));
249 // Format description
250 char size_str
[STRING_SIZE
];
251 snprintf(size_str
, sizeof(size_str
), "%4.1fGB", (double)disk
->size
/ pow(1024, 3));
253 if (*disk
->vendor
&& *disk
->model
) {
254 snprintf(disk
->description
, sizeof(disk
->description
),
255 "%s - %s - %s", size_str
, disk
->vendor
, disk
->model
);
257 } else if (*disk
->vendor
|| *disk
->model
) {
258 snprintf(disk
->description
, sizeof(disk
->description
),
259 "%s - %s", size_str
, (*disk
->vendor
) ? disk
->vendor
: disk
->model
);
262 snprintf(disk
->description
, sizeof(disk
->description
),
263 "%s - N/A", size_str
);
271 udev_device_unref(dev
);
274 udev_enumerate_unref(enumerate
);
281 void hw_free_disks(struct hw_disk
** disks
) {
282 struct hw_disk
** disk
= disks
;
284 while (*disk
!= NULL
) {
285 if (--(*disk
)->ref
== 0)
294 unsigned int hw_count_disks(struct hw_disk
** disks
) {
295 unsigned int ret
= 0;
303 struct hw_disk
** hw_select_disks(struct hw_disk
** disks
, int* selection
) {
304 struct hw_disk
** ret
= hw_create_disks();
305 struct hw_disk
** selected_disks
= ret
;
307 unsigned int num_disks
= hw_count_disks(disks
);
309 for (unsigned int i
= 0; i
< num_disks
; i
++) {
310 if (selection
&& selection
[i
]) {
311 struct hw_disk
*selected_disk
= disks
[i
];
312 selected_disk
->ref
++;
314 *selected_disks
++ = selected_disk
;
319 *selected_disks
= NULL
;
324 static unsigned long long hw_swap_size(struct hw_destination
* dest
) {
325 unsigned long long memory
= hw_memory();
327 unsigned long long swap_size
= memory
/ 4;
329 // Min. swap size is 128MB
330 if (swap_size
< MB2BYTES(128))
331 swap_size
= MB2BYTES(128);
333 // Cap swap size to 1GB
334 else if (swap_size
> MB2BYTES(1024))
335 swap_size
= MB2BYTES(1024);
340 static unsigned long long hw_root_size(struct hw_destination
* dest
) {
341 unsigned long long root_size
;
343 if (dest
->size
< MB2BYTES(2048))
344 root_size
= MB2BYTES(1024);
346 else if (dest
->size
>= MB2BYTES(2048) && dest
->size
<= MB2BYTES(3072))
347 root_size
= MB2BYTES(1536);
350 root_size
= MB2BYTES(2048);
355 static unsigned long long hw_boot_size(struct hw_destination
* dest
) {
359 static int hw_calculate_partition_table(struct hw_destination
* dest
) {
363 snprintf(path
, sizeof(path
), "%s%s", dest
->path
, (dest
->is_raid
) ? "p" : "");
364 dest
->part_boot_idx
= 0;
366 // Determine the size of the target block device
368 dest
->size
= (dest
->disk1
->size
>= dest
->disk2
->size
) ?
369 dest
->disk2
->size
: dest
->disk1
->size
;
371 // The RAID will install some metadata at the end of the disk
372 // and we will save up some space for that.
373 dest
->size
-= MB2BYTES(2);
375 dest
->size
= dest
->disk1
->size
;
378 // As we add some extra space before the beginning of the first
379 // partition, we need to substract that here.
380 dest
->size
-= MB2BYTES(1);
382 // Add some more space for partition tables, etc.
383 dest
->size
-= MB2BYTES(1);
385 // Determine partition table
386 dest
->part_table
= HW_PART_TABLE_MSDOS
;
388 // Disks over 2TB need to use GPT
389 if (dest
->size
>= MB2BYTES(2047 * 1024))
390 dest
->part_table
= HW_PART_TABLE_GPT
;
392 // We also use GPT on raid disks by default
393 else if (dest
->is_raid
)
394 dest
->part_table
= HW_PART_TABLE_GPT
;
396 // When using GPT, GRUB2 needs a little bit of space to put
398 if (dest
->part_table
== HW_PART_TABLE_GPT
) {
399 snprintf(dest
->part_bootldr
, sizeof(dest
->part_bootldr
),
400 "%s%d", path
, part_idx
);
402 dest
->size_bootldr
= MB2BYTES(4);
404 dest
->part_boot_idx
= part_idx
++;
406 *dest
->part_bootldr
= '\0';
407 dest
->size_bootldr
= 0;
410 dest
->size_boot
= hw_boot_size(dest
);
411 dest
->size_swap
= hw_swap_size(dest
);
412 dest
->size_root
= hw_root_size(dest
);
414 // Determine the size of the data partition.
415 unsigned long long used_space
= dest
->size_bootldr
+ dest
->size_boot
416 + dest
->size_swap
+ dest
->size_root
;
418 // Disk is way too small
419 if (used_space
>= dest
->size
)
422 dest
->size_data
= dest
->size
- used_space
;
424 // If it gets too small, we remove the swap space.
425 if (dest
->size_data
<= MB2BYTES(256)) {
426 dest
->size_data
+= dest
->size_swap
;
430 // Set partition names
431 if (dest
->size_boot
> 0) {
432 if (dest
->part_boot_idx
== 0)
433 dest
->part_boot_idx
= part_idx
;
435 snprintf(dest
->part_boot
, sizeof(dest
->part_boot
), "%s%d", path
, part_idx
++);
437 *dest
->part_boot
= '\0';
439 if (dest
->size_swap
> 0)
440 snprintf(dest
->part_swap
, sizeof(dest
->part_swap
), "%s%d", path
, part_idx
++);
442 *dest
->part_swap
= '\0';
444 // There is always a root partition
445 if (dest
->part_boot_idx
== 0)
446 dest
->part_boot_idx
= part_idx
;
448 snprintf(dest
->part_root
, sizeof(dest
->part_root
), "%s%d", path
, part_idx
++);
450 if (dest
->size_data
> 0)
451 snprintf(dest
->part_data
, sizeof(dest
->part_data
), "%s%d", path
, part_idx
++);
453 *dest
->part_data
= '\0';
458 struct hw_destination
* hw_make_destination(int part_type
, struct hw_disk
** disks
) {
459 struct hw_destination
* dest
= malloc(sizeof(*dest
));
461 if (part_type
== HW_PART_TYPE_NORMAL
) {
462 dest
->disk1
= *disks
;
465 strncpy(dest
->path
, dest
->disk1
->path
, sizeof(dest
->path
));
467 } else if (part_type
== HW_PART_TYPE_RAID1
) {
468 dest
->disk1
= *disks
++;
469 dest
->disk2
= *disks
;
470 dest
->raid_level
= 1;
472 snprintf(dest
->path
, sizeof(dest
->path
), "/dev/md0");
475 // Is this a RAID device?
476 dest
->is_raid
= (part_type
> HW_PART_TYPE_NORMAL
);
478 int r
= hw_calculate_partition_table(dest
);
482 // Set default filesystem
483 dest
->filesystem
= HW_FS_DEFAULT
;
488 unsigned long long hw_memory() {
490 char line
[STRING_SIZE
];
492 unsigned long long memory
= 0;
494 /* Calculate amount of memory in machine */
495 if ((handle
= fopen("/proc/meminfo", "r"))) {
496 while (fgets(line
, sizeof(line
), handle
)) {
497 if (!sscanf (line
, "MemTotal: %llu kB", &memory
)) {
505 return memory
* 1024;
508 static int hw_zero_out_device(const char* path
, int bytes
) {
510 memset(block
, 0, sizeof(block
));
512 int blocks
= bytes
/ sizeof(block
);
514 int fd
= open(path
, O_WRONLY
);
518 unsigned int bytes_written
= 0;
519 while (blocks
-- > 0) {
520 bytes_written
+= write(fd
, block
, sizeof(block
));
526 return bytes_written
;
529 int hw_create_partitions(struct hw_destination
* dest
) {
530 // Before we write a new partition table to the disk, we will erase
531 // the first couple of megabytes at the beginning of the device to
532 // get rid of all left other things like bootloaders and partition tables.
533 // This solves some problems when changing from MBR to GPT partitions or
534 // the other way around.
535 int r
= hw_zero_out_device(dest
->path
, MB2BYTES(10));
540 asprintf(&cmd
, "/usr/sbin/parted -s %s -a optimal", dest
->path
);
542 // Set partition type
543 if (dest
->part_table
== HW_PART_TABLE_MSDOS
)
544 asprintf(&cmd
, "%s mklabel msdos", cmd
);
545 else if (dest
->part_table
== HW_PART_TABLE_GPT
)
546 asprintf(&cmd
, "%s mklabel gpt", cmd
);
548 unsigned long long part_start
= MB2BYTES(1);
550 if (*dest
->part_bootldr
) {
551 asprintf(&cmd
, "%s mkpart %s ext2 %lluB %lluB", cmd
,
552 (dest
->part_table
== HW_PART_TABLE_GPT
) ? "BOOTLDR" : "primary",
553 part_start
, part_start
+ dest
->size_bootldr
- 1);
555 part_start
+= dest
->size_bootldr
;
558 if (*dest
->part_boot
) {
559 asprintf(&cmd
, "%s mkpart %s ext2 %lluB %lluB", cmd
,
560 (dest
->part_table
== HW_PART_TABLE_GPT
) ? "BOOT" : "primary",
561 part_start
, part_start
+ dest
->size_boot
- 1);
563 part_start
+= dest
->size_boot
;
566 if (*dest
->part_swap
) {
567 asprintf(&cmd
, "%s mkpart %s linux-swap %lluB %lluB", cmd
,
568 (dest
->part_table
== HW_PART_TABLE_GPT
) ? "SWAP" : "primary",
569 part_start
, part_start
+ dest
->size_swap
- 1);
571 part_start
+= dest
->size_swap
;
574 if (*dest
->part_root
) {
575 asprintf(&cmd
, "%s mkpart %s ext2 %lluB %lluB", cmd
,
576 (dest
->part_table
== HW_PART_TABLE_GPT
) ? "ROOT" : "primary",
577 part_start
, part_start
+ dest
->size_root
- 1);
579 part_start
+= dest
->size_root
;
582 if (*dest
->part_data
) {
583 asprintf(&cmd
, "%s mkpart %s ext2 %lluB %lluB", cmd
,
584 (dest
->part_table
== HW_PART_TABLE_GPT
) ? "DATA" : "primary",
585 part_start
, part_start
+ dest
->size_data
- 1);
587 part_start
+= dest
->size_data
;
590 if (dest
->part_boot_idx
> 0)
591 asprintf(&cmd
, "%s set %d boot on", cmd
, dest
->part_boot_idx
);
593 if (dest
->part_table
== HW_PART_TABLE_GPT
) {
594 if (*dest
->part_bootldr
) {
595 asprintf(&cmd
, "%s set %d bios_grub on", cmd
, dest
->part_boot_idx
);
597 asprintf(&cmd
, "%s disk_set pmbr_boot on", cmd
);
602 // Wait until the system re-read the partition table
604 unsigned int counter
= 10;
606 while (counter
-- > 0) {
609 if (*dest
->part_bootldr
&& (access(dest
->part_bootldr
, R_OK
) != 0))
612 if (*dest
->part_boot
&& (access(dest
->part_boot
, R_OK
) != 0))
615 if (*dest
->part_swap
&& (access(dest
->part_swap
, R_OK
) != 0))
618 if (*dest
->part_root
&& (access(dest
->part_root
, R_OK
) != 0))
621 if (*dest
->part_data
&& (access(dest
->part_data
, R_OK
) != 0))
624 // All partitions do exist, exiting the loop.
635 static int hw_format_filesystem(const char* path
, int fs
) {
636 char cmd
[STRING_SIZE
] = "\0";
639 if (fs
== HW_FS_SWAP
) {
640 snprintf(cmd
, sizeof(cmd
), "/sbin/mkswap -v1 %s &>/dev/null", path
);
642 } else if (fs
== HW_FS_REISERFS
) {
643 snprintf(cmd
, sizeof(cmd
), "/sbin/mkreiserfs -f %s ", path
);
646 } else if (fs
== HW_FS_EXT4
) {
647 snprintf(cmd
, sizeof(cmd
), "/sbin/mke2fs -T ext4 %s", path
);
650 } else if (fs
== HW_FS_EXT4_WO_JOURNAL
) {
651 snprintf(cmd
, sizeof(cmd
), "/sbin/mke2fs -T ext4 -O ^has_journal %s", path
);
654 } else if (fs
== HW_FS_XFS
) {
655 snprintf(cmd
, sizeof(cmd
), "/sbin/mkfs.xfs -f %s", path
);
660 int r
= mysystem(cmd
);
665 int hw_create_filesystems(struct hw_destination
* dest
) {
669 if (*dest
->part_boot
) {
670 r
= hw_format_filesystem(dest
->part_boot
, dest
->filesystem
);
676 if (*dest
->part_swap
) {
677 r
= hw_format_filesystem(dest
->part_swap
, HW_FS_SWAP
);
683 r
= hw_format_filesystem(dest
->part_root
, dest
->filesystem
);
688 if (*dest
->part_data
) {
689 r
= hw_format_filesystem(dest
->part_data
, dest
->filesystem
);
697 int hw_mount_filesystems(struct hw_destination
* dest
, const char* prefix
) {
698 char target
[STRING_SIZE
];
700 assert(*prefix
== '/');
702 const char* filesystem
;
703 switch (dest
->filesystem
) {
705 filesystem
= "reiserfs";
709 case HW_FS_EXT4_WO_JOURNAL
:
722 int r
= hw_mount(dest
->part_root
, prefix
, filesystem
, 0);
727 if (*dest
->part_boot
) {
728 snprintf(target
, sizeof(target
), "%s%s", prefix
, HW_PATH_BOOT
);
729 mkdir(target
, S_IRWXU
|S_IRWXG
|S_IRWXO
);
731 r
= hw_mount(dest
->part_boot
, target
, filesystem
, 0);
733 hw_umount_filesystems(dest
, prefix
);
740 if (*dest
->part_data
) {
741 snprintf(target
, sizeof(target
), "%s%s", prefix
, HW_PATH_DATA
);
742 mkdir(target
, S_IRWXU
|S_IRWXG
|S_IRWXO
);
744 r
= hw_mount(dest
->part_data
, target
, filesystem
, 0);
746 hw_umount_filesystems(dest
, prefix
);
753 if (*dest
->part_swap
) {
754 r
= swapon(dest
->part_swap
, 0);
756 hw_umount_filesystems(dest
, prefix
);
762 // bind-mount misc filesystems
763 char** otherfs
= other_filesystems
;
765 snprintf(target
, sizeof(target
), "%s%s", prefix
, *otherfs
);
767 mkdir(target
, S_IRWXU
|S_IRWXG
|S_IRWXO
);
768 r
= hw_mount(*otherfs
, target
, NULL
, MS_BIND
);
770 hw_umount_filesystems(dest
, prefix
);
781 int hw_umount_filesystems(struct hw_destination
* dest
, const char* prefix
) {
783 if (*dest
->part_boot
) {
784 hw_umount(dest
->part_boot
);
788 if (*dest
->part_data
) {
789 hw_umount(dest
->part_data
);
793 hw_umount(dest
->part_root
);
796 if (*dest
->part_swap
) {
797 swapoff(dest
->part_swap
);
801 char target
[STRING_SIZE
];
802 char** otherfs
= other_filesystems
;
805 snprintf(target
, sizeof(target
), "%s%s", prefix
, *otherfs
++);
812 int hw_setup_raid(struct hw_destination
* dest
) {
816 assert(dest
->is_raid
);
818 asprintf(&cmd
, "echo \"y\" | /sbin/mdadm --create --verbose --metadata=%s --auto=mdp %s",
819 RAID_METADATA
, dest
->path
);
821 switch (dest
->raid_level
) {
823 asprintf(&cmd
, "%s --level=1 --raid-devices=2", cmd
);
831 asprintf(&cmd
, "%s %s", cmd
, dest
->disk1
->path
);
833 // Clear all data at the beginning
834 r
= hw_zero_out_device(dest
->disk1
->path
, MB2BYTES(10));
840 asprintf(&cmd
, "%s %s", cmd
, dest
->disk2
->path
);
842 // Clear all data at the beginning
843 r
= hw_zero_out_device(dest
->disk2
->path
, MB2BYTES(10));
851 // Wait a moment until the device has been properly brought up
853 unsigned int counter
= 10;
854 while (counter
-- > 0) {
857 // If the raid device has not yet been properly brought up,
858 // opening it will fail with the message: Device or resource busy
859 // Hence we will wait a bit until it becomes usable.
860 FILE* f
= fopen(dest
->path
, "r");
871 int hw_stop_all_raid_arrays() {
872 return mysystem("/sbin/mdadm --stop --scan");
875 int hw_install_bootloader(struct hw_destination
* dest
) {
876 char cmd
[STRING_SIZE
];
879 // Generate configuration file
880 snprintf(cmd
, sizeof(cmd
), "/usr/sbin/grub-mkconfig -o /boot/grub/grub.cfg");
881 r
= system_chroot(DESTINATION_MOUNT_PATH
, cmd
);
885 char cmd_grub
[STRING_SIZE
];
886 snprintf(cmd_grub
, sizeof(cmd_grub
), "/usr/sbin/grub-install --no-floppy --recheck");
889 snprintf(cmd
, sizeof(cmd
), "%s %s", cmd_grub
, dest
->disk1
->path
);
890 r
= system_chroot(DESTINATION_MOUNT_PATH
, cmd
);
894 snprintf(cmd
, sizeof(cmd
), "%s %s", cmd_grub
, dest
->disk2
->path
);
895 r
= system_chroot(DESTINATION_MOUNT_PATH
, cmd
);
897 snprintf(cmd
, sizeof(cmd
), "%s %s", cmd_grub
, dest
->path
);
898 r
= system_chroot(DESTINATION_MOUNT_PATH
, cmd
);
904 static char* hw_get_uuid(const char* dev
) {
905 blkid_probe p
= blkid_new_probe_from_filename(dev
);
906 const char* buffer
= NULL
;
913 blkid_probe_lookup_value(p
, "UUID", &buffer
, NULL
);
916 uuid
= strdup(buffer
);
923 int hw_write_fstab(struct hw_destination
* dest
) {
924 FILE* f
= fopen(DESTINATION_MOUNT_PATH
"/etc/fstab", "w");
928 const char* fmt
= "UUID=%s %-8s %-4s %-10s %d %d\n";
932 if (*dest
->part_boot
) {
933 uuid
= hw_get_uuid(dest
->part_boot
);
936 fprintf(f
, fmt
, uuid
, "/boot", "auto", "defaults", 1, 2);
942 if (*dest
->part_swap
) {
943 uuid
= hw_get_uuid(dest
->part_swap
);
946 fprintf(f
, fmt
, uuid
, "swap", "swap", "defaults,pri=1", 0, 0);
952 uuid
= hw_get_uuid(dest
->part_root
);
954 fprintf(f
, fmt
, uuid
, "/", "auto", "defaults", 1, 1);
959 if (*dest
->part_data
) {
960 uuid
= hw_get_uuid(dest
->part_data
);
963 fprintf(f
, fmt
, uuid
, "/var", "auto", "defaults", 1, 1);