0

I'm having an issue with a bootable USB I made. So this is an ongoing project that I have been working on for a while now. Basically, I installed red hat 7 onto a usb so that the usb is essentially the OS. I then issued the following commands to try to capture this "live USB" into a .raw.gz file for redistribution:

  if=/dev/sda bs=10000 count=500000 status=progress | gzip > newredhat.raw.gz

the above task captures the first 5gb of the bootable USB and stores it into an image called newredhat.raw.gz as a compressed .raw file. The process is working as it should, except for one thing. I then issue the following command in order to put this custom image onto another USB which has been formatted fat32 and is 100% clean:

 zcat newredhat.raw.gz > /dev/sdc

After the extraction/write is done, The new USB boots as it should, however it boots into emergency mode. I have been looking for hours about what the reasoning behind this could be but seeing as this is arguably a very unique scenario there is not much about it. I tried vi /etc/fstab and it tells me that /etc/fstab does not exist and creates a new file to edit. I also looked at the journal and the only thing coming back is "failed to mount sysroot". The idea behind this whole project is that it could be a simple extract - go clone for my Linux based USB's and servers. Whats really odd is that This exact method worked for openSUSE. Is it something to do with the way that Red hat creates its architecture upon install? If this is the case is there any work around? Thanks in advance for all of the help!

1

1) The bs parameter for dd is the block size. If this is not a power of two, and in particular if this is not the block size of your device, you are doing it wrong. In that case, don't use dd in the first place.

2) Depending on how exactly you laid out the first USB stick (you didn't tell us), taking the first 5 GB may have missed the partition table at the end.

The safe way to copy between storage media of different sizes is to make a partition table on each of them with a single bootable partition of identical size (using whatever partition program you like), and then copy the complete partition

gzip /dev/sda1 > newredhat.raw.gz
zcat newredhat.raw.gz > /dev/sdc1

In that way, the partition table can compensate for devices of different size.

This also works between USB sticks and harddisks.

3) To debug what goes with your second USB stick, it would be extremely helpful to look at the messages it shows before going into emergency mode. dmesg or logs will help if it scrolls to fast. So please edit the question with the verbatim messages you see before it complains "failed to mount sysroot". I have a hunch this is because you messed up the partition table (see above). And the detected partition table should show up in dmesg/logs. And if "the same exact method worked for openSUSE", this may be because openSUSE used a different partitioning scheme, and/or your USB sticks were of the same size.

Edit

One problem with just copying the start of the whole USB stick is that for example a GPT will also have information at the very end. While this is duplicate information, it may cause trouble.

So again: Instead of copying just the first 5G of a 32G stick to a 16G stick, make a partition of size 5G on the first stick, make a partition of exactly the same size on the second stick, then copy the partition (/dev/sda1), not the whole stick (/dev/sda). You can create partitions with fdisk, gdisk, parted, or whatever you like. You don't need to calculate anything, you just have to make sure the partitions are the exact same size.

  • Hi Dirk, The goal for using the count method was so that say I wanted to run this command on a 32gb USB and save the DD into a file of 5gb size, that way I could then deploy this image to a USB that is 16b. Based on my understanding, did you mean that It is better to let the entire drive copy in any scenario, and then simply deploy it ? or would I need to perform a fdisk -l on the destination USB and then issue the count command on the source USB using the calculated information from the destination file system? – RickwhoPrograms Jul 24 '18 at 14:23
  • got it! would that copy any of the existing data from source to destination at all though? I was hoping I could copy some of the information over as well! – RickwhoPrograms Jul 24 '18 at 15:08

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.