Changeset 3147 in MondoRescue for branches/3.1/mondo/src/mondorestore/mondo-prep.c
- Timestamp:
- Jun 19, 2013, 8:34:46 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.1/mondo/src/mondorestore/mondo-prep.c
r2937 r3147 110 110 popup_and_OK 111 111 ("I must now reboot. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine."); 112 system("reboot");112 paranoid_system("reboot"); 113 113 } 114 114 } … … 171 171 172 172 int do_my_funky_lvm_stuff(bool just_erase_existing_volumes, 173 173 bool vacuum_pack) 174 174 { 175 /** 175 /** buffers **********************************************/ 176 176 char *tmp = NULL; 177 177 char *tmp1 = NULL; … … 188 188 char *p; 189 189 char *q; 190 char *r; 190 191 191 192 /** int ***************************************************/ … … 442 443 /** pointers *********************************************************/ 443 444 char *p; 445 char *q; 444 446 445 447 /** init *************************************************************/ … … 503 505 } else { 504 506 strcpy(new_mountlist->el[new_mountlist->entries].device, 505 507 old_mountlist->el[lino].device); 506 508 strcpy(new_mountlist->el[new_mountlist->entries].mountpoint, 507 509 old_mountlist->el[lino].mountpoint); 508 510 strcpy(new_mountlist->el[new_mountlist->entries].format, 509 511 old_mountlist->el[lino].format); 510 512 new_mountlist->el[new_mountlist->entries].size = 511 513 old_mountlist->el[lino].size; … … 527 529 * @return 0 for success, nonzero for failure. 528 530 */ 529 int create_raid_device_via_mdadm(struct raidlist_itself *raidlist, char *device) 530 { 531 /** int **************************************************************/ 532 int i = 0; 533 int j = 0; 534 int res = 0; 535 536 /** buffers ***********************************************************/ 537 char *devices = NULL; 538 char *strtmp = NULL; 539 char *level = NULL; 540 char *program = NULL; 541 char *tmp = NULL; 542 char *oldmd = NULL; 543 char *bootdevice; 544 char *name; 531 int create_raid_device_via_mdadm(struct raidlist_itself *raidlist, char *device, bool test) { 532 /** int **************************************************************/ 533 int i = 0; 534 int j = 0; 535 int v = 0; 536 int res = 0; 537 538 /** buffers ***********************************************************/ 539 char *devices = NULL; 540 char *level = NULL; 541 char *program = NULL; 545 542 546 543 malloc_string(bootdevice); … … 735 732 /* format raid partition */ 736 733 mr_asprintf(program, "for plex in `vinum lv -r %s | grep '^P' | tr '\t' ' ' | tr -s ' ' | cut -d' ' -f2`; do echo $plex; done > /tmp/plexes", basename(device)); 737 system(program);734 paranoid_system(program); 738 735 if (g_fprep) { 739 736 fprintf(g_fprep, "%s\n", program); … … 752 749 753 750 mr_asprintf(tmp, "vinum init %s", line); 754 system(tmp);751 paranoid_system(tmp); 755 752 mr_free(tmp); 756 753 … … 781 778 log_to_screen("Initializing RAID device %s", device); 782 779 783 // Shouldn't be necessary.780 // Shouldn't be necessary. 784 781 log_to_screen("Stopping %s", device); 785 782 stop_raid_device(device); … … 789 786 log_msg(1, "Making %s", device); 790 787 // use mkraid if it exists, otherwise use mdadm 791 792 res = create_raid_device_via_mdadm(raidlist, device);793 788 if (run_program_and_log_output("which mkraid", FALSE)) { 789 res = create_raid_device_via_mdadm(raidlist, device, TRUE); 790 log_msg(1, "Creating RAID device %s via mdadm returned %d", device, res); 794 791 } else { 795 792 mr_asprintf(program, "mkraid --really-force %s", device); … … 884 881 */ 885 882 int format_everything(struct mountlist_itself *mountlist, bool interactively, 886 883 struct raidlist_itself *raidlist) 887 884 { 888 885 /** int **************************************************************/ … … 907 904 log_it("format_everything (mountlist, interactively = %s", (interactively) ? "true" : "false"); 908 905 909 mvaddstr_and_log_it(g_currentY, 0, "Formatting partitions 906 mvaddstr_and_log_it(g_currentY, 0, "Formatting partitions "); 910 907 open_progress_form("Formatting partitions", 911 912 913 908 "I am now formatting your hard disk partitions.", 909 "This may take up to five minutes.", "", 910 mountlist->entries + 1); 914 911 915 912 progress_step = … … 949 946 sleep(2); 950 947 // This last step is probably necessary 951 // 952 // 953 // system("sync"); system("sync");system("sync");954 // 948 // log_to_screen("Re-starting software RAIDs..."); 949 // start_all_raid_devices(mountlist); 950 // paranoid_system("sync"); paranoid_system("sync"); paranoid_system("sync"); 951 // sleep(5); 955 952 // do LVMs now 956 953 log_msg(1, "Creating LVMs"); … … 992 989 continue; 993 990 } else if (!does_file_exist(me->device) 994 995 991 && strncmp(me->device, "/dev/hd", 7) 992 && strncmp(me->device, "/dev/sd", 7)) { 996 993 log_it("Not formatting %s yet - doesn't exist - probably an LVM", me->device); 997 994 continue; … … 1049 1046 } 1050 1047 newtSuspend(); 1051 system("clear");1048 paranoid_system("clear"); 1052 1049 newtResume(); 1053 1050 return (retval); … … 1064 1061 */ 1065 1062 int make_dummy_partitions(FILE * pout_to_fdisk, char *drivename, 1066 1063 int devno_we_must_allow_for) 1067 1064 { 1068 1065 /** int **************************************************************/ … … 1178 1175 fprintf(f, "\n\n%u partitions:\n", lp->d_npartitions); 1179 1176 fprintf(f, 1180 "# 1177 "# size offset fstype [fsize bsize bps/cpg]\n"); 1181 1178 pp = lp->d_partitions; 1182 1179 for (i = 0; i < lp->d_npartitions; i++, pp++) { 1183 1180 if (pp->p_size) { 1184 fprintf(f, " 1181 fprintf(f, " %c: %8lu %8lu ", 'a' + i, (u_long) pp->p_size, 1185 1182 (u_long) pp->p_offset); 1186 1183 if (pp->p_fstype < FSMAXTYPES) … … 1191 1188 1192 1189 case FS_UNUSED: /* XXX */ 1193 fprintf(f, " 1190 fprintf(f, " %5lu %5lu %5.5s ", (u_long) pp->p_fsize, 1194 1191 (u_long) (pp->p_fsize * pp->p_frag), ""); 1195 1192 break; 1196 1193 1197 1194 case FS_BSDFFS: 1198 fprintf(f, " 1195 fprintf(f, " %5lu %5lu %5u ", (u_long) pp->p_fsize, 1199 1196 (u_long) (pp->p_fsize * pp->p_frag), pp->p_cpg); 1200 1197 break; 1201 1198 1202 1199 case FS_BSDLFS: 1203 fprintf(f, " 1200 fprintf(f, " %5lu %5lu %5d", (u_long) pp->p_fsize, 1204 1201 (u_long) (pp->p_fsize * pp->p_frag), pp->p_cpg); 1205 1202 break; … … 1217 1214 fprintf(f, "- %lu", 1218 1215 (u_long) ((pp->p_offset + pp->p_size + 1219 1220 1216 lp->d_secpercyl - 1) / lp->d_secpercyl - 1217 1)); 1221 1218 if (pp->p_size % lp->d_secpercyl) 1222 1219 putc('*', f); … … 1256 1253 /* 1257 1254 * Nobody in these enligthened days uses the CHS geometry for 1258 * anything, but nontheless try to get it right. 1255 * anything, but nontheless try to get it right. If we fail 1259 1256 * to get any good ideas from the device, construct something 1260 1257 * which is IBM-PC friendly. … … 1340 1337 lp->d_partitions[c - 'a'].p_cpg = 64; 1341 1338 } else if (!strcasecmp(mountlist->el[idx].format, "raid") 1342 1339 || !strcasecmp(mountlist->el[idx].format, "vinum")) { 1343 1340 lp->d_partitions[c - 'a'].p_fstype = FS_VINUM; 1344 1341 } else if (!strcmp(mountlist->el[idx].format, "swap")) { … … 1422 1419 char *format = NULL; 1423 1420 char *tmp = NULL; 1421 char *tmp1 = NULL; 1424 1422 char *tmp1 = NULL; 1425 1423 … … 1511 1509 1512 1510 /* OK, we've found partition /dev/hdxN in mountlist; let's prep it */ 1513 /* For FreeBSD, that is 1511 /* For FreeBSD, that is /dev/adXsY */ 1514 1512 1515 1513 log_it("Found partition %s in mountlist", device_str); … … 1540 1538 previous_devno = 1541 1539 make_dummy_partitions(pout_to_fdisk, drivename, 1542 1540 current_devno); 1543 1541 } 1544 1542 } … … 1595 1593 sync(); 1596 1594 paranoid_pclose(pout_to_fdisk); 1597 log_msg(0,1598 1595 paranoid_system("sync"); 1596 log_msg(0,"------------------- fdisk.log looks like this ------------------"); 1599 1597 mr_asprintf(tmp, "cat %s >> %s", FDISK_LOG, MONDO_LOGFILE); 1600 1598 system(tmp); … … 1625 1623 * Create partition number @p partno on @p drive with @p fdisk. 1626 1624 * @param drive The drive to create the partition on. 1627 // 1625 // * @param partno The partition number of the new partition (1-4 are primary, >=5 is logical). 1628 1626 * @param prev_partno The partition number of the most recently prepped partition. 1629 1627 * @param format The filesystem type of this partition (used to set the type). … … 1656 1654 1657 1655 log_it("partition_device('%s', %d, %d, '%s', %lld) --- starting", 1658 1656 drive, partno, prev_partno, format, partsize); 1659 1657 1660 1658 if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) { … … 1743 1741 retval = 1744 1742 set_partition_type(pout_to_fdisk, drive, partno, format, 1745 1743 partsize); 1746 1744 if (retval) { 1747 1745 log_msg(1, "Failed. Trying again..."); 1748 1746 retval = 1749 1747 set_partition_type(pout_to_fdisk, drive, partno, 1750 1748 format, partsize); 1751 1749 } 1752 1750 } … … 1783 1781 retval = 1784 1782 set_partition_type(pout_to_fdisk, drive, partno, format, 1785 1783 partsize); 1786 1784 if (retval) { 1787 1785 log_it("Partitioned %s but failed to set its type", partition_name); … … 1832 1830 /** buffer *********************************************************/ 1833 1831 struct list_of_disks *drivelist; 1834 /* 1832 /* struct mountlist_itself new_mtlist, *mountlist; */ 1835 1833 1836 1834 /** end ************************************************************/ … … 1840 1838 1841 1839 log_it("partition_everything() --- starting"); 1842 mvaddstr_and_log_it(g_currentY, 0, "Partitioning hard drives 1843 /* 1840 mvaddstr_and_log_it(g_currentY, 0, "Partitioning hard drives "); 1841 /* mountlist=orig_mtlist; */ 1844 1842 if (mountlist_contains_raid_devices(mountlist)) { 1845 /* 1846 /* 1843 /* mountlist=&new_mtlist; */ 1844 /* extrapolate_mountlist_to_include_raid_partitions(mountlist,orig_mtlist); */ 1847 1845 log_msg(0, 1848 1846 "Mountlist, including the partitions incorporated in RAID devices:-"); … … 1865 1863 1866 1864 open_progress_form("Partitioning devices", 1867 1868 1869 1865 "I am now going to partition all your drives.", 1866 "This should not take more than five minutes.", "", 1867 mountlist->entries); 1870 1868 1871 1869 make_list_of_drives_in_mountlist(mountlist, drivelist); … … 1885 1883 } 1886 1884 newtSuspend(); 1887 system("clear");1885 paranoid_system("clear"); 1888 1886 newtResume(); 1889 1887 paranoid_free(drivelist); … … 1906 1904 */ 1907 1905 int set_partition_type(FILE * pout_to_fdisk, const char *drive, int partno, 1908 1906 const char *format, long long partsize) 1909 1907 { 1910 1908 /** buffers *********************************************************/ … … 1939 1937 } 1940 1938 } else if (strcmp(format, "ext2") == 0 1941 || strcmp(format, "reiserfs") == 0 1942 || strcmp(format, "ext3") == 0 1943 || strcmp(format, "ext4") == 0 1944 || strcmp(format, "xfs") == 0 1945 || strcmp(format, "jfs") == 0) { 1939 || strcmp(format, "reiserfs") == 0 1940 || strcmp(format, "ext3") == 0 1941 || strcmp(format, "ext4") == 0 1942 || strcmp(format, "xfs") == 0 1943 || strcmp(format, "jfs") == 0 1944 || strcmp(format, "btrfs") == 0) { 1946 1945 mr_asprintf(partcode, "83"); 1947 1946 } else if (strcmp(format, "minix") == 0) { … … 1956 1955 mr_asprintf(partcode, "7"); 1957 1956 } else if ((strcmp(format, "ufs") == 0) 1958 1957 || (strcmp(format, "ffs") == 0)) { /* raid autodetect */ 1959 1958 mr_asprintf(partcode, "a5"); 1960 1959 } else if (strcmp(format, "lvm") == 0) { … … 2108 2107 mr_asprintf(program, "vinum stop -f %s", raid_device); 2109 2108 #else 2110 2111 2109 // use raidstop if it exists, otherwise use mdadm 2110 if (run_program_and_log_output("which raidstop", FALSE)) { 2112 2111 mr_asprintf(program, "mdadm -S %s", raid_device); 2113 2112 } else { … … 2174 2173 /** pointers ********************************************************/ 2175 2174 FILE *fin; 2175 char *q; 2176 2176 int i; 2177 2177 … … 2203 2203 for (p = dev; *p > 32; p++); 2204 2204 *p = '\0'; 2205 re s= stop_raid_device(dev);2205 retval += stop_raid_device(dev); 2206 2206 mr_free(dev); 2207 2207 } … … 2261 2261 } else if (strcmp(format, "ext4") == 0) { 2262 2262 mr_asprintf(program, "mkfs -t ext4 -F -q"); 2263 } else if (strcmp(format, "btrfs") == 0) { 2264 strcpy(program, "mkfs.btrfs"); 2263 2265 } else if (strcmp(format, "minix") == 0) { 2264 2266 mr_asprintf(program, "mkfs.minix"); … … 2297 2299 * There are a few problems with this function: 2298 2300 * - It won't work if there was any unallocated space on the user's hard drive 2299 * 2301 * when it was backed up. 2300 2302 * - It won't work if the user's hard drive lies about its size (more common 2301 * 2303 * than you'd think). 2302 2304 * 2303 2305 * @param mountlist The mountlist to use for resizing @p drive_name. … … 2311 2313 /** int *************************************************************/ 2312 2314 int partno, lastpart; 2313 /** remove driveno, noof_drives stan benoit apr 2002**/2314 2315 2315 2316 /** float ***********************************************************/
Note:
See TracChangeset
for help on using the changeset viewer.